Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT Last Will and Testament #499

Open
wants to merge 1 commit into
base: dev2
Choose a base branch
from
Open

Conversation

ckuethe
Copy link
Contributor

@ckuethe ckuethe commented Jan 2, 2025

Register a lost connection message with the MQTT broker to publish if the client loses connection. Also publish online when the client connects and offline when the client politely disconnects to a status topic. This way you get a clue if the device was shut down or it somehow failed.

From my MQTT viewer:

...
[0 ] rdz_sonde_server/csk/uptime > {"uptime": 106.6, "user": "radiosonde", "time": 2025-01-02 21:23:35, "SW": "rdzTTGOsonde", "VER": "dev20250102"}
(powered off device)
[0 ] rdz_sonde_server/csk/status > lost connection
[0 ] rdz_sonde_server/csk/status > online
[0 ] rdz_sonde_server/csk/uptime > {"uptime": 15.8, "user": "radiosonde", "time": 2025-01-02 21:24:17, "SW": "rdzTTGOsonde", "VER": "dev20250102"}
...

@dl9rdz
Copy link
Owner

dl9rdz commented Jan 9, 2025

I am hesitating to merge this as it is, as in the past I have tried to minimize the use of global variables (like the char lwt[128];). Its just 128 bytes, but that is already something on the TTGO. Whenever easily feasible I prefer local variables on the stack that only use RAM during function execution, this is why the topic string is in a function local char topic[128];

It course its a trade-off between space use and CPU time use for constructing the topic on each invocation - besides the difference of being able to change the topic in the config without restarting). Unless there are more good reasons for the global lwt variable, I would prefer having the topic for the additional messages in a stack (function local) variable as well...

@ckuethe
Copy link
Contributor Author

ckuethe commented Jan 9, 2025

No problem. Happy to follow your preferred style. Will update PR later today.

Register a message with the MQTT broker to publish if the client
loses connection. Also publish online/offline status - all to a
`status` topic.

avoid global variable
@ckuethe
Copy link
Contributor Author

ckuethe commented Jan 10, 2025

lwt global removed, LWT publication moved into its own function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants