homieiot / homie-esp8266

💡 ESP8266 framework for Homie, a lightweight MQTT convention for the IoT
http://homieiot.github.io/homie-esp8266
MIT License
1.36k stars 308 forks source link

Question on code: online/offline #423

Closed psyciknz closed 6 years ago

psyciknz commented 6 years ago

While not an issue, hoping someone can help.

How is the $online false set if not driven use user code. Ie what sets the online state from true to false when the device has disconnected/lost power? Can someone explain? I'd like to replicate in code for something else, so it uses the homie model of showing is a device is connected.

It looks like the true status is set as a retained message to the $online topic with the QOS set to At Least once? I just can't figure out how the broker knows the device has gone and sets the $online to false.

n8twj commented 6 years ago

Hi - I believe it has something to do with the "Last Will and Testament" concept from MQTT, but I cannot quickly locate an example

Typos courtesy of my iPhone

psyciknz commented 6 years ago

I saw the posting of the true status in the boot-normal.cpp. And it looked like it was retained. The 1 before retained I thought was the at least once.

But I replicated that in c# and the true was set but it didn’t set to false when I exited.


From: Jeremy McNamara notifications@github.com<mailto:notifications@github.com> Sent: Monday, November 13, 2017 16:25 Subject: Re: [marvinroger/homie-esp8266] Question on code: online/offline (#423) To: marvinroger/homie-esp8266 homie-esp8266@noreply.github.com<mailto:homie-esp8266@noreply.github.com> Cc: psyciknz github@andc.co.nz<mailto:github@andc.co.nz>, Author author@noreply.github.com<mailto:author@noreply.github.com>

Hi - I believe it has something to do with the "Last Will and Testament" concept from MQTT, but I cannot quickly locate an example

Typos courtesy of my iPhone

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/marvinroger/homie-esp8266/issues/423#issuecomment-343800109, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AFGkc11I_GlWC28yQoYc046GDusNskS1ks5s17aTgaJpZM4QbMQM.

psyciknz commented 6 years ago

Figured it out, you helped with the LWT guidance. So for the client I was using, setting the last will and testament was part of the connection. And you set the $online to false as LWT.

Then as part of connecting you create a $online true. And so on disconnection (forcibly) the LWT takes effect.

Thanks, interesting exercise.