forked from rizasatyabudhi/MoodLamp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevent_listener.py
43 lines (33 loc) · 843 Bytes
/
event_listener.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
36
37
38
39
40
41
42
from socketio_client.manager import Manager
import gpio as led
import gevent
from gevent import monkey
monkey.patch_socket()
io = Manager('moodlight.cloudapp.net', 3000)
moodlamp = io.socket('/')
def turn_on_lamp(state):
led.reset()
if state == 'anger':
led.redOn()
elif state == 'joy':
led.yellowOn()
elif state == 'disgust':
led.greenOn()
elif state == 'sad':
led.blueOn()
elif state == 'contempt':
led.magentaOn()
elif state == 'surprise':
led.whiteOn()
elif state == 'fear':
led.cyanOn()
@moodlamp.on_connect()
def moodlamp_connect():
print('connect')
@moodlamp.on('state_changed')
def on_hello(*args):
current_state = args[0].encode("utf-8")
turn_on_lamp(current_state)
print(current_state)
moodlamp.connect()
gevent.wait()