Thanks for the contribution, this is a nice and simple improvement. Rebased and merged in b50d3462d783e4aab2f10d6b8117641244918f64
QUERY · ISSUE
can't await mqtt.simple publish method
Hi
I'm using umqtt.simple and there is problem when i await mqtt.publish in my code !
'NoneType' object isn't iterable
Is there any way to solve this issue ?
Or use other lib like https://github.com/peterhinch/micropython-mqtt/blob/master/mqtt_as ?
CANDIDATE · PULL REQUEST
wait_msg() return op as indication if there was a message
As indicated in this issue: https://github.com/micropython/micropython-lib/issues/328, it would be useful if wait_msg() would return a value if a message was received.
A common use case using this library would be:
def callback(topic, msg):
print(topic, msg)
async def check_messages(mqtt_client, interval):
while True:
mqtt_client.check_msg()
await asyncio.sleep(interval)
In the above scenario, if more than one message was published to the topic being subscribed to, it will still get consumed every <interval> seconds. If this change is merged, we would be able to do:
def callback(topic, msg):
print(topic, msg)
async def check_messages(mqtt_client, interval):
while True:
while mqtt_client.check_msg() is not None:
continue
await asyncio.sleep(interval)
And any waiting messages will get consumed immediately.
1 comment
The umqtt.simple module is sync.You'd better use peterhinch's uasync mqtt lib.
While you only need subscribe to some topic.
my solution is :
@2niuhe thanks, but using umqtt_async have its own problem : https://forum.micropython.org/viewtopic.php?f=15&t=7144
thanks for your solution but i had problem in publish part not others .