-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlight.py
56 lines (47 loc) · 1.41 KB
/
light.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
import os
import sys
import json
#from webServer import *
#from raspberryPi import *
import RPi.GPIO as io
class light:
response = ''
lightEndPoint = '/light/?format=json'
lights = ''
def setPins(self):
for light in self.lights:
gpioPin = light['gpio']
print light['gpio']
io.setup(gpioPin,io.OUT)
def updateLightInfo(self,light):
self.lights = light
def updateStatus(self):
for light in self.lights:
gpioPin = light['gpio']
if light['status'] == True:
io.output(gpioPin,io.HIGH)
else:
io.output(gpioPin,io.LOW)
def registerLight(self,GPIO,label,webServer,raspberryPi):
data = {'raspberry_pi_id':raspberryPi.getId(),
'status':False,
'gpio':GPIO,
'label':label}
if webServer.postToDatabase(data,self.lightEndPoint):
return 'Light with GPIO: '+ str(GPIO) +' successfully registered'
else:
return 'Problem registering light with GPIO: '+str(GPIO)
#web = webServer()
#web.setUsername('test7')
#web.setPassword('test')
#web.setAuth()
#pi = raspberryPi(web)
#print pi.registerPi(web)
#pi.getPiData(web)
#light = light()
#light.registerLight(4, 'Living Room',web,pi)
#light.registerLight(8, 'Kitchen',web,pi)
#light.updateLightInfo(web)
#light.setPins()
#while 1:#
#light.updateStatus(web)