When I try and run the code below the screen remains blank and doesn't indicate the client is connected to the broker.
#! /usr/bin/python
import paho.mqtt.client as mqtt
broker = "localhost"
#define what happens after connection
def on_connect(rc):
print "Connection returned result: "+str(rc)
#On recipt of a message do action
def on_message(msg):
n = msg.payload
t = msg.topic
print t+" "+str(n)
# create broker
mqttc = mqtt.Client()
#define callbacks
mqttc.on_message = on_message
mqttc.on_connect = on_connect
#connect
mqttc.connect(broker, 1883, 60)
#Subscribe to topic
mqttc.subscribe("/sensor/rfid", 2)
#keep connected
mqttc.loop_forever()
I can verify that the broker is running properly since I was able to run
mosquitto_sub -t /sensor/rfid
and get messages sent from the MyMQTT app on my android phone. I also forgot to mention this is all on the raspberry pi with mosquitto, mosquitto-clients, and paho-mqtt installed.