Skip to content

Commit c7587ad

Browse files
committed
new partitions and bugfixes
fix #31 fix #33
1 parent 2ebebc0 commit c7587ad

File tree

11 files changed

+82
-36
lines changed

11 files changed

+82
-36
lines changed

components/awsiot/awsiot_rest.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ esp_err_t awsiot_update_shadow(awsiot_config_t* awsiot_config, char* body) {
5858
// sprintf(host_header, "Host: %s", awsiot_config->endpoint);
5959

6060
request_t* req = req_new(uri);
61+
if (!req) {
62+
return ESP_FAIL;
63+
}
6164

6265
req->ca_cert = req_parse_x509_crt((unsigned char*)verisign_root_ca_pem_start, verisign_root_ca_pem_end-verisign_root_ca_pem_start);
6366
if (!req->ca_cert) {

components/net/thing_speak.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static void set_config_str_field(char** field, char* value) {
4343

4444
static char* prepare_thingspeak_payload(oap_measurement_t* meas) {
4545
char* payload = malloc(512);
46+
if (!payload) return NULL;
4647
sprintf(payload, "api_key=%s", apikey);
4748

4849
if (meas->pm) {
@@ -69,6 +70,9 @@ static char* prepare_thingspeak_payload(oap_measurement_t* meas) {
6970

7071
static esp_err_t rest_post(char* uri, char* payload) {
7172
request_t* req = req_new(uri);
73+
if (!req) {
74+
return ESP_FAIL;
75+
}
7276
ESP_LOGD(TAG, "request payload: %s", payload);
7377

7478
req_setopt(req, REQ_SET_POSTFIELDS, payload);
@@ -116,10 +120,13 @@ static esp_err_t thing_speak_send(oap_measurement_t* meas, oap_sensor_config_t*
116120
}
117121

118122
char* payload = prepare_thingspeak_payload(meas);
119-
esp_err_t ret = rest_post(OAP_THING_SPEAK_URI, payload);
120-
free(payload);
121-
122-
return ret;
123+
if (payload) {
124+
esp_err_t ret = rest_post(OAP_THING_SPEAK_URI, payload);
125+
free(payload);
126+
return ret;
127+
} else {
128+
return ESP_FAIL;
129+
}
123130
}
124131

125132
oap_publisher_t thingspeak_publisher = {

components/oap_common/include/oap_debug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ void heap_log_free(heap_log* log);
3333

3434
void log_task_stack(const char* task);
3535
void log_heap_size(const char* msg);
36+
void reduce_heap_size_to(size_t size);

components/oap_common/oap_debug.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ void log_heap_size(const char* msg) {
5353
last_free_heap = free_heap;
5454
}
5555

56+
static void* dummy;
57+
void reduce_heap_size_to(size_t size) {
58+
size_t reduce_by = xPortGetFreeHeapSize() - size;
59+
if (reduce_by > 0) {
60+
ESP_LOGE(TAG, "********************** REDUCE HEAP BY %d TO %d bytes !!!!!!!!!!!", reduce_by, size);
61+
do {
62+
size_t block = reduce_by > 10000 ? 10000 : reduce_by;
63+
reduce_by-=block;
64+
dummy = malloc(block);
65+
if (!dummy) {
66+
ESP_LOGE(TAG, "FAILED TO ALLOCATE!");
67+
}
68+
} while (reduce_by > 0);
69+
}
70+
}
71+
5672
static int heap_log_count = 0;
5773

5874
/*

components/oap_common/test/test_oap_storage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ TEST_CASE("bigblob", "[oap_common]")
100100
{
101101
nvs_clean_if_necessary();
102102

103-
size_t blob_size = MAX_NVS_VALUE_SIZE * 1 + 10;
103+
size_t blob_size = MAX_NVS_VALUE_SIZE * 10 + 10;
104104
void* blob = malloc(blob_size);
105105

106106
TEST_ESP_ERR(ESP_ERR_NVS_NOT_FOUND, storage_get_bigblob("blob", &blob, NULL));

components/ota/ota.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ esp_err_t fetch_last_ota_info(ota_config_t* ota_config, ota_info_t* ota_info)
144144
{
145145
ESP_LOGI(TAG, "fetch ota info from %s", ota_config->index_uri);
146146
request_t* req = req_new(ota_config->index_uri);
147+
if (!req) {
148+
return OAP_OTA_ERR_REQUEST_FAILED;
149+
}
147150

148151
// ESP_LOGI(TAG, "REQ.HOST:%s", (char*)req_list_get_key(req->opt, "host")->value);
149152
// ESP_LOGI(TAG, "REQ.PATH:%s", (char*)req_list_get_key(req->opt, "path")->value);
@@ -202,6 +205,9 @@ esp_err_t download_ota_binary(ota_config_t* ota_config, ota_info_t* ota_info, es
202205
ESP_LOGI(TAG, "download ota binary from %s", file_uri);
203206

204207
request_t* req = req_new(file_uri);
208+
if (!req) {
209+
return OAP_OTA_ERR_REQUEST_FAILED;
210+
}
205211
req->ca_cert = req_parse_x509_crt((unsigned char*)_root_ca_pem_start, _root_ca_pem_end-_root_ca_pem_start);
206212

207213
req_setopt(req, REQ_SET_HEADER, "Connection: close");
@@ -350,6 +356,7 @@ esp_err_t check_ota(ota_config_t* ota_config) {
350356
}
351357

352358
static void check_ota_task(ota_config_t* ota_config) {
359+
delay(1000);
353360
check_ota(ota_config);
354361
vTaskDelete(NULL);
355362
}

main/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ void app_main() {
357357
delay(1000);
358358
ESP_LOGI(TAG,"starting app... firmware %s", oap_version_str());
359359

360+
//130kb is a nice cap to test against alloc fails
361+
//reduce_heap_size_to(130000);
360362
storage_init();
361363

362364
ESP_LOGD(TAG, "retrieve sensor config");

partitions.csv

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Name, Type, SubType, Offset, Size
2+
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
3+
nvs, data, nvs, 0x9000, 0x13000
4+
otadata, data, ota, 0x1c000, 0x2000
5+
phy_init, data, phy, 0x1e000, 0x1000
6+
factory, 0, 0, 0x30000, 0x140000
7+
coredump, data, coredump,, 0x10000
8+
ota_0, 0, ota_0, , 0x140000
9+
ota_1, 0, ota_1, , 0x140000

sdkconfig.defaults

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CONFIG_LOG_BOOTLOADER_LEVEL=2
2929
#
3030
# Serial flasher config
3131
#
32-
CONFIG_ESPTOOLPY_PORT="/dev/ttyUSB0"
32+
CONFIG_ESPTOOLPY_PORT="/opt/oap/dev/ttyOAP"
3333
# CONFIG_ESPTOOLPY_BAUD_115200B is not set
3434
# CONFIG_ESPTOOLPY_BAUD_230400B is not set
3535
CONFIG_ESPTOOLPY_BAUD_921600B=y
@@ -74,20 +74,18 @@ CONFIG_MONITOR_BAUD=115200
7474
#
7575
# OpenAirProject
7676
#
77-
CONFIG_OAP_PM_SAMPLE_BUF_SIZE=120
78-
CONFIG_OAP_RESULT_BUFFER_SIZE=1
7977
CONFIG_OAP_CONTROL_PANEL=1
8078

8179
#
8280
# Partition Table
8381
#
8482
# CONFIG_PARTITION_TABLE_SINGLE_APP is not set
85-
CONFIG_PARTITION_TABLE_TWO_OTA=y
86-
# CONFIG_PARTITION_TABLE_CUSTOM is not set
83+
# CONFIG_PARTITION_TABLE_TWO_OTA is not set
84+
CONFIG_PARTITION_TABLE_CUSTOM=y
8785
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
88-
CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000
89-
CONFIG_PARTITION_TABLE_FILENAME="partitions_two_ota.csv"
90-
CONFIG_APP_OFFSET=0x10000
86+
CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x30000
87+
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
88+
CONFIG_APP_OFFSET=0x30000
9189

9290
#
9391
# Compiler options
@@ -441,7 +439,6 @@ CONFIG_OPENSSL_ASSERT_DO_NOTHING=y
441439
CONFIG_OAP_OTA_ENABLED=1
442440
CONFIG_OAP_OTA_BIN_URI_PREFIX="https://openairproject.com/ota/"
443441
CONFIG_OAP_OTA_INDEX_URI="https://openairproject.com/ota/index.txt"
444-
CONFIG_OAP_OTA_CHECK_INTERVAL=3600
445442

446443
#
447444
# OAP Peripherals
@@ -451,6 +448,13 @@ CONFIG_OAP_LED_G_PIN=27
451448
CONFIG_OAP_LED_B_PIN=14
452449
CONFIG_OAP_BTN_0_PIN=39
453450

451+
#
452+
# OAP measurements
453+
#
454+
CONFIG_OAP_PM_SAMPLE_BUF_SIZE=120
455+
CONFIG_OAP_HEATER_CONTROL_PIN=21
456+
CONFIG_OAP_FAN_CONTROL_PIN=22
457+
454458
#
455459
# OAP PMSx003 Sensor
456460
#
@@ -460,8 +464,6 @@ CONFIG_OAP_PM_UART_RXD_PIN=13
460464
CONFIG_OAP_PM_UART_TXD_PIN=5
461465
CONFIG_OAP_PM_UART_RTS_PIN=18
462466
CONFIG_OAP_PM_UART_CTS_PIN=19
463-
CONFIG_OAP_HEATER_CONTROL_PIN=21
464-
CONFIG_OAP_FAN_CONTROL_PIN=22
465467
CONFIG_OAP_PM_ENABLED_AUX=0
466468
CONFIG_OAP_PM_UART_NUM_AUX=0x2
467469
CONFIG_OAP_PM_SENSOR_CONTROL_PIN_AUX=2
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Special partition table for unit test app
2-
#
3-
# Name, Type, SubType, Offset, Size, Flags
1+
# Let's keep it the same as for app
2+
# Name, Type, SubType, Offset, Size
43
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
5-
nvs, data, nvs, 0x9000, 0x6000
6-
#otadata, data, ota, 0xd000, 0x2000
7-
phy_init, data, phy, 0xf000, 0x1000
8-
factory, 0, 0, 0x10000, 0x140000
9-
ota_0, 0, ota_0, , 256K
10-
ota_1, 0, ota_1, , 256K
4+
nvs, data, nvs, 0x9000, 0x13000
5+
otadata, data, ota, 0x1c000, 0x2000
6+
phy_init, data, phy, 0x1e000, 0x1000
7+
factory, 0, 0, 0x30000, 0x140000
8+
coredump, data, coredump,, 0x10000
9+
ota_0, 0, ota_0, , 0x140000
10+
ota_1, 0, ota_1, , 0x140000

unit-test-app/sdkconfig.defaults

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ CONFIG_LOG_BOOTLOADER_LEVEL=3
3131
#
3232
# Serial flasher config
3333
#
34-
CONFIG_ESPTOOLPY_PORT="/dev/ttyUSB0"
34+
CONFIG_ESPTOOLPY_PORT="/opt/oap/dev/ttyOAP.TEST"
3535
# CONFIG_ESPTOOLPY_BAUD_115200B is not set
3636
# CONFIG_ESPTOOLPY_BAUD_230400B is not set
3737
CONFIG_ESPTOOLPY_BAUD_921600B=y
@@ -80,9 +80,9 @@ CONFIG_MONITOR_BAUD=115200
8080
# CONFIG_PARTITION_TABLE_TWO_OTA is not set
8181
CONFIG_PARTITION_TABLE_CUSTOM=y
8282
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partition_table_unit_test_app.csv"
83-
CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000
83+
CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x30000
8484
CONFIG_PARTITION_TABLE_FILENAME="partition_table_unit_test_app.csv"
85-
CONFIG_APP_OFFSET=0x10000
85+
CONFIG_APP_OFFSET=0x30000
8686

8787
#
8888
# Compiler options
@@ -424,11 +424,6 @@ CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED=y
424424
CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED=y
425425
CONFIG_MBEDTLS_ECP_NIST_OPTIM=y
426426

427-
#
428-
# OAP measurements
429-
#
430-
CONFIG_OAP_PM_SAMPLE_BUF_SIZE=120
431-
432427
#
433428
# OpenSSL
434429
#
@@ -442,7 +437,6 @@ CONFIG_OPENSSL_ASSERT_DO_NOTHING=y
442437
CONFIG_OAP_OTA_ENABLED=1
443438
CONFIG_OAP_OTA_BIN_URI_PREFIX="https://openairproject.com/ota/"
444439
CONFIG_OAP_OTA_INDEX_URI="https://openairproject.com/ota/index.txt"
445-
CONFIG_OAP_OTA_CHECK_INTERVAL=3600
446440

447441
#
448442
# OAP Peripherals
@@ -452,6 +446,13 @@ CONFIG_OAP_LED_G_PIN=27
452446
CONFIG_OAP_LED_B_PIN=14
453447
CONFIG_OAP_BTN_0_PIN=35
454448

449+
#
450+
# OAP measurements
451+
#
452+
CONFIG_OAP_PM_SAMPLE_BUF_SIZE=120
453+
CONFIG_OAP_HEATER_CONTROL_PIN=21
454+
CONFIG_OAP_FAN_CONTROL_PIN=22
455+
455456
#
456457
# OAP PMSx003 Sensor
457458
#
@@ -461,8 +462,6 @@ CONFIG_OAP_PM_UART_RXD_PIN=13
461462
CONFIG_OAP_PM_UART_TXD_PIN=5
462463
CONFIG_OAP_PM_UART_RTS_PIN=18
463464
CONFIG_OAP_PM_UART_CTS_PIN=19
464-
CONFIG_OAP_HEATER_CONTROL_PIN=21
465-
CONFIG_OAP_FAN_CONTROL_PIN=22
466465
CONFIG_OAP_PM_ENABLED_AUX=0
467466
CONFIG_OAP_PM_UART_NUM_AUX=0x2
468467
CONFIG_OAP_PM_SENSOR_CONTROL_PIN_AUX=2

0 commit comments

Comments
 (0)