Updated report format.
Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
parent
7776d32f03
commit
7f34b7ce23
31
main/main.c
31
main/main.c
|
@ -13,7 +13,9 @@
|
|||
#include "esp_adc/adc_cali.h"
|
||||
#include "esp_adc/adc_cali_scheme.h"
|
||||
#include "esp_adc/adc_oneshot.h"
|
||||
#include "esp_app_desc.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_mac.h"
|
||||
#include "esp_sleep.h"
|
||||
#include "esp_sntp.h"
|
||||
|
||||
|
@ -40,7 +42,7 @@
|
|||
#define APP_SNTP_TIMEOUT_SECS 60
|
||||
|
||||
#define APP_SENSOR_INTERVAL_SECS 1
|
||||
#define APP_SENSOR_REPORT_TRIGGER_POINTS 20 /* Count of the trigger points which triggers telemetry reporting */
|
||||
#define APP_SENSOR_REPORT_TRIGGER_POINTS 4 /* Count of the trigger points which triggers telemetry reporting */
|
||||
#define APP_SENSOR_REPORT_WATERMARK_PERCENT 80 /* when the buffer reaches this watermark in each trigger point */
|
||||
#define APP_SENSOR_REPORT_CRITICAL_PERCENT 95 /* Critical level, when this is reached, reports will be flushed */
|
||||
|
||||
|
@ -49,6 +51,14 @@
|
|||
#define APP_LED_PIN 16
|
||||
#define APP_ADC_CH ADC_CHANNEL_6
|
||||
|
||||
#define APP_TELEMETRY_TOPIC "v1/devices/me/telemetry"
|
||||
#define APP_ATTRIBUTE_TOPIC "v1/devices/me/attributes"
|
||||
|
||||
#define APP_ATTRIBUTE_JSON_STRING "{\"firmwareVersion\":\"%s\", \"macAddress\":\"" MACSTR "\"}"
|
||||
#define APP_TELEMETRY_JSON_STRING \
|
||||
"{\"ts\":%lld,\"values\":{\"temperature\":%.2f,\"humidity\":%.2f,\"batteryVoltage\":%ld}}"
|
||||
|
||||
static void app_report_attributes(void);
|
||||
static void app_report_task(void *pvParameters);
|
||||
|
||||
static uint64_t app_get_msec_timestamp(void);
|
||||
|
@ -112,6 +122,9 @@ void app_main(void) {
|
|||
sntp_stop();
|
||||
|
||||
ESP_ERROR_CHECK(app_mqtt_init(APP_MQTT_TIMEOUT_SECS * 1000));
|
||||
|
||||
app_report_attributes();
|
||||
|
||||
ESP_ERROR_CHECK(app_mqtt_deinit());
|
||||
|
||||
/*
|
||||
|
@ -220,8 +233,8 @@ static void app_report_task(void *pvParameters) {
|
|||
while (app_report_rb_get_count() > 0) {
|
||||
app_report_rb_consume(&rpt);
|
||||
|
||||
// TODO: Create new report
|
||||
// app_mqtt_publish(INFLUX_TOPIC, rpt_buffer);
|
||||
snprintf(rpt_buffer, 512, APP_TELEMETRY_JSON_STRING, rpt.ts, rpt.temperature, rpt.humidity, batt_voltage);
|
||||
app_mqtt_publish(APP_TELEMETRY_TOPIC, rpt_buffer);
|
||||
}
|
||||
|
||||
free(rpt_buffer);
|
||||
|
@ -254,6 +267,18 @@ drop_data_exit:
|
|||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
static void app_report_attributes(void) {
|
||||
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);
|
||||
|
||||
snprintf(rpt_buf, 256, APP_ATTRIBUTE_JSON_STRING, app_descr->version, MAC2STR(mac_addr));
|
||||
|
||||
app_mqtt_publish(APP_ATTRIBUTE_TOPIC, rpt_buf);
|
||||
}
|
||||
|
||||
static uint64_t app_get_msec_timestamp(void) {
|
||||
struct timeval tv_now;
|
||||
gettimeofday(&tv_now, NULL);
|
||||
|
|
Loading…
Reference in New Issue