-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconnect.py
More file actions
37 lines (30 loc) · 774 Bytes
/
connect.py
File metadata and controls
37 lines (30 loc) · 774 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
31
32
33
34
35
import requests
server = "http://localhost:5000"
# get list of GPIOs
url = "%s/gpio"%(server, )
print "Getting from", url
r = requests.get(url)
print "- return code", r.status_code
print "- data:", r.json()
print ""
# get value for A0
url = "%s/gpio/A0"%(server, )
print "Getting from", url
r = requests.get(url)
getData = r.json()
print "- return code", r.status_code
print "- data:", getData
print ""
# set (using put) value for A0
putData = {'data': str(int(getData['value'])+2) }
print "Putting data", putData, "to", url
r = requests.put(url, json=putData)
print "- return code", r.status_code
print ""
# get newvalue for A0
print "Getting from", url
r = requests.get(url)
getData = r.json()
print "- return code", r.status_code
print "- data:", getData
print ""