I am unable to connect to mosquitto broker from Python. I can do it from command line using mosquitto_pub/sub. However, not from Python. Is there some form of a sandbox that you run Python scripts in?
I can run the test file from 3 other machines, that have mosquitto broker installed and running with default settings.
- sudo apt-get update
- sudo apt-get install mosquitto mosquitto-clients
- sudo service mosquitto status
My python test file:
import paho.mqtt.client as mqtt
def on_log(client, userdata, level, buf):
print("log: ", buf)
def on_connect(client, userdata, flag, rc):
m = c.publish(“house/bulbs/bulb1”, “OFF”)
c = mqtt.Client()
c.on_log = on_log
c.on_connect = on_connect
assert (c.connect(‘localhost’, 1883) == 0)