Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check_for_messages res evaluates to 49 or 50 #1

Open
Beormund opened this issue Dec 5, 2022 · 0 comments
Open

check_for_messages res evaluates to 49 or 50 #1

Beormund opened this issue Dec 5, 2022 · 0 comments

Comments

@Beormund
Copy link

Beormund commented Dec 5, 2022

Thanks for a great async MQTT implementation. I particularly like the decoupling from wifi/networking. I have got this working nicely on a RP Pico W connecting to Mosquitto. I had a slight issue on connecting. The on_connection_cb kept firing repeatedly in connect(). It was due to message_handler() -> check_for_messages() setting is_connected to False when res = 49 or 50. This in turn causes keep_alive_task to break out of the while loop. I simply removed:

else:
raise OSError(-1)

I'm not sure what codes 49 or 50 are??

self.loop.create_task(self.message_handler()) # Tasks quit on connection fail.
self.loop.create_task(self.keep_alive_task())
->
async def message_handler(self):
try:
while self.is_connected:
await self.check_for_message()
except OSError:
pass
self.is_connected = False
->
res = await self.read(1)
if res == b'':
return None
res = res[0]

# res = 49 or 50

->

else:
raise OSError(-1)
->
async def keep_alive_task(self):
while self.is_connected:
if ticks_diff(ticks_ms(), self.last_message_received) >= (self.keep_alive*1000/2):
try:
await self.ping()
except OSError:
break
await asyncio.sleep(1)
self.is_connected = False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant