peterhinch / micropython-mqtt

A 'resilient' asynchronous MQTT driver. Recovers from WiFi and broker outages.
MIT License
550 stars 117 forks source link

ESP8266 use wifi credentials if not stored on device #21

Closed kevinkk525 closed 4 years ago

kevinkk525 commented 4 years ago

As I was reorganizing my wifi code in my project pysmartnode I realized, that the library doesn't handle the case that the esp8266 has no wifi credentials stored. The connect() coro would just exit and expect the user to handle that case. However as a user I would expect the library to handle this case too if I provide my wifi credentials in the configuration, especially since it is handled for every other device too since those don't even connect without credentials.

So I ended up having to implement that case in my higher layer mqtt handler which is not intuitive.

This little change could solve the problem. Didn't implement it in my fork either to keep the inner workings equal. You probably thought of this problem and had reasons not to implement it?

kevinkk525 commented 4 years ago

It probably does, that is why this solution only uses credentials if the inital connect with the stored credentials doesn't work. It could be further refined to only try the configured credentials once at the first connect instead of during every non successful connection attempt.

peterhinch commented 4 years ago

It does indeed. I've woken up properly now :)