MQTT tutorial on Raspberry pi, Arduino and Python



Arduino tutorial about the MQTT communication protocol between machines m2m.

Brief overview about mqtt.

Download and install Mosquitto on a raspberry pi:
Command lines:
wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key

sudo apt-key add mosquitto-repo.gpg.key

cd /etc/apt/sources.list.d/

sudo wget http://repo.mosquitto.org/debian/mosquitto-wheezy.list

sudo -i

apt-get update

apt-get install mosquitto

link to the arduino code: https://create.arduino.cc/editor/LogMaker360/8e970f25-fb19-4b9a-8045-9ab864e3ec95/preview

Python code is in the arduino sketch.

command line
to see all the published topics and text:
mosquitto_sub -v -t “#”
to see a specific topic like “ledStatus”:
mosquitto_sub -h 192.168.0.106 -i testLED -t ledStatus //repace the ip address with your broker IP.
to publish a new message to a topic (ledStatus):
mosquitto_pub -h 192.168.0.106 -t ledStatus -m “0” // replace IP with your broker IP

install the python mqtt library paho-mqtt on Raspberry pi:

pip install paho-mqtt

Link to install mosquitto on Windows:
Step by step installing and configuring Mosquitto with Windows 7

source

Reply


Build A Site Info