-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathraspberrypi.py
More file actions
30 lines (27 loc) · 768 Bytes
/
raspberrypi.py
File metadata and controls
30 lines (27 loc) · 768 Bytes
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
import serial
import RPi.GPIO
import urllib2
import json
hostname = 'http://139.199.168.197:5000/dachuang/api/v1/allHardware'
ser = serial.Serial('/dev/ttyACM0', 9600, timeout = 4)
while 1:
r = urllib2.Request(hostname)
r = urllib2.urlopen(r)
res = r.read()
result = json.loads(res)
print result
send = ''
if result[0]['status'] == 1:
send += 'a'
else:
send += 'A'
if result[1]['status'] == 1:
send += 'b'
else:
send += 'B'
ser.write(send)
response = ser.readall()
if '' != response:
response = response[0:2]
ret = urllib2.Request("http://139.199.168.197:5000/dachuang/api/v1/updateHardware?hardwarename=tempUnit&status=3" + '&num=' + response)
ret = urllib2.urlopen(ret)