-
Notifications
You must be signed in to change notification settings - Fork 0
/
sinners.py
56 lines (46 loc) · 1.11 KB
/
sinners.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import socket
import json
import threading
import time
import socket_to_web
import raspi
import arduino
def log(text):
print text
try:
file_stat = open('status.json','r')
file_cmd = open('cmd.json','r')
except:
log("No files json. Script is close")
raise SystemExit(1)
try:
status_json = file_stat.read()
cmd_json = file_cmd.read()
except:
log("Read files json error. Script is close")
raise SystemExit(1)
try:
status = json.loads(status_json)
cmd = json.loads(cmd_json)
except:
log("Error decode json files. Script is close")
raise SystemExit(1)
web = socket_to_web.LinkToWeb(status, cmd)
inputs = raspi.RPi(status)
output = arduino.arduino(status)
try:
t1 = threading.Thread(target = web.start)
log("Socket Threading start")
t1.start()
while True:
status = web.read(status) #read commands for webserver
inputs.read() #read raspberry pi inputs
output.write() #send command to arduino on USB
if status['start']:
if time.localtime(time.time() - status['time']).tm_min > 0:
status = web.reset(status)
#time.sleep(1)
except:
web.stop()