plapointe6 / EspMQTTClient

Wifi and MQTT handling for ESP8266 and ESP32
GNU General Public License v3.0
448 stars 134 forks source link

Please add a "onWiFiConnectionEstablished" callback #76

Open ikarisan opened 3 years ago

ikarisan commented 3 years ago

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.

kintel commented 2 years ago

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 commented 2 years ago

@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..