Page 1 of 1
How to publish a disconnected client to another mqtt client (ESP32 - Arduino)
Posted: Mon Aug 07, 2017 8:44 pm
by Pyshco
I have a ESP32, a mosquitto server and a Android phone with Linear MQTT Dashboard installed. The thing is: I need to advice the phone about the state of the ESP32 specifically when is disconnected, I'm using the PubSubClient library.
Any help?
Re: How to publish a disconnected client to another mqtt client (ESP32 - Arduino)
Posted: Mon Aug 07, 2017 9:27 pm
by kolban
An ESP32 can publish message on MQTT. These can be received by an MQTT broker which in turn can make them available to an MQTT subscriber. If the messages contain ESP32 status, then that will result in status information being supplied to the MQTT subscriber.
Re: How to publish a disconnected client to another mqtt client (ESP32 - Arduino)
Posted: Tue Aug 08, 2017 4:20 am
by tele_player
If you're running your own MQTT server, for instance, mosquitto on Linux, you could write a script which publishes when a specific client hasn't published in a while.
Re: How to publish a disconnected client to another mqtt client (ESP32 - Arduino)
Posted: Tue Aug 08, 2017 2:06 pm
by Pyshco
Hey there Neil and tele_player!
Thanks for the quick replies and answers!
Re: How to publish a disconnected client to another mqtt client (ESP32 - Arduino)
Posted: Tue Aug 08, 2017 3:17 pm
by tele_player
I haven't tried to do this, but I expect this could be done using a shell script, mosquitto_pub and mosquitto_sub, or a python script.
Re: How to publish a disconnected client to another mqtt client (ESP32 - Arduino)
Posted: Tue Aug 08, 2017 5:45 pm
by kolban
@Pyscho,
lets see if we can clarify some of your needs.
You said:
I have a ESP32, a mosquitto server and a Android phone with Linear MQTT Dashboard installed. The thing is: I need to advice the phone about the state of the ESP32 specifically when is disconnected, I'm using the PubSubClient library.
You have an ESP32. Got that.
You have a mosquitto server. For others, this is an MQTT open source server. On what platform is the mosquitto server running?
You have an Android phone. Got that.
You have something called "Linear MQTT Dashboard" installed. Don't know what that is... but I'll assume its an MQTT client capable of receiving messages from an MQTT broker.
Now we get into the crux of the story. If I am understanding, you need to have the ESP32 post periodic MQTT messages on a topic which will then be delivered to Mosquitto server. An MQTT client that happens to be running on your Android phone will receive them.
Then you said "about the state of the ESP32 specifically when is disconnected".
In that statement ... when "what" is disconnected and disconnected from what?
Can you also paint some back story on the design/plan of why this function is needed. Putting it in context can commonly help.
In addition, can you answer whether this is a work project, a personal project or a school assignment?
Re: How to publish a disconnected client to another mqtt client (ESP32 - Arduino)
Posted: Tue Aug 08, 2017 6:12 pm
by Pyshco
Back story: I'm on a internship, and they need a ESP32 reading constantly the voltage of a battery to get the actual "%" of it , the ESP32 needs to be connected to a MQTT server (Mosquitto in this case) and they need to get notifications on a phone or Gmail (in this case i choose the phone), I have all done, but, they need a notification if the ESP is disconnected of the network or else (example: if was unplugged).
PD: Yes, Linear MQTT Dashboard is a MQTT client on android.
Re: How to publish a disconnected client to another mqtt client (ESP32 - Arduino)
Posted: Tue Aug 08, 2017 7:21 pm
by kolban
If I am understanding correctly, the ESP32 is producing messages on a regular basis ... but if the ESP32 should be "lost" from the network, then you wont to know that. What about detecting that a message was NOT published by the ESP32 after a period of time when we should have expected the ESP32 to publish a new message? Would that be a sufficient algorithm?
Re: How to publish a disconnected client to another mqtt client (ESP32 - Arduino)
Posted: Tue Aug 08, 2017 7:33 pm
by Pyshco
I think so, but, how do i do that algorithm? *I'm new on programming to*.
Re: How to publish a disconnected client to another mqtt client (ESP32 - Arduino)
Posted: Tue Aug 08, 2017 7:57 pm
by tele_player
It's simpler than I thought. Google 'mqtt last will'. No additional script needed.