0

I am currently running a raspberry pi with a MQTT broker. But my problem is that I also want to use the raspberry pi to publish on the broker, for some microcontrollers to receive the message. I do not know how to utilise this. There's however a few ideas:

  1. Make Thonny open the terminal and make it paste this message: mosquitto_pub -d -t testTopic -m "Hello world!" Though I dont know whether that is possible, especially due to the "" that are required for it to work.
  2. Or a more direct method by using a mqtt library for Thonny. However there is only one library "mqtt 0.0.1", and the developer doesnt even have a github page for it. Also installing this library externally "micropython-umqtt.simple 1.3.4" didn't work either.
Jumike
  • 3
  • 2
  • An mqtt broker is just a network service. You can connect to it from the local system just as easily as from remote systems. – larsks Aug 05 '23 at 11:13

1 Answers1

0

Yes, you can run both a MQTT Broker and a MQTT Client on the same device, you can even run 1000s of clients on the same device if you so choose to.

As for Python MQTT clients, the most popular is probably the Paho Python client available here: https://www.eclipse.org/paho/clients/python/

Or for devices the MicroPython client https://mpython.readthedocs.io/en/master/library/mPython/umqtt.simple.html (with it's github page here: https://github.com/micropython/micropython-lib/tree/master/micropython/umqtt.simple)

If you have problems with any of the libraries, ask a new question and include all the details about the problem, so that we have something to work with.

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • Thank you, I figured it out. I am now running a python scrypt using the paho client 24/7 and publishing onto the broker, which can be accessed from anywhere on the world – Jumike Aug 15 '23 at 20:29