fix LWT, add discovery for LWT

This commit is contained in:
technyon
2023-04-04 20:05:51 +02:00
parent 5c6eef5b9c
commit 710aa1775e
3 changed files with 31 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
#pragma once
#define NUKI_HUB_VERSION "8.20"
#define NUKI_HUB_VERSION "8.21-pre-2"
#define MQTT_QOS_LEVEL 1
#define MQTT_CLEAN_SESSIONS false

View File

@@ -23,12 +23,21 @@ Network::Network(Preferences *preferences, const String& maintenancePathPrefix,
_hostname = _preferences->getString(preference_hostname);
memset(_maintenancePathPrefix, 0, sizeof(_maintenancePathPrefix));
size_t len = maintenancePathPrefix.length();
for(int i=0; i < len; i++)
{
_maintenancePathPrefix[i] = maintenancePathPrefix.charAt(i);
}
String connectionStateTopic = _preferences->getString(preference_mqtt_lock_path) + mqtt_topic_mqtt_connection_state;
memset(_mqttConnectionStateTopic, 0, sizeof(_mqttConnectionStateTopic));
len = connectionStateTopic.length();
for(int i=0; i < len; i++)
{
_mqttConnectionStateTopic[i] = connectionStateTopic.charAt(i);
}
setupDevice();
}
@@ -417,7 +426,7 @@ bool Network::reconnect()
}
}
publishString(_maintenancePathPrefix, _mqttConnectionStateTopic, "online");
publishString(_maintenancePathPrefix, mqtt_topic_mqtt_connection_state, "online");
_mqttConnectionState = 2;
for(const auto& callback : _reconnectedCallbacks)
@@ -698,6 +707,24 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n
"",
{ { "enabled_by_default", "true" } });
// MQTT Connected
publishHassTopic("binary_sensor",
"mqtt_connected",
uidString,
"_mqtt_connected",
"MQTT connected",
name,
baseTopic,
mqtt_topic_mqtt_connection_state,
deviceType,
"",
"",
"diagnostic",
"",
{{"pl_on", "online"},
{"pl_off", "offline"},
{"ic", "mdi:lan-connect"}});
// Firmware version
publishHassTopic("sensor",
"firmware_version",

View File

@@ -101,8 +101,8 @@ private:
static Network* _inst;
const char* _mqttConnectionStateTopic = mqtt_topic_mqtt_connection_state;
const char* _lastWillPayload = "offline";
char _mqttConnectionStateTopic[211] = {0};
Preferences* _preferences;
IPConfiguration* _ipConfiguration = nullptr;