hsaturn / TinyMqtt

ESP 8266 / 32 / WROOM Small footprint Mqtt Broker and Client
GNU General Public License v3.0
183 stars 40 forks source link

Disconnections Management #100

Open Leonidas00000 opened 4 months ago

Leonidas00000 commented 4 months ago

I'm trying to implement a broker with this library and i wanted to know if there is a easy way to detect disconnected clients, i didn't found "onDisconnect()" event or anything like that, i want to know how can i detect a disconnected client and get its "id".

hsaturn commented 3 months ago

Hello

You're right, this is on my todo list. I've never been disconnected so I did not implement this. Not planned but I keep this issue for when I have time.

Aurentiaco35 commented 1 month ago

Hello,

I also want to detect disconnected clients, I tried to add myself but I couldn't manage it. Is there any update about it?

Leonidas00000 commented 4 weeks ago

Hello,

even though there is no a disconnection management implemented, i have managed to do it. I don´t know if this helps you but, i detected a client disconnection using

"Clients_connected = broker.clientsCount();"

With this command i can controll the number of clients i have connected to my broker, if i compare this number taken in two diferent moments of my "loop()", i can check if there was a disconnection in my broker and eventually do something with a conditional function.

Controlling which client disconnected is a little bit more difficult because the library does not support "last will message", but as i only have 6 devices, y created a 6 position vector that reloads every few seconds detecting the id of the clients that are connected in that moment to the broker, in that way i can detect which client get disconnected.

I´m still working on this, hope it helps!

Aurentiaco35 commented 3 weeks ago

That would help thank you so much.