Minor example using MQTT and Python. forked project
Using test server: https://test.mosquitto.org/
Requires Mosquitto to be installed.
On Linux/Ubuntu with the apt-get package manager:
apt update
apt install mosquitto
apt install mosquitto-clients
o:
apt install mosquitto mosquitto-clients
On /etc/mosquitto/mosquito.conf
# comment all lines and put these
listener 1883 0.0.0.0
allow_anonymous true
mkdir /run/mosquitto
chown mosquitto: /run/mosquitto/
# Testing
mosquitto -c /etc/mosquitto/mosquitto.conf -v
# Port in use?
ps -ef | grep mosquitto
kill <pid_proces>
#finally
service mosquitto start
service mosquitto status
Simply clone this repo, setup virtualenv and use pip to install requirements.
git clone https://github.com/wisaaco/mosquitto-python-example
cd mqtt-mosquitto-example
pip install -r requirements.txt
client.connect("127.0.0.1", 1883, 60)
Start the subscriber which will enter a loop waiting for new messages:
python3 subscriber.py
(Only with PlanB) Then open a new terminal and send a message:
mosquitto_pub -d -h localhost -q 0 -t perros/pics -m "Bonito cachorrito de perro maltes"
This should generate a message in the terminal running the subscriber.
Take a look at publisher.py to see how to publish messages using python. Or just open another terminal and run it from command line while subscriber.py is running:
python3 publisher.py
- https://github.com/roppert/mosquitto-python-example
- http://jpmens.net/2013/02/25/lots-of-messages-mqtt-pub-sub-and-the-mosquitto-broker/
- https://www.justinribeiro.com/chronicle/2012/11/08/securing-mqtt-communication-between-ardruino-and-mosquitto/
- http://www.instructables.com/id/USB-RFID-Python-Pub-Sub-MQTT/
- http://mosquitto.org/documentation/python/
- https://pypi.python.org/pypi/paho-mqtt