EspMQTTClient icon indicating copy to clipboard operation
EspMQTTClient copied to clipboard

Please add a "onWiFiConnectionEstablished" callback

Open ikarisan opened this issue 4 years ago • 2 comments

I am trying to use you MQTT library together with NTPClient libraries. These libraries require at least to wait for an established WiFi connection, before asking a NTP server. Would it be possible to include a onWiFiConnectionEstablished() method as well? Maybe the MQTT broker is not reachable but the WiFi is already usable.

A client.getWiFiConnection() would also be nice, because some libraries require to pass a reference to a WiFi or WiFiUdp object.

ikarisan avatar Dec 23 '20 18:12 ikarisan

I was just looking into this. This should be possible to do yourself using WiFi events, smth. like this for esp32:

...
WiFi.onEvent(onWiFiConnectionEstablished, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_GOT_IP)
...

void onWiFiConnectionEstablished(WiFiEvent_t event, WiFiEventInfo_t info) {
}

There should be opportunities, in the dev version of this library, to add such a convenience function though.

kintel avatar Feb 04 '22 05:02 kintel

@plapointe6 what's your opinion on using magic functions like onConnectionEstablished, which the user has to implement? If it's just a single function, it's quite user friendly, but it can become a bit messy if there are more signals we'd like to expose. Like WiFi connection status.

Allowing users to register callbacks is more classic, but that could introduce an incompatibility with the current version of the library. Not sure if that's a big issue..

kintel avatar Feb 09 '22 02:02 kintel