-
Notifications
You must be signed in to change notification settings - Fork 1
/
libMotorPhoton.py
38 lines (29 loc) · 1.08 KB
/
libMotorPhoton.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
from commands import getoutput as go
import json
import time
class motorPhoton():
def __init__(self,name=None):
self.particle = name
self.ac = open("/home/labroot/ac").read().strip()
def getNames(self):
return go('curl -s https://api.particle.io/v1/devices?access_token=%s' % self.ac)
def setMotor(self,motor,mode,pwm):
out = str(motor)+str(mode)+str(pwm).rjust(3,"0")
return go('curl -s https://api.particle.io/v1/devices/%s/setMotor \
-d access_token=%s \
-d "args=%s"' % (self.particle,self.ac,out))
def getData(self):
data = go("curl -s -G https://api.spark.io/v1/devices/%s/lab2_data -d access_token=%s" % (self.particle,self.ac))
data = json.loads(data)
st = data['result']
data['result'] = json.loads(st)
data['result']['time'] = time.time()
return data['result']
if __name__ == "__main__":
b = motorPhoton("FearlessFearow")
print b.setMotor(0,0,55)
time.sleep(1)
a = b.getData()
keys = a.keys()
keys.sort()
for k in keys: print k,":",a[k]