-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwatchtext.py
35 lines (30 loc) · 1.07 KB
/
watchtext.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
35
import sys
import paho.mqtt.client as mqtt
last_message = ""
client = mqtt.Client("dalek-python")
client.connect("localhost")
def on_message(client, userdata, message):
"""
Enables the Dalek to receive a message from an Epruino Watch via
MQTT over Bluetooth (BLE) to place it into active or inactive States
"""
global last_message
payload = str(message.payload.decode("utf-8"))
if payload != last_message:
last_message = payload
event = payload[2:].lower()
print("Event: ",str(event))
#if command[1] == "Dale" and command[2] == "face" and command[3] == "on":
# dalek.on_event('waiting')
#if command[1] == "Dale" and command[2] == "face" and command[3] == "off":
# dalek.on_event('silent')
#else:
#dalek.on_event('unknown')
client.on_message = on_message # attach function to callback
client.subscribe("/ble/advertise/d3:fe:97:d2:d1:9e/espruino/m")
while True:
try:
client.loop(0.1)
except KeyboardInterrupt:
print("Stopped by CTRL+C")
sys.exit(0)