Skip to content
Permalink
4314b47c03
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
28 lines (20 sloc) 721 Bytes
import sys
import paho.mqtt.client as paho
def message_handling(client, userdata, msg):
print(f"{msg.topic}: {msg.payload.decode()}")
client = paho.Client()
client.on_message = message_handling
if client.connect("localhost", 1883, 60) != 0:
print("Couldn't connect to the mqtt broker")
sys.exit(1)
client.subscribe("location/CityName/DistrictName/Device123")
client.subscribe("status/CityName/DistrictName/Device123")
client.subscribe("alerts/CityName/DistrictName/Device123")
try:
print("Press CTRL+C to exit...")
client.loop_forever()
except Exception:
print("Caught an Exception, something went wrong...")
finally:
print("Disconnecting from the MQTT broker")
client.disconnect()