Mercurial > code > home > repos > homeauto
annotate service/garageArduino/garageArduino.py @ 44:55b68d1e8212
opening usb apparently causes an arduino restart now, so i have to wait for that to pass before beginning communications
Ignore-this: 9f34e8914c6bbe3fb54b2c8f5ed01804
author | drewp@bigasterisk.com |
---|---|
date | Sat, 29 Dec 2012 04:54:54 -0800 |
parents | 62b3bb861e35 |
children | 69b214997213 |
rev | line source |
---|---|
0 | 1 #!bin/python |
2 """ | |
3 talks to frontdoordriver.pde on an arduino | |
4 """ | |
5 | |
6 from __future__ import division | |
7 | |
34
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
8 import cyclone.web, json, traceback, os, sys, time, logging, bitstring |
5
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
9 from twisted.internet import reactor, task, defer |
0 | 10 from twisted.web.client import getPage |
11 sys.path.append("/my/proj/house/frontdoor") | |
12 from loggingserial import LoggingSerial | |
5
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
13 sys.path.append("/my/proj/homeauto/lib") |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
14 from cycloneerr import PrettyErrorHandler |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
15 from logsetup import log |
0 | 16 sys.path.append("../../../room") |
17 from carbondata import CarbonClient | |
18 sys.path.append("/my/site/magma") | |
19 from stategraph import StateGraph | |
20 from rdflib import Namespace, RDF, Literal | |
34
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
21 from webcolors import hex_to_rgb, rgb_to_hex |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
22 |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
23 def rgbFromHex(h): |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
24 """returns tuple of 0..1023""" |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
25 norm = hex_to_rgb(h) |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
26 return tuple([x * 4 for x in norm]) |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
27 |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
28 def hexFromRgb(rgb): |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
29 return rgb_to_hex(tuple([x // 4 for x in rgb])) |
5
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
30 |
0 | 31 |
32 ROOM = Namespace("http://projects.bigasterisk.com/room/") | |
33 DEV = Namespace("http://projects.bigasterisk.com/device/") | |
34 | |
35 class ArduinoGarage(object): | |
36 def __init__(self, port='/dev/ttyACM0'): | |
37 self.ser = LoggingSerial(port=port, baudrate=115200, timeout=1) | |
44
55b68d1e8212
opening usb apparently causes an arduino restart now, so i have to wait for that to pass before beginning communications
drewp@bigasterisk.com
parents:
40
diff
changeset
|
38 time.sleep(2) # wait for a arduino reset to pass |
0 | 39 self.ser.flush() |
44
55b68d1e8212
opening usb apparently causes an arduino restart now, so i have to wait for that to pass before beginning communications
drewp@bigasterisk.com
parents:
40
diff
changeset
|
40 self.ping() |
0 | 41 |
42 def ping(self): | |
43 self.ser.write("\x60\x00\x00") | |
44 msg = self.ser.readJson() | |
45 assert msg == {"ok":True}, msg | |
46 | |
47 def poll(self): | |
48 self.ser.write("\x60\x01\x00") | |
49 ret = self.ser.readJson() | |
50 return ret | |
51 | |
52 def lastLevel(self): | |
53 self.ser.write("\x60\x02\x00") | |
54 return self.ser.readJson()['z'] | |
55 | |
56 def setThreshold(self, t): | |
57 """set 10-bit threshold""" | |
58 self.ser.write("\x60\x03"+chr(max(1 << 2, t) >> 2)) | |
59 return self.ser.readJson()['threshold'] | |
60 | |
5
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
61 def setGarage(self, level): |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
62 """set garage door opener pin""" |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
63 self.ser.write("\x60\x04"+chr(int(bool(level)))) |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
64 return self.ser.readJson()['garage'] |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
65 |
34
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
66 def setVideoSelect(self, chan): |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
67 """set video select bits from 0..3""" |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
68 self.ser.write("\x60\x05"+chr(chan)) |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
69 return self.ser.readJson()['videoSelect'] |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
70 |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
71 def shiftbrite(self, colors): |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
72 """ |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
73 shift out this sequence of (r,g,b) triples of 10-bit ints |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
74 """ |
40 | 75 resetCurrent = "".join(bitstring.pack("0b01, uint:10, uint:10, uint:10", |
76 127, 127, 127).bytes | |
77 for loop in range(len(colors))) | |
34
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
78 out = "".join(bitstring.pack("0b00, uint:10, uint:10, uint:10", |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
79 b, r, g).bytes |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
80 for r,g,b in colors) |
40 | 81 out = resetCurrent + out |
34
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
82 self.ser.write("\x60\x06" + chr(len(out)) + out) |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
83 msg = self.ser.readJson() |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
84 assert msg == {"ok":1}, msg |
0 | 85 |
86 class Index(PrettyErrorHandler, cyclone.web.RequestHandler): | |
87 def get(self): | |
88 """ | |
89 this is an acceptable status check since it makes a round-trip | |
90 to the arduino before returning success | |
91 """ | |
92 self.settings.arduino.ping() | |
93 | |
94 self.set_header("Content-Type", "application/xhtml+xml") | |
95 self.write(open("index.html").read()) | |
96 | |
97 class GraphPage(PrettyErrorHandler, cyclone.web.RequestHandler): | |
98 def get(self): | |
99 self.set_header("Content-Type", "application/x-trig") | |
100 g = StateGraph(ROOM['garageArduino']) | |
101 self.settings.poller.assertIsCurrent() | |
102 g.add((DEV['frontDoorMotion'], ROOM['state'], | |
103 ROOM['motion'] if self.settings.poller.lastValues['motion'] else | |
104 ROOM['noMotion'])) | |
105 g.add((ROOM['house'], ROOM['usingPower'], | |
106 Literal(self.settings.poller.lastWatts, datatype=ROOM["#watts"]))) | |
107 self.write(g.asTrig()) | |
108 | |
109 class FrontDoorMotion(PrettyErrorHandler, cyclone.web.RequestHandler): | |
110 def get(self): | |
111 self.set_header("Content-Type", "application/javascript") | |
112 self.settings.poller.assertIsCurrent() | |
113 self.write(json.dumps({"frontDoorMotion" : | |
114 self.settings.poller.lastValues['motion']})) | |
115 | |
116 class HousePower(PrettyErrorHandler, cyclone.web.RequestHandler): | |
117 def get(self): | |
118 self.set_header("Content-Type", "application/javascript") | |
119 self.settings.poller.assertIsCurrent() | |
120 w = self.settings.poller | |
121 self.write(json.dumps({ | |
122 "currentWatts" : round(w.lastWatts, 2) if isinstance(w.lastWatts, float) else w.lastWatts, | |
123 "lastPulseAgo" : "%.1f sec ago" % (time.time() - w.lastBlinkTime) if w.lastBlinkTime is not None else "unknown", | |
124 "kwhPerBlink" : w.kwhPerBlink})) | |
125 | |
126 class HousePowerRaw(PrettyErrorHandler, cyclone.web.RequestHandler): | |
127 """ | |
128 raw data from the analog sensor, for plotting or picking a noise threshold | |
129 """ | |
130 def get(self): | |
131 self.set_header("Content-Type", "application/javascript") | |
4
be855a111619
move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
0
diff
changeset
|
132 pts = [] |
be855a111619
move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
0
diff
changeset
|
133 for i in range(60): |
be855a111619
move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
0
diff
changeset
|
134 level = self.settings.arduino.lastLevel() |
be855a111619
move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
0
diff
changeset
|
135 pts.append((round(time.time(), 3), level)) |
be855a111619
move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
0
diff
changeset
|
136 |
be855a111619
move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
0
diff
changeset
|
137 self.write(json.dumps({"irLevels" : pts})) |
0 | 138 |
139 class HousePowerThreshold(PrettyErrorHandler, cyclone.web.RequestHandler): | |
140 """ | |
141 the level that's between between an IR pulse and the noise | |
142 """ | |
143 def get(self): | |
144 self.set_header("Content-Type", "application/javascript") | |
145 self.settings.poller.assertIsCurrent() | |
146 self.write(json.dumps({"threshold" : thr})) | |
147 | |
148 def put(self): | |
149 pass | |
150 | |
5
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
151 class GarageDoorOpen(PrettyErrorHandler, cyclone.web.RequestHandler): |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
152 def post(self): |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
153 self.set_header("Content-Type", "text/plain") |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
154 self.settings.arduino.setGarage(True) |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
155 self.write("pin high, waiting..\n") |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
156 self.flush() |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
157 d = defer.Deferred() |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
158 def finish(): |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
159 self.settings.arduino.setGarage(False) |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
160 self.write("pin low. Done") |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
161 d.callback(None) |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
162 reactor.callLater(1.5, finish) # this time depends on the LP circuit |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
163 return d |
0 | 164 |
34
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
165 class VideoSelect(PrettyErrorHandler, cyclone.web.RequestHandler): |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
166 def post(self): |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
167 self.set_header("Content-Type", "application/javascript") |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
168 v = self.settings.arduino.setVideoSelect(int(self.request.body)) |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
169 self.write(json.dumps({"videoSelect" : v})) |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
170 |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
171 class Brite(PrettyErrorHandler, cyclone.web.RequestHandler): |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
172 def get(self, chan): |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
173 self.set_header("Content-Type", "text/plain") |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
174 self.write(hexFromRgb(self.settings.colors[int(chan)])) |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
175 |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
176 def put(self, chan): |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
177 s = self.settings |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
178 s.colors[int(chan)] = rgbFromHex(self.request.body) |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
179 s.arduino.shiftbrite(s.colors) |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
180 post = put |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
181 |
0 | 182 class Application(cyclone.web.Application): |
183 def __init__(self, ard, poller): | |
184 handlers = [ | |
185 (r"/", Index), | |
186 (r"/graph", GraphPage), | |
187 (r"/frontDoorMotion", FrontDoorMotion), | |
188 (r'/housePower', HousePower), | |
4
be855a111619
move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
0
diff
changeset
|
189 (r'/housePower/raw', HousePowerRaw), |
be855a111619
move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
0
diff
changeset
|
190 (r'/housePower/threshold', HousePowerThreshold), |
5
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
191 (r'/garageDoorOpen', GarageDoorOpen), |
34
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
192 (r'/videoSelect', VideoSelect), |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
193 (r"/brite/(\d+)", Brite), |
0 | 194 ] |
34
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
195 colors = [(0,0,0)] * 1 # stored 10-bit |
90ff65ccd46b
garage: videoselect and shiftbrite move from parallel to arduino
drewp@bigasterisk.com
parents:
13
diff
changeset
|
196 settings = {"arduino" : ard, "poller" : poller, "colors" : colors} |
0 | 197 cyclone.web.Application.__init__(self, handlers, **settings) |
198 | |
199 class Poller(object): | |
200 """ | |
201 times the blinks to estimate power usage. Captures the other | |
202 returned sensor values too in self.lastValues | |
203 """ | |
204 def __init__(self, ard, period): | |
205 self.ard = ard | |
206 self.period = period | |
207 self.carbon = CarbonClient(serverHost='bang') | |
208 self.lastBlinkTime = None | |
209 self.lastValues = None | |
210 self.lastPollTime = 0 | |
211 self.lastWatts = "(just restarted; wait no data yet)" | |
212 self.kwhPerBlink = 1.0 # unsure | |
213 self.lastMotion = False | |
214 | |
215 def assertIsCurrent(self): | |
216 """raise an error if the poll data is not fresh""" | |
217 dt = time.time() - self.lastPollTime | |
218 if dt > period * 2: | |
219 raise ValueError("last poll time was too old: %.1f sec ago" % dt) | |
220 | |
221 def poll(self): | |
222 now = time.time() | |
223 try: | |
224 try: | |
225 newData = ard.poll() | |
226 except ValueError, e: | |
227 print e | |
44
55b68d1e8212
opening usb apparently causes an arduino restart now, so i have to wait for that to pass before beginning communications
drewp@bigasterisk.com
parents:
40
diff
changeset
|
228 os.abort() |
0 | 229 else: |
230 self.lastPollTime = now | |
231 self.lastValues = newData # for other data besides the blinks | |
232 self.processBlinks(now, newData['newBlinks']) | |
233 self.processMotion(newData['motion']) | |
234 | |
235 except (IOError, OSError): | |
236 os.abort() | |
237 except Exception, e: | |
238 print "poll error", e | |
239 traceback.print_exc() | |
240 | |
241 def processBlinks(self, now, b): | |
242 if b > 0: | |
243 if b > 1: | |
244 # todo: if it's like 1,1,2,2,2,2,1,1 then we | |
245 # need to subdivide those inner sample periods | |
246 # since there might really be two blinks. But | |
247 # if it's like 0,0,0,2,0,0, that should be | |
248 # treated like b=1 since it's probably noise | |
249 pass | |
250 | |
251 if self.lastBlinkTime is not None: | |
252 dt = now - self.lastBlinkTime | |
253 dth = dt / 3600. | |
254 watts = self.kwhPerBlink / dth | |
255 | |
256 if watts > 10000: | |
257 # this pulse (or the previous one) is | |
258 # likely noise. Too late for the previous | |
259 # one, but we're going to skip this one | |
260 return | |
261 else: | |
262 self.lastWatts = watts | |
263 | |
264 # todo: remove this; a separate logger shall do it | |
265 self.carbon.send('system.house.powerMeter_w', watts, now) | |
266 | |
267 self.lastBlinkTime = now | |
268 | |
269 def processMotion(self, state): | |
270 if state == self.lastMotion: | |
271 return | |
272 self.lastMotion = state | |
273 msg = json.dumps(dict(board='garage', | |
274 name="frontDoorMotion", state=state)) | |
275 getPage('http://bang.bigasterisk.com:9069/inputChange', | |
276 method="POST", | |
277 postdata=msg, | |
278 headers={'Content-Type' : 'application/json'} | |
279 ).addErrback(self.reportError, msg) | |
280 | |
281 def reportError(self, msg, *args): | |
282 print "post error", msg, args | |
283 | |
284 if __name__ == '__main__': | |
285 | |
286 config = { # to be read from a file | |
13 | 287 'arduinoPort': '/dev/serial/by-id/usb-Arduino__www.arduino.cc__Arduino_Uno_6493534323335161A2F1-if00', |
0 | 288 'servePort' : 9050, |
289 'pollFrequency' : 5, | |
290 'boardName' : 'garage', # gets sent with updates | |
291 } | |
292 | |
5
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
293 #from twisted.python import log as twlog |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
294 #twlog.startLogging(sys.stdout) |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
295 |
4c44c80a6a72
move garage door opener from parport to arduino
drewp@bigasterisk.com
parents:
4
diff
changeset
|
296 log.setLevel(logging.DEBUG) |
0 | 297 |
13 | 298 ard = ArduinoGarage(port=config['arduinoPort']) |
0 | 299 |
300 period = 1/config['pollFrequency'] | |
301 p = Poller(ard, period) | |
302 task.LoopingCall(p.poll).start(period) | |
303 reactor.listenTCP(config['servePort'], Application(ard, p)) | |
304 reactor.run() |