24 lines
586 B
Python
24 lines
586 B
Python
import paho.mqtt.client as mqtt
|
|
|
|
|
|
def on_connect(client, userdata, flags, rc):
|
|
print("Connected with result code "+str(rc))
|
|
|
|
# Subscribing in on_connect() means that if we lose the connection and
|
|
# reconnect then subscriptions will be renewed.
|
|
client.subscribe("Rover/Debug")
|
|
|
|
|
|
def on_message(client, userdata, msg):
|
|
print(msg.topic+" -> "+str(msg.payload)[2:-1])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
client = mqtt.Client()
|
|
client.on_connect = on_connect
|
|
client.on_message = on_message
|
|
|
|
client.connect("172.22.64.216", 1883, 60)
|
|
|
|
client.loop_forever()
|