Paho.mqtt in Micropython

When I include ‘import paho.mqtt.client as mqtt_client’ in a micropython program on the RPi3B/Pico I receive the error message 'no module named ‘paho’.

When I check on the RPi terminal where I installed paho.mqt it confirms that the ‘Requirement already satisfied:’

Using the Thonny package management process I can’t locate anything on a PyPI search.

Can anyone confirm that paho should be able to be installed in micropython and if so how.

Thanks
Toni

1 Like

Hi Toni,

Micropython unfortunately doesnt have access to the Paho MQTT library, a full Python version is however.

For Micropython I would suggest these libraries:
https://mpython.readthedocs.io/en/v2.2.1/library/mPython/umqtt.simple.html
(A bit more advanced but robust) GitHub - peterhinch/micropython-mqtt: A 'resilient' asynchronous MQTT driver. Recovers from WiFi and broker outages.

FYI: If you are using a Pi SBC to program a Pico, any of the guides for the Pico (or Micropython based microcontroller) will be the ones you want to follow

1 Like

Thanks Liam I’ll push on with umqtt.simple which I understand can be included with micropython and for use on the Pico.
Cheers
Toni

2 Likes

Just remember that the Python on your 3B is separate to the Micropython on your Pico. When you connect your Pico in Thonny you are working directly with Micropython on your Pico, not the Python on your 3B!

1 Like

Good point, thanks
Toni

1 Like

MicroPython provides its own MQTT client libraries (umqtt.simple or umqtt.robust) that are lightweight and work well on constrained devices like the Raspberry Pi Pico.

Thanks Lia, I have now tried using umqtt.simple and it is all now working.

Cheers
Toni

1 Like

Hi Toni,

Great to hear that you managed to get it all working!