-
Notifications
You must be signed in to change notification settings - Fork 0
/
mqtt_sub_app.py
34 lines (25 loc) · 997 Bytes
/
mqtt_sub_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Include the Paho Mqtt https://pypi.org/project/paho-mqtt/
import paho.mqtt.client as mqtt
import time
# def IR_inside(client, userdata, message):
# print("Received message '" + str(message.payload) + "' on topic '"
# + message.topic + "' with QoS " + str(message.qos))
# print("position 3")
# Printing publishers message
def on_message(client, userdata, message):
# print the payload of the message and decode
print ("Recieved message: ", str(message.payload.decode("utf-8")))
mqttBroker = "mqtt.eclipseprojects.io"
client = mqtt.Client("Application")
client.connect(mqttBroker)
# Loop for 30 seconds subscribe to temp topic
client.loop_start()
client.subscribe("PEOPLE")
# Recieved message
client.on_message = on_message
# client.message_callback_add("PEOPLE/Inside_IR", IR_inside)
# client.on_message = on_message
# ENTER CODE HERE Subtract people if IR_inside then IR_Outside
# ENTER CODE HERE Add if IR_outside then IR_inside
time.sleep(30)
client.loop_end()