mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Consolidate mqtt state messages
This commit is contained in:
parent
6bf6f67fd9
commit
8dbea689f3
@ -870,7 +870,7 @@ void IRAM_ATTR debugLoop(void)
|
||||
void debugEverySecond()
|
||||
{
|
||||
if(debugTelePeriod > 0 && (millis() - debugLastMillis) >= debugTelePeriod * 1000) {
|
||||
dispatch_output_statusupdate();
|
||||
dispatch_output_statusupdate(NULL, NULL);
|
||||
debugLastMillis = millis();
|
||||
}
|
||||
// printLocalTime();
|
||||
|
@ -43,7 +43,7 @@ void dispatch_web_update(const char * espOtaUrl);
|
||||
void dispatch_reboot(bool saveConfig);
|
||||
|
||||
void dispatch_output_idle_state(uint8_t state);
|
||||
void dispatch_output_statusupdate(void);
|
||||
void dispatch_output_statusupdate(const char *, const char *);
|
||||
void dispatch_output_current_page();
|
||||
|
||||
void dispatch_gpio_event(uint8_t pin, uint8_t group, uint8_t eventid);
|
||||
|
@ -36,7 +36,6 @@ EthernetClient mqttNetworkClient;
|
||||
//#include "hasp_tft.h"
|
||||
#include "hasp_debug.h"
|
||||
#include "hasp_config.h"
|
||||
#include "hasp_wifi.h"
|
||||
#include "hasp_dispatch.h"
|
||||
#include "hasp.h"
|
||||
|
||||
@ -44,8 +43,6 @@ EthernetClient mqttNetworkClient;
|
||||
#include "user_config_override.h"
|
||||
#endif
|
||||
|
||||
extern unsigned long debugLastMillis; // UpdateStatus timer
|
||||
|
||||
/*
|
||||
String mqttGetSubtopic; // MQTT subtopic for incoming commands requesting .val
|
||||
String mqttGetSubtopicJSON; // MQTT object buffer for JSON status when requesting .val
|
||||
@ -165,13 +162,6 @@ void IRAM_ATTR mqtt_send_state(const __FlashStringHelper * subtopic, const char
|
||||
// Log.notice(TAG_MQTT_PUB, F("%sstate/%S = %s"), mqttNodeTopic, subtopic, payload);
|
||||
}
|
||||
|
||||
void mqtt_send_gpio_event(uint8_t pin, uint8_t group, const char * event)
|
||||
{
|
||||
char payload[64];
|
||||
snprintf_P(payload, sizeof(payload), PSTR("{\"pin\":%d,\"group\":%d,\"event\":\"%s\"}"), pin, group, event);
|
||||
mqtt_send_state(F("input"), payload);
|
||||
}
|
||||
|
||||
void IRAM_ATTR mqtt_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data)
|
||||
{
|
||||
// if(mqttIsConnected()) {
|
||||
@ -195,57 +185,6 @@ void IRAM_ATTR mqtt_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const
|
||||
// data);
|
||||
}
|
||||
|
||||
void mqtt_send_statusupdate()
|
||||
{ // Periodically publish a JSON string indicating system status
|
||||
char data[3 * 128];
|
||||
{
|
||||
char buffer[128];
|
||||
|
||||
haspGetVersion(buffer, sizeof(buffer));
|
||||
snprintf_P(data, sizeof(data), PSTR("{\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"), buffer,
|
||||
long(millis() / 1000));
|
||||
|
||||
#if HASP_USE_WIFI > 0
|
||||
#if defined(STM32F4xx)
|
||||
IPAddress ip;
|
||||
ip = WiFi.localIP();
|
||||
char espIp[16];
|
||||
memset(espIp, 0, sizeof(espIp));
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"ssid\":\"%s\",\"rssi\":%i,\"ip\":\"%d.%d.%d.%d\","), WiFi.SSID(),
|
||||
WiFi.RSSI(), ip[0], ip[1], ip[2], ip[3]);
|
||||
#else
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"ssid\":\"%s\",\"rssi\":%i,\"ip\":\"%s\","), WiFi.SSID().c_str(),
|
||||
WiFi.RSSI(), WiFi.localIP().toString().c_str());
|
||||
#endif
|
||||
strcat(data, buffer);
|
||||
#endif
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","),
|
||||
halGetFreeHeap(), halGetHeapFragmentation(), halGetCoreVersion().c_str());
|
||||
strcat(data, buffer);
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"),
|
||||
haspGetPage(), (HASP_NUM_PAGES));
|
||||
strcat(data, buffer);
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"espVcc\":%.2f,"), (float)ESP.getVcc() / 1000);
|
||||
strcat(data, buffer);
|
||||
#endif
|
||||
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"),
|
||||
halDisplayDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT));
|
||||
strcat(data, buffer);
|
||||
}
|
||||
mqtt_send_state(F("statusupdate"), data);
|
||||
debugLastMillis = millis();
|
||||
|
||||
/* if(updateEspAvailable) {
|
||||
mqttStatusPayload += F("\"updateEspAvailable\":true,");
|
||||
} else {
|
||||
mqttStatusPayload += F("\"updateEspAvailable\":false,");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Receive incoming messages
|
||||
static void mqtt_message_cb(char * topic, byte * payload, unsigned int length)
|
||||
@ -426,7 +365,7 @@ void mqttStart()
|
||||
|
||||
haspReconnect();
|
||||
dispatch_output_current_page();
|
||||
dispatch_output_statusupdate();
|
||||
dispatch_output_statusupdate(NULL, NULL);
|
||||
}
|
||||
|
||||
void mqttSetup()
|
||||
|
@ -13,10 +13,8 @@ void mqttStart();
|
||||
void mqttStop();
|
||||
|
||||
void IRAM_ATTR mqtt_send_state(const __FlashStringHelper * subtopic, const char * payload);
|
||||
void mqtt_send_gpio_event(uint8_t pin,uint8_t group, const char * event);
|
||||
void IRAM_ATTR mqtt_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data);
|
||||
|
||||
void mqtt_send_statusupdate(void);
|
||||
bool IRAM_ATTR mqttIsConnected();
|
||||
|
||||
bool mqttGetConfig(const JsonObject & settings);
|
||||
|
@ -76,7 +76,18 @@ bool networkEverySecond(void)
|
||||
#if HASP_USE_WIFI > 0
|
||||
// return wifiEverySecond();
|
||||
#endif
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void network_get_status(char * buffer, size_t len)
|
||||
{
|
||||
#if HASP_USE_ETHERNET > 0
|
||||
network_get_status(buffer, len);
|
||||
#endif
|
||||
|
||||
#if HASP_USE_WIFI > 0
|
||||
wifi_get_status(buffer, len);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
@ -15,8 +15,8 @@ void networkStop(void);
|
||||
/* ===== Special Event Processors ===== */
|
||||
|
||||
/* ===== Getter and Setter Functions ===== */
|
||||
void network_get_status(char * buffer, size_t len);
|
||||
|
||||
/* ===== Read/Write Configuration ===== */
|
||||
|
||||
|
||||
#endif
|
@ -492,6 +492,21 @@ void wifiStop()
|
||||
Log.warning(TAG_WIFI, F("Stopped"));
|
||||
}
|
||||
|
||||
void wifi_get_status(char * buffer, size_t len)
|
||||
{
|
||||
#if defined(STM32F4xx)
|
||||
IPAddress ip;
|
||||
ip = WiFi.localIP();
|
||||
char espIp[16];
|
||||
memset(espIp, 0, sizeof(espIp));
|
||||
snprintf_P(buffer, len, PSTR("\"ssid\":\"%s\",\"rssi\":%i,\"ip\":\"%d.%d.%d.%d\","), WiFi.SSID(), WiFi.RSSI(),
|
||||
ip[0], ip[1], ip[2], ip[3]);
|
||||
#else
|
||||
snprintf_P(buffer, len, PSTR("\"ssid\":\"%s\",\"rssi\":%i,\"ip\":\"%s\","), WiFi.SSID().c_str(), WiFi.RSSI(),
|
||||
WiFi.localIP().toString().c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ============ Confiuration =============================================================== */
|
||||
|
||||
bool wifiGetConfig(const JsonObject & settings)
|
||||
|
@ -11,7 +11,9 @@ bool wifiShowAP();
|
||||
bool wifiShowAP(char * ssid, char * pass);
|
||||
bool wifiEvery5Seconds(void);
|
||||
void wifiStop(void);
|
||||
|
||||
bool wifiValidateSsid(const char * ssid, const char * pass);
|
||||
void wifi_get_status(char * buffer, size_t len);
|
||||
|
||||
bool wifiGetConfig(const JsonObject & settings);
|
||||
bool wifiSetConfig(const JsonObject & settings);
|
||||
|
Loading…
x
Reference in New Issue
Block a user