mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-13 00:46:38 +02:00
MQTT last will with uptime
This commit is contained in:
parent
7f4417716d
commit
ba91e905ce
2 changed files with 10 additions and 4 deletions
|
@ -834,8 +834,10 @@ void app::setupMqtt(void) {
|
||||||
|
|
||||||
if(mMqttActive) {
|
if(mMqttActive) {
|
||||||
mMqtt.sendMsg("version", mVersion);
|
mMqtt.sendMsg("version", mVersion);
|
||||||
if(mMqtt.isConnected())
|
if(mMqtt.isConnected()) {
|
||||||
mMqtt.sendMsg("device", mSysConfig.deviceName);
|
mMqtt.sendMsg("device", mSysConfig.deviceName);
|
||||||
|
mMqtt.sendMsg("uptime", "0");
|
||||||
|
}
|
||||||
|
|
||||||
/*char topic[30];
|
/*char topic[30];
|
||||||
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
|
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
|
||||||
|
|
|
@ -92,10 +92,14 @@ class mqtt {
|
||||||
// da ein MQTT_CONNECTION_LOST -3 die Werte zerstört hat.
|
// da ein MQTT_CONNECTION_LOST -3 die Werte zerstört hat.
|
||||||
mClient->setServer(mCfg->broker, mCfg->port);
|
mClient->setServer(mCfg->broker, mCfg->port);
|
||||||
mClient->setBufferSize(MQTT_MAX_PACKET_SIZE);
|
mClient->setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||||
|
|
||||||
|
char lwt[MQTT_TOPIC_LEN + 7 ]; // "/uptime" --> + 7 byte
|
||||||
|
snprintf(lwt, MQTT_TOPIC_LEN + 7, "%s/uptime", mCfg->topic);
|
||||||
|
|
||||||
if((strlen(mCfg->user) > 0) && (strlen(mCfg->pwd) > 0))
|
if((strlen(mCfg->user) > 0) && (strlen(mCfg->pwd) > 0))
|
||||||
resub = mClient->connect(mDevName, mCfg->user, mCfg->pwd);
|
resub = mClient->connect(mDevName, mCfg->user, mCfg->pwd, lwt, 0, false, "offline");
|
||||||
else
|
else
|
||||||
resub = mClient->connect(mDevName);
|
resub = mClient->connect(mDevName, lwt, 0, false, "offline");
|
||||||
// ein Subscribe ist nur nach einem connect notwendig
|
// ein Subscribe ist nur nach einem connect notwendig
|
||||||
if(resub) {
|
if(resub) {
|
||||||
char topic[MQTT_TOPIC_LEN + 13 ]; // "/devcontrol/#" --> + 6 byte
|
char topic[MQTT_TOPIC_LEN + 13 ]; // "/devcontrol/#" --> + 6 byte
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue