I have installed mosquitto on Ubuntu 15.10 using the following command
sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update
To check if Mosquitto is installed i type mosquitto and it shows all the details as follows:
1458716686: mosquitto version 1.4.8 (build date Sun, 14 Feb 2016 15:48:26 +0000) starting
1458716686: Using default config.
1458716686: Opening ipv4 listen socket on port 1883.
1458716686: Opening ipv6 listen socket on port 1883.
Which implies mosquitto is working right?
So i proceed with my program written in python. (Pyton version 2.7)
import mosquitto
mqttc = mosquitto.Mosquitto("python_pub")
mqttc.will_set("/event/dropped", "Sorry, I seem to have died.")
mqttc.connect("127.0.0.1", 1883, 60, True)
mqttc.publish("hello/world", "Hello, World!")
On running the above program i get this error
ImportError: No module named mosquitto
I am new to the whole mqtt concept. Please let me know where i went wrong
The mosquitto python module is no longer part of the Eclipse Mosquitto project, it has moved to the Eclipse Paho project instead.
You can install it with pip install paho-mqtt or pip3 install paho-mqtt.
You could then do:
import paho.mqtt as paho
mqttc = paho.Client()
...
The remainder of the API is largely the same, it has just been expanded and improved.
http://www.eclipse.org/paho/clients/python/ says:
import paho.mqtt.client as mqtt
client = mqtt.Client()
check another code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With