Updated buffer size, removed unused attributes in regular reports.

Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
Yilin Sun 2023-05-22 23:38:27 +08:00
parent 3d72616ed4
commit 4a98dcce43
Signed by: imi415
GPG Key ID: 17F01E106F9F5E0A
2 changed files with 16 additions and 9 deletions

View File

@ -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;

View File

@ -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);
}