Updated buffer size, removed unused attributes in regular reports.
Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
parent
3d72616ed4
commit
4a98dcce43
|
@ -8,7 +8,7 @@
|
||||||
/* App */
|
/* App */
|
||||||
#include "app_report_rb.h"
|
#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 app_report_rb_t s_report_rb[APP_REPORT_RB_SIZE];
|
||||||
static volatile uint32_t s_report_rb_rptr = 0U;
|
static volatile uint32_t s_report_rb_rptr = 0U;
|
||||||
|
|
23
main/main.c
23
main/main.c
|
@ -54,13 +54,15 @@
|
||||||
#define APP_TELEMETRY_TOPIC "v1/devices/me/telemetry"
|
#define APP_TELEMETRY_TOPIC "v1/devices/me/telemetry"
|
||||||
#define APP_ATTRIBUTE_TOPIC "v1/devices/me/attributes"
|
#define APP_ATTRIBUTE_TOPIC "v1/devices/me/attributes"
|
||||||
|
|
||||||
#define APP_ATTRIBUTE_JSON_STRING \
|
#define APP_ATTRIBUTE_INIT_JSON_STRING \
|
||||||
"{\"firmwareVersion\":\"%s\", \"macAddress\":\"" MACSTR \
|
"{\"firmwareVersion\":\"%s\", \"macAddress\":\"" MACSTR \
|
||||||
"\",\"hasHumidity\":true,\"hasPressure\":false,\"batteryPowered\":true,\"batteryType\":\"Li-ion\"," \
|
"\",\"hasHumidity\":true,\"hasPressure\":false,\"batteryPowered\":true,\"batteryType\":\"Li-ion\"," \
|
||||||
"\"batteryVoltage\":%ld}"
|
"\"batteryVoltage\":%ld}"
|
||||||
|
#define APP_ATTRIBUTE_JSON_STRING "{\"batteryVoltage\":%ld}"
|
||||||
|
|
||||||
#define APP_TELEMETRY_JSON_STRING "{\"ts\":%lld,\"values\":{\"temperature\":%.2f,\"humidity\":%.2f}}"
|
#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 void app_report_task(void *pvParameters);
|
||||||
|
|
||||||
static uint64_t app_get_msec_timestamp(void);
|
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));
|
ESP_ERROR_CHECK(app_mqtt_init(APP_MQTT_TIMEOUT_SECS * 1000));
|
||||||
|
|
||||||
app_report_attributes();
|
app_report_attributes(true);
|
||||||
|
|
||||||
ESP_ERROR_CHECK(app_mqtt_deinit());
|
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));
|
ESP_ERROR_CHECK(app_mqtt_init(APP_MQTT_TIMEOUT_SECS * 1000));
|
||||||
|
|
||||||
app_report_attributes();
|
app_report_attributes(false);
|
||||||
|
|
||||||
rpt_buffer = malloc(512);
|
rpt_buffer = malloc(512);
|
||||||
|
|
||||||
|
@ -268,15 +270,20 @@ drop_data_exit:
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_report_attributes(void) {
|
static void app_report_attributes(bool init) {
|
||||||
char rpt_buf[256];
|
char rpt_buf[256];
|
||||||
uint8_t mac_addr[6];
|
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;
|
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);
|
app_mqtt_publish(APP_ATTRIBUTE_TOPIC, rpt_buf);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue