Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paho.mqtt.client as mqtt
- MQTT_Broker = "iot.eclipse.org"
- MQTT_Port = 1883
- Keep_Alive_Interval = 60
- MQTT_Topic = 'Errors1'
- #Subscribe to all Sensors at Base Topic
- def on_connect(mosq, obj, rc):
- mqttc.subscribe(MQTT_Topic, 0)
- #Save Data into DB Table
- def on_message(mosq, obj, msg):
- # This is the Master Call for saving MQTT Data into DB
- # For details of "sensor_Data_Handler" function please refer "sensor_data_to_db.py"
- print("MQTT Data Received...")
- print("MQTT Topic: " + msg.topic)
- print("Data: " + msg.payload)
- def on_subscribe(mosq, obj, mid, granted_qos):
- pass
- mqttc = mqtt.Client()
- # Assign event callbacks
- mqttc.on_message = on_message
- mqttc.on_connect = on_connect
- mqttc.on_subscribe = on_subscribe
- # Connect
- x = mqttc.connect(MQTT_Broker, int(MQTT_Port), int(Keep_Alive_Interval))
- print("connected")
- # Continue the network loop
- mqttc.loop_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement