Added mqtt status topic

This commit is contained in:
cschwinne 2019-11-10 22:13:07 +01:00
parent 1595542d59
commit 6989b1730e
4 changed files with 12 additions and 3 deletions

View File

@ -100,7 +100,7 @@
//version code in format yymmddb (b = daily build)
#define VERSION 1911101
#define VERSION 1911102
char versionString[] = "0.8.6";
@ -386,6 +386,7 @@ unsigned long realtimeTimeout = 0;
long lastMqttReconnectAttempt = 0;
long lastInterfaceUpdate = 0;
byte interfaceUpdateCallMode = 0;
char mqttStatusTopic[40] = ""; //this must be global because of async handlers
#if AUXPIN >= 0
//auxiliary debug pin

View File

@ -176,6 +176,7 @@ void handleNotifications()
{
//ignore notification if received within a second after sending a notification ourselves
if (millis() - notificationSentTime < 1000) return;
if (udpIn[1] > 199) return; //do not receive custom versions
bool someSel = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects);
//apply colors from notification

View File

@ -19,7 +19,6 @@ void onMqttConnect(bool sessionPresent)
{
//(re)subscribe to required topics
char subuf[38];
strcpy(subuf, mqttDeviceTopic);
if (mqttDeviceTopic[0] != 0)
{
@ -89,6 +88,10 @@ void publishMqtt()
strcat(subuf, "/c");
mqtt->publish(subuf, 0, true, s);
strcpy(subuf, mqttDeviceTopic);
strcat(subuf, "/status");
mqtt->publish(subuf, 0, true, "online");
char apires[1024];
XML_response(nullptr, false, apires);
strcpy(subuf, mqttDeviceTopic);
@ -243,6 +246,10 @@ bool initMqtt()
}
mqtt->setClientId(mqttClientID);
if (mqttUser[0] && mqttPass[0]) mqtt->setCredentials(mqttUser, mqttPass);
strcpy(mqttStatusTopic, mqttDeviceTopic);
strcat(mqttStatusTopic, "/status");
mqtt->setWill(mqttStatusTopic, 0, true, "offline");
mqtt->connect();
return true;
}

View File

@ -64,7 +64,7 @@ void initServer()
server.on("/settings/wifi", HTTP_POST, [](AsyncWebServerRequest *request){
if (!(wifiLock && otaLock)) handleSettingsSet(request, 1);
serveMessage(request, 200,"WiFi settings saved.","Reconnecting now...",255);
serveMessage(request, 200,"WiFi settings saved.","Reconnecting now...",129);
forceReconnect = true;
});