Hi Peter,
I read somewhere you prefer be contacted via this forum regarding any issues with mqtt_as.
As I mentioned on my last post, I'm working on a project where I'm using wifimgr to make the ESP32 module mobile, OTA to update the code and mqtt to communicate with node-red.
So, I've been doing lots of testing in the last few days and I noticed that the function (async def wifi_connect (self)) was causing me lot of problems as it was trying to connect to the network when the module was already connected.
Therefore, I make some changes to get around the problem. The function is now checking for a connection first and then continues otherwise, makes a new connection.
Not sure if the code is technically correct as I'm not a programmer, but it solved the problem, for now.
Code: Select all
async def wifi_connect(self):
s = self._sta_if
self.dprint('WIFI connection')
if not s.isconnected():
self.dprint('Conn error! raising error 1')
s.active(True)
s.connect(self._ssid, self._wifi_pw)
await asyncio.sleep(5)
while s.status() == network.STAT_CONNECTING: # Break out on fail or success. Check once per sec.
await asyncio.sleep(1)
raise OSError
# Ensure connection stays up for a few secs.
self.dprint('Checking WiFi integrity.')
for _ in range(5):
if not s.isconnected():
self.dprint('Conn error! raising error 2')
raise OSError # in 1st 5 secs
await asyncio.sleep(1)
self.dprint('Got reliable connection')