Replies: 1 comment
-
Your use of The problem is that async def main():
mqtt_client.connect()
while True:
data = await pm.read()
if data is not None:
# Publish sensor readings to MQTT topic
mqtt_payload = "PM1.0: {}, PM2.5: {}, PM10: {}".format(data[0], data[1], data[2])
mqtt_client.publish(mqtt_topic, mqtt_payload)
await uasyncio.sleep(60) # Publish readings every 60 seconds
pm.registerCallback(pm.print)
asyncio.run(main()) This assumes that Resources which may be of interest: asyncio tutorial. Once you've got MQTT working you might want to look at asynchronous MQTT. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Guys,
I am new in Micropython and I need learn a lot yet but i now am busy with project at home to use ESP32 and PMS5003 to send via mqtt data to Home Assistant.
I could use Arduino code but i want to learn micropython.
Til now i used librabry pms5003.py and main.py as follows:
Everyth works as it should but then i wrote a code to send this data via MQTT
I know someth is wrong but i don't know what and i think that my little knowledge is the issue ;)
Can someone help me with this?
PS. I have code to connect to WIFI in boot.py
Beta Was this translation helpful? Give feedback.
All reactions