From 4a98dcce43772c5ea42d9cd2c74778d1963d40c8 Mon Sep 17 00:00:00 2001 From: Yilin Sun Date: Mon, 22 May 2023 23:38:27 +0800 Subject: [PATCH] Updated buffer size, removed unused attributes in regular reports. Signed-off-by: Yilin Sun --- main/app_report_rb.c | 2 +- main/main.c | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/main/app_report_rb.c b/main/app_report_rb.c index 3210f09..33c4717 100644 --- a/main/app_report_rb.c +++ b/main/app_report_rb.c @@ -8,7 +8,7 @@ /* App */ #include "app_report_rb.h" -#define APP_REPORT_RB_SIZE 4800 +#define APP_REPORT_RB_SIZE 6400 static app_report_rb_t s_report_rb[APP_REPORT_RB_SIZE]; static volatile uint32_t s_report_rb_rptr = 0U; diff --git a/main/main.c b/main/main.c index 6dc1ae5..9d7a31c 100644 --- a/main/main.c +++ b/main/main.c @@ -54,13 +54,15 @@ #define APP_TELEMETRY_TOPIC "v1/devices/me/telemetry" #define APP_ATTRIBUTE_TOPIC "v1/devices/me/attributes" -#define APP_ATTRIBUTE_JSON_STRING \ +#define APP_ATTRIBUTE_INIT_JSON_STRING \ "{\"firmwareVersion\":\"%s\", \"macAddress\":\"" MACSTR \ "\",\"hasHumidity\":true,\"hasPressure\":false,\"batteryPowered\":true,\"batteryType\":\"Li-ion\"," \ "\"batteryVoltage\":%ld}" +#define APP_ATTRIBUTE_JSON_STRING "{\"batteryVoltage\":%ld}" + #define APP_TELEMETRY_JSON_STRING "{\"ts\":%lld,\"values\":{\"temperature\":%.2f,\"humidity\":%.2f}}" -static void app_report_attributes(void); +static void app_report_attributes(bool init); static void app_report_task(void *pvParameters); static uint64_t app_get_msec_timestamp(void); @@ -129,7 +131,7 @@ void app_main(void) { ESP_ERROR_CHECK(app_mqtt_init(APP_MQTT_TIMEOUT_SECS * 1000)); - app_report_attributes(); + app_report_attributes(true); ESP_ERROR_CHECK(app_mqtt_deinit()); @@ -227,7 +229,7 @@ static void app_report_task(void *pvParameters) { ESP_ERROR_CHECK(app_mqtt_init(APP_MQTT_TIMEOUT_SECS * 1000)); - app_report_attributes(); + app_report_attributes(false); rpt_buffer = malloc(512); @@ -268,15 +270,20 @@ drop_data_exit: vTaskDelete(NULL); } -static void app_report_attributes(void) { +static void app_report_attributes(bool init) { char rpt_buf[256]; uint8_t mac_addr[6]; - const esp_app_desc_t *app_descr = esp_app_get_description(); - esp_read_mac(mac_addr, ESP_MAC_WIFI_STA); uint32_t batt_voltage = app_adc_read() * 2; - snprintf(rpt_buf, 256, APP_ATTRIBUTE_JSON_STRING, app_descr->version, MAC2STR(mac_addr), batt_voltage); + if (init) { + const esp_app_desc_t *app_descr = esp_app_get_description(); + esp_read_mac(mac_addr, ESP_MAC_WIFI_STA); + + snprintf(rpt_buf, 256, APP_ATTRIBUTE_INIT_JSON_STRING, app_descr->version, MAC2STR(mac_addr), batt_voltage); + } else { + snprintf(rpt_buf, 256, APP_ATTRIBUTE_JSON_STRING, batt_voltage); + } app_mqtt_publish(APP_ATTRIBUTE_TOPIC, rpt_buf); }