adafruit / Adafruit_IO_Arduino

Arduino library to access Adafruit IO from WiFi, cellular, and ethernet modules.
Other
209 stars 108 forks source link

Disconnect and ssid check #104

Closed sellensr closed 4 years ago

sellensr commented 4 years ago

Scope: Created a _disconnect() function in all the wifi hardware variants that calls the appropriate wifi.disconnect() and waits long enough (300 ms) for it to take effect. Created an AIO.disconnect() that calls the hardware _disconnect().

https://github.com/adafruit/Adafruit_IO_Arduino/issues/101

Check that the ssid string is not zero length before trying to connect wifi. Call _disconnect() before trying to connect in order to break any existing connection. This allows sketches to self manage wifi by setting the AIO ssid to "".

Limitations: Only tested on WINC1500, so relying on Travis to check other builds. Will make connect() calls take about 300 ms longer. May change failure mode of code where SSID is set to "".

brentru commented 4 years ago

@sellensr Ok, everything looks good. I will test on M0/AirLift and ESP32 hardware tomorrow AM.

brentru commented 4 years ago

@sellensr I tested this on a PyPortal, ESP32 and ESP8266. All were able to connect to Adafruit IO.

However, a blank SSID/Password will cause the Serial.print(".") in our example sketches to print ...., even if it's disconnected.

I'm not sure if we want to re-use AIO_NET_DISCONNECTED for the SSID check.

Let's make a new enum here for an invalid ssid: https://github.com/adafruit/Adafruit_IO_Arduino/blob/master/src/AdafruitIO_Definitions.h#L107 and call it AIO_INVALID_SSID.

I feel the user code would handle this after the io.connect() call.

_dev_cu_usbmodem144212101_and_adafruitio_02_pubsub_-_config_h___Arduino_1_8_9_and_1__git__Users_brentrubell_Documents_Arduino_libraries_Adafruit_IO_Arduino__less__and_Disconnect_and_ssid_check_by_sellensr_·_Pull_Request__104_·_adafruit_Adaf

sellensr commented 4 years ago

I'd pick AIO_SSID_INVALID to match AIO_FINGERPRINT_INVALID and AIO_AUTH_FAILED for word order. The user code could then detect and do something after io.connect() and some wait time.

Even if I set that status, the examples will still .... because they have no code to detect why a full connection isn't completed. I don't think they need the added complexity, and this is the behaviour they have always had for anything other than fully correct ssid pass, user, and key, isn't it?

brentru commented 4 years ago

I'd pick AIO_SSID_INVALID to match AIO_FINGERPRINT_INVALID and AIO_AUTH_FAILED for word order. The user code could then detect and do something after io.connect() and some wait time. AIO_SSID_INVALID is OK by me!

and this is the behaviour they have always had for anything other than fully correct ssid pass, user, and key, isn't it?

Yep. I agree, let's not modify the examples for now. In the future, I'd like to have them be more verbose to indicate what ... means.

Once this passes, please bump the minor version number within https://github.com/adafruit/Adafruit_IO_Arduino/blob/master/library.properties#L2 to 3.4.0 to prepare for a release :)

Thanks for adding this!

sellensr commented 4 years ago

OK, I'll watch for Travis to succeed then bump up the version number. I'm having fun and developing some github skills I didn't have. Thanks for helping me along, as this will make my own projects more reliable, which we need when monitoring greenhouses through the cold.

brentru commented 4 years ago

No problem, thanks for contributing to Adafruit IO Arduino!

I should convert this repository to GitHub Actions instead of travis, it currently takes ~20min per build.