From cd4be903fe6ab32cc5dd146bb63853b58bce58d0 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 29 Mar 2021 02:48:41 +0200 Subject: [PATCH] Add mac address and idle to statusupdate messages --- platformio.ini | 2 +- src/hasp/hasp_dispatch.cpp | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/platformio.ini b/platformio.ini index 03fc69ac..a13bf3af 100644 --- a/platformio.ini +++ b/platformio.ini @@ -59,7 +59,7 @@ build_flags = ; -- Hasp build options ---------------------------- -D HASP_VER_MAJ=0 -D HASP_VER_MIN=4 - -D HASP_VER_REV=0 + -D HASP_VER_REV=1 -D HASP_LOG_LEVEL=9 ${override.build_flags} diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 5107241e..a3573bd1 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -360,11 +360,8 @@ void dispatch_text_line(const char* cmnd) } } -// send idle state to the client -void dispatch_output_idle_state(uint8_t state) +void dispatch_get_idle_state(uint8_t state, char* payload) { - char topic[6]; - char payload[6]; switch(state) { case HASP_SLEEP_LONG: memcpy_P(payload, PSTR("long"), 5); @@ -375,7 +372,16 @@ void dispatch_output_idle_state(uint8_t state) default: memcpy_P(payload, PSTR("off"), 4); } +} + +// send idle state to the client +void dispatch_output_idle_state(uint8_t state) +{ + char topic[6]; + char payload[6]; memcpy_P(topic, PSTR("idle"), 5); + + dispatch_get_idle_state(state, payload); dispatch_state_subtopic(topic, payload); } @@ -1032,18 +1038,22 @@ void dispatch_output_statusupdate(const char*, const char*) { #if HASP_USE_MQTT > 0 - char data[3 * 128]; + char data[400]; + char topic[16]; { char buffer[128]; haspGetVersion(buffer, sizeof(buffer)); - snprintf_P(data, sizeof(data), - PSTR("{\"node\":\"%s\",\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"), - haspDevice.get_hostname(), buffer, long(millis() / 1000)); + dispatch_get_idle_state(hasp_sleep_state, topic); + snprintf_P(data, sizeof(data), PSTR("{\"node\":\"%s\",\"idle\":\"%s\",\"version\":\"%s\",\"uptime\":%lu,"), + haspDevice.get_hostname(), topic, buffer, long(millis() / 1000)); // \"status\":\"available\", -#if HASP_USE_WIFI > 0 +#if HASP_USE_WIFI > 0 || HASP_USE_ETHERNET > 0 network_get_statusupdate(buffer, sizeof(buffer)); strcat(data, buffer); + + snprintf_P(buffer, sizeof(buffer), PSTR("\"mac\":\"%s\","), halGetMacAddress(0, ":").c_str()); + strcat(data, buffer); #endif snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"core\":\"%s\","), @@ -1064,7 +1074,6 @@ void dispatch_output_statusupdate(const char*, const char*) strcat(data, buffer); } - char topic[16]; memcpy_P(topic, PSTR("statusupdate"), 13); dispatch_state_subtopic(topic, data); dispatchLastMillis = millis();