-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
executable file
·57 lines (44 loc) · 1.1 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# -*- coding: utf-8 -*
#
# @author XU Kai([email protected])
# @date 2016-12-04 星期日
#
#
#
#
#
#
#
from conf import SERVER
try:
import RPi.GPIO as GPIO
import atexit
atexit.register(GPIO.cleanup)
except ImportError:
print('Not the Pi env !')
import directives
import logging
logging.getLogger('socketIO-client').setLevel(logging.DEBUG)
logging.basicConfig()
import os, socketIO_client
from socketIO_client import SocketIO, LoggingNamespace
def receiveDirectives(args):
directive = args['D']
if args.has_key('S'):
signal = args['S']
else:
signal = ''
global GPIO # Fuck the Global vars cost me severl hours ! :()
try:
GPIO
except NameError:
GPIO = {}
try:
getattr(__import__('directives.' + directive), directive).run(GPIO, signal)
except ImportError:
print('Directive not found on the CAR !')
if __name__ == "__main__" :
socketIO = SocketIO(SERVER['ip'], SERVER['port'], LoggingNamespace, params={'specify': 'CAR'})
socketIO.on('directives', receiveDirectives)
socketIO.wait()