Mercurial > code > home > repos > homeauto
annotate service/piNode/piNode.py @ 1754:92999dfbf321 default tip
add shelly support
author | drewp@bigasterisk.com |
---|---|
date | Tue, 04 Jun 2024 13:03:43 -0700 |
parents | 9d074317e16a |
children |
rev | line source |
---|---|
636 | 1 import logging, socket, json, time, pkg_resources |
182 | 2 import cyclone.web |
226 | 3 from rdflib import Namespace, URIRef, Literal, Graph, RDF, ConjunctiveGraph |
184
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
4 from rdflib.parser import StringInputSource |
636 | 5 from twisted.internet import reactor |
6 from twisted.internet.defer import inlineCallbacks, maybeDeferred, returnValue | |
347 | 7 from twisted.internet.threads import deferToThread |
182 | 8 from docopt import docopt |
636 | 9 import etcd3 |
466
1122016d16eb
stats handler, events output fix, build updaets
drewp@bigasterisk.com
parents:
408
diff
changeset
|
10 from greplin import scales |
1122016d16eb
stats handler, events output fix, build updaets
drewp@bigasterisk.com
parents:
408
diff
changeset
|
11 from greplin.scales.cyclonehandler import StatsHandler |
1681 | 12 import os |
13 #os.environ['PIGPIO_ADDR'] = 'pigpio' # (aka the docker host) | |
636 | 14 import pigpio |
15 import treq | |
331
a94f2a522d41
build and import updates for rdfdb, etc
drewp@bigasterisk.com
parents:
325
diff
changeset
|
16 |
226 | 17 from patchablegraph import PatchableGraph, CycloneGraphHandler, CycloneGraphEventsHandler |
589
f397ec8bd13d
pinode devs can now poll in parallel (within one poll step). doesn't help much.
drewp@bigasterisk.com
parents:
553
diff
changeset
|
18 from cycloneerr import PrettyErrorHandler |
640
23ab244aa649
move bnode id optimization to its own file. more logging cleanups
drewp@bigasterisk.com
parents:
639
diff
changeset
|
19 from standardservice.logsetup import log, verboseLogging |
338
f64e20d3407e
RgbPixelsAnimation and docker build updates
drewp@bigasterisk.com
parents:
331
diff
changeset
|
20 from rdfdb.rdflibpatch import inContext |
f64e20d3407e
RgbPixelsAnimation and docker build updates
drewp@bigasterisk.com
parents:
331
diff
changeset
|
21 from rdfdb.patch import Patch |
640
23ab244aa649
move bnode id optimization to its own file. more logging cleanups
drewp@bigasterisk.com
parents:
639
diff
changeset
|
22 from rdflib_pi_opt import patchRandid |
23ab244aa649
move bnode id optimization to its own file. more logging cleanups
drewp@bigasterisk.com
parents:
639
diff
changeset
|
23 from export_to_influxdb import InfluxExporter |
182 | 24 |
25 import devices | |
233
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
230
diff
changeset
|
26 |
182 | 27 ROOM = Namespace('http://projects.bigasterisk.com/room/') |
28 HOST = Namespace('http://bigasterisk.com/ruler/host/') | |
29 | |
30 hostname = socket.gethostname() | |
233
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
230
diff
changeset
|
31 CTX = ROOM['pi/%s' % hostname] |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
230
diff
changeset
|
32 |
466
1122016d16eb
stats handler, events output fix, build updaets
drewp@bigasterisk.com
parents:
408
diff
changeset
|
33 STATS = scales.collection('/root', |
552
98384c3ccd33
update build and deps to use invoke and to use new lib layout, plus more stats collection
drewp@bigasterisk.com
parents:
466
diff
changeset
|
34 scales.PmfStat('configReread'), |
98384c3ccd33
update build and deps to use invoke and to use new lib layout, plus more stats collection
drewp@bigasterisk.com
parents:
466
diff
changeset
|
35 scales.IntStat('pollException'), |
625
69a84b3d1dfa
frontdoor configs; move device class timing to greplin stats
drewp@bigasterisk.com
parents:
624
diff
changeset
|
36 scales.PmfStat('pollAll'), |
552
98384c3ccd33
update build and deps to use invoke and to use new lib layout, plus more stats collection
drewp@bigasterisk.com
parents:
466
diff
changeset
|
37 scales.PmfStat('sendOneshot'), |
98384c3ccd33
update build and deps to use invoke and to use new lib layout, plus more stats collection
drewp@bigasterisk.com
parents:
466
diff
changeset
|
38 scales.PmfStat('outputStatements'), |
1681 | 39 scales.IntStat('oneshotSuccess'), |
40 scales.IntStat('oneshotFail'), | |
466
1122016d16eb
stats handler, events output fix, build updaets
drewp@bigasterisk.com
parents:
408
diff
changeset
|
41 ) |
258 | 42 |
183
634d6e477953
get piNode working, for motionsensor at least
drewp@bigasterisk.com
parents:
182
diff
changeset
|
43 class Config(object): |
1681 | 44 def __init__(self, masterGraph): |
45 log.info('connect to etcd-homeauto') | |
46 self.etcd = etcd3.client(host='etcd-homeauto', port=9022) | |
47 log.info('version %r', self.etcd.status().version) | |
48 | |
408
0787cd64ecf8
cmdline flag on piNode to pick hub host
drewp@bigasterisk.com
parents:
382
diff
changeset
|
49 |
347 | 50 self.masterGraph = masterGraph |
51 self.configGraph = ConjunctiveGraph() | |
52 self.boards = [] | |
53 self.etcPrefix = 'pi/' | |
628
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
54 self.rereadLater = None |
347 | 55 |
56 self.reread() | |
57 | |
58 deferToThread(self.watchEtcd) | |
59 | |
60 def watchEtcd(self): | |
408
0787cd64ecf8
cmdline flag on piNode to pick hub host
drewp@bigasterisk.com
parents:
382
diff
changeset
|
61 events, cancel = self.etcd.watch_prefix(self.etcPrefix) |
347 | 62 reactor.addSystemEventTrigger('before', 'shutdown', cancel) |
63 for ev in events: | |
64 log.info('%s changed', ev.key) | |
65 reactor.callFromThread(self.configChanged) | |
66 | |
67 def configChanged(self): | |
68 self.cancelRead() | |
69 self.rereadLater = reactor.callLater(.1, self.reread) | |
70 | |
71 def cancelRead(self): | |
628
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
72 if self.rereadLater: |
347 | 73 self.rereadLater.cancel() |
74 self.rereadLater = None | |
552
98384c3ccd33
update build and deps to use invoke and to use new lib layout, plus more stats collection
drewp@bigasterisk.com
parents:
466
diff
changeset
|
75 |
98384c3ccd33
update build and deps to use invoke and to use new lib layout, plus more stats collection
drewp@bigasterisk.com
parents:
466
diff
changeset
|
76 @STATS.configReread.time() |
347 | 77 def reread(self): |
78 self.rereadLater = None | |
183
634d6e477953
get piNode working, for motionsensor at least
drewp@bigasterisk.com
parents:
182
diff
changeset
|
79 log.info('read config') |
347 | 80 self.configGraph = ConjunctiveGraph() |
408
0787cd64ecf8
cmdline flag on piNode to pick hub host
drewp@bigasterisk.com
parents:
382
diff
changeset
|
81 for v, md in self.etcd.get_prefix(self.etcPrefix): |
347 | 82 log.info(' read file %r', md.key) |
83 self.configGraph.parse(StringInputSource(v), format='n3') | |
84 self.configGraph.bind('', ROOM) | |
85 self.configGraph.bind('rdf', RDF) | |
233
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
230
diff
changeset
|
86 # config graph is too noisy; maybe make it a separate resource |
347 | 87 #masterGraph.patch(Patch(addGraph=self.configGraph)) |
88 self.setupBoards() | |
624 | 89 |
90 def setupBoards(self): | |
347 | 91 thisHost = Literal(hostname) |
92 for row in self.configGraph.query( | |
93 'SELECT ?board WHERE { ?board a :PiBoard; :hostname ?h }', | |
94 initBindings=dict(h=thisHost)): | |
95 thisBoard = row.board | |
96 break | |
97 else: | |
98 log.warn("config had no board for :hostname %s. Waiting for config update." % | |
99 thisHost) | |
100 self.boards = [] | |
101 return | |
102 | |
103 log.info("found config for board %r" % thisBoard) | |
1681 | 104 self.boards = [Board(self.configGraph, self.masterGraph, thisBoard)] |
347 | 105 |
182 | 106 |
628
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
107 class DeviceRunner(object): |
642 | 108 def __init__(self, dev, masterGraph, sendOneshot, influx): |
628
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
109 self.dev = dev |
642 | 110 self.masterGraph = masterGraph |
111 self.sendOneshot = sendOneshot | |
112 self.influx = influx | |
628
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
113 self.period = getattr(self.dev, 'pollPeriod', .05) |
642 | 114 self.latestStatementsFromInputs = set() |
115 self.lastPollTime = None | |
628
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
116 |
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
117 reactor.callLater(0, self.poll) |
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
118 |
642 | 119 def syncMasterGraphToHostStatements(self): |
120 hostStmtCtx = URIRef(self.dev.uri + '/host') | |
121 newQuads = inContext(self.dev.hostStatements(), hostStmtCtx) | |
122 p = self.masterGraph.patchSubgraph(hostStmtCtx, newQuads) | |
123 if p: | |
124 log.debug("patch master with these host stmts %s", p) | |
125 | |
628
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
126 @inlineCallbacks |
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
127 def poll(self): |
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
128 now = time.time() |
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
129 try: |
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
130 with self.dev.stats.poll.time(): |
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
131 new = yield maybeDeferred(self.dev.poll) |
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
132 finally: |
642 | 133 reactor.callLater(max(0, self.period - (time.time() - now)), self.poll) |
134 | |
135 if isinstance(new, dict): # new style | |
136 oneshot = set(new['oneshot']) | |
137 new = set(new['latest']) | |
138 else: | |
139 oneshot = set() | |
140 new = set(new) | |
141 | |
142 prev = self.latestStatementsFromInputs | |
143 # it's important that quads from different devices | |
144 # don't clash, since that can lead to inconsistent | |
145 # patches (e.g. | |
146 # dev1 changes value from 1 to 2; | |
147 # dev2 changes value from 2 to 3; | |
148 # dev1 changes from 2 to 4 but this patch will | |
149 # fail since the '2' statement is gone) | |
150 self.masterGraph.patch(Patch.fromDiff(inContext(prev, self.dev.uri), | |
151 inContext(new, self.dev.uri))) | |
152 self.latestStatementsFromInputs = new | |
153 | |
154 self.syncMasterGraphToHostStatements() # needed? | |
155 | |
156 if oneshot: | |
157 self.sendOneshot(oneshot) | |
158 self.lastPollTime = now | |
159 | |
160 if self.latestStatementsFromInputs: | |
161 self.influx.exportToInflux(set.union(set(self.latestStatementsFromInputs))) | |
162 | |
628
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
163 returnValue(new) |
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
164 |
642 | 165 def filterIncomingStatements(self, stmts): |
166 wanted = set() | |
167 unwanted = set(stmts) | |
168 for pat in self.dev.outputPatterns(): | |
169 if [term is None for term in pat] != [False, False, True]: | |
170 raise NotImplementedError | |
171 for stmt in stmts: | |
172 if stmt[:2] == pat[:2]: | |
173 wanted.add(stmt) | |
174 unwanted.discard(stmt) | |
175 return wanted, unwanted | |
176 | |
177 def onPutStatements(self, stmts): | |
178 log.info("output goes to action handler for %s" % self.dev.uri) | |
179 with self.dev.stats.output.time(): | |
180 self.dev.sendOutput(stmts) | |
181 self.syncMasterGraphToHostStatements() | |
182 | |
1681 | 183 def sendOneshot(oneshot): |
184 body = (' '.join('%s %s %s .' % (s.n3(), p.n3(), o.n3()) | |
185 for s,p,o in oneshot)).encode('utf8') | |
186 url = 'http://reasoning:9071/oneShot' | |
187 log.debug('post to %r', url) | |
188 d = treq.post( | |
189 url=url.encode('ascii'), | |
190 headers={b'Content-Type': [b'text/n3']}, | |
191 data=body, | |
192 timeout=5) | |
193 | |
194 def ok(k): | |
195 log.debug('sendOneshot to %r success', url) | |
196 STATS.oneshotSuccess += 1 | |
197 def err(e): | |
198 log.info('oneshot post to %r failed: %s', | |
199 url, e.getErrorMessage()) | |
200 STATS.oneshotFail += 1 | |
201 d.addCallbacks(ok, err) | |
202 | |
182 | 203 class Board(object): |
204 """similar to arduinoNode.Board but without the communications stuff""" | |
1681 | 205 def __init__(self, graph, masterGraph, uri): |
182 | 206 self.graph, self.uri = graph, uri |
226 | 207 self.masterGraph = masterGraph |
636 | 208 |
349
88bd46f4e28c
more robust about not accumulating old stmts
drewp@bigasterisk.com
parents:
347
diff
changeset
|
209 self.masterGraph.setToGraph(self.staticStmts()) |
182 | 210 self.pi = pigpio.pi() |
642 | 211 |
293 | 212 self._influx = InfluxExporter(self.graph) |
642 | 213 self._runners = [DeviceRunner(d, self.masterGraph, self.sendOneshot, self._influx) |
214 for d in devices.makeDevices(graph, self.uri, self.pi)] | |
215 log.debug('found %s devices', len(self._runners)) | |
552
98384c3ccd33
update build and deps to use invoke and to use new lib layout, plus more stats collection
drewp@bigasterisk.com
parents:
466
diff
changeset
|
216 |
98384c3ccd33
update build and deps to use invoke and to use new lib layout, plus more stats collection
drewp@bigasterisk.com
parents:
466
diff
changeset
|
217 @STATS.sendOneshot.time() |
642 | 218 def sendOneshot(self, oneshot): |
1681 | 219 sendOneshot(oneshot) |
251
254df9f881a6
start sending oneshot events from some devices
drewp@bigasterisk.com
parents:
243
diff
changeset
|
220 |
552
98384c3ccd33
update build and deps to use invoke and to use new lib layout, plus more stats collection
drewp@bigasterisk.com
parents:
466
diff
changeset
|
221 @STATS.outputStatements.time() |
642 | 222 def outputStatements(self, stmts: set): |
223 if not stmts: | |
224 return | |
225 for devRunner in self._runners: | |
226 wanted, unwanted = devRunner.filterIncomingStatements(stmts) | |
227 log.info(f'\ndev {devRunner.dev.uri}:n wanted {wanted}. unwanted {unwanted}') | |
228 if len(wanted) == len(stmts): | |
229 devRunner.onPutStatements(stmts) | |
230 break | |
231 elif len(unwanted) == len(stmts): | |
232 continue | |
233 else: | |
234 raise NotImplementedError(f'dev {devRunner.dev.uri} wanted only {wanted}') | |
235 else: | |
233
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
230
diff
changeset
|
236 log.info("Board %s doesn't care about these statements:", self.uri) |
1681 | 237 for s in unwanted: |
233
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
230
diff
changeset
|
238 log.warn("%r", s) |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
230
diff
changeset
|
239 |
226 | 240 def staticStmts(self): |
233
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
230
diff
changeset
|
241 return [(HOST[hostname], ROOM['connectedTo'], self.uri, CTX)] |
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
230
diff
changeset
|
242 |
183
634d6e477953
get piNode working, for motionsensor at least
drewp@bigasterisk.com
parents:
182
diff
changeset
|
243 def description(self): |
634d6e477953
get piNode working, for motionsensor at least
drewp@bigasterisk.com
parents:
182
diff
changeset
|
244 """for web page""" |
634d6e477953
get piNode working, for motionsensor at least
drewp@bigasterisk.com
parents:
182
diff
changeset
|
245 return { |
634d6e477953
get piNode working, for motionsensor at least
drewp@bigasterisk.com
parents:
182
diff
changeset
|
246 'uri': self.uri, |
642 | 247 'devices': [d.dev.description() for d in self._runners], |
183
634d6e477953
get piNode working, for motionsensor at least
drewp@bigasterisk.com
parents:
182
diff
changeset
|
248 'graph': 'http://sticker:9059/graph', #todo |
628
accbbd521ecd
wip for pytype support and separate device run loops on piNode
drewp@bigasterisk.com
parents:
627
diff
changeset
|
249 } |
624 | 250 |
184
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
251 def rdfGraphBody(body, headers): |
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
252 g = Graph() |
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
253 g.parse(StringInputSource(body), format='nt') |
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
254 return g |
183
634d6e477953
get piNode working, for motionsensor at least
drewp@bigasterisk.com
parents:
182
diff
changeset
|
255 |
591 | 256 class OutputPage(PrettyErrorHandler, cyclone.web.RequestHandler): |
182 | 257 def put(self): |
184
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
258 arg = self.request.arguments |
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
259 if arg.get('s') and arg.get('p'): |
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
260 subj = URIRef(arg['s'][-1]) |
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
261 pred = URIRef(arg['p'][-1]) |
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
262 turtleLiteral = self.request.body |
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
263 try: |
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
264 obj = Literal(float(turtleLiteral)) |
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
265 except ValueError: |
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
266 obj = Literal(turtleLiteral) |
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
267 stmt = (subj, pred, obj) |
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
268 else: |
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
269 g = rdfGraphBody(self.request.body, self.request.headers) |
e052416a2290
piNode allow nt graphs as the body of a PUT /output
drewp@bigasterisk.com
parents:
183
diff
changeset
|
270 assert len(g) == 1, len(g) |
636 | 271 stmt = next(g.triples((None, None, None))) |
182 | 272 |
347 | 273 for b in self.settings.config.boards: |
636 | 274 b.outputStatements({stmt}) |
182 | 275 |
591 | 276 class Boards(PrettyErrorHandler, cyclone.web.RequestHandler): |
183
634d6e477953
get piNode working, for motionsensor at least
drewp@bigasterisk.com
parents:
182
diff
changeset
|
277 def get(self): |
634d6e477953
get piNode working, for motionsensor at least
drewp@bigasterisk.com
parents:
182
diff
changeset
|
278 self.set_header('Content-type', 'application/json') |
634d6e477953
get piNode working, for motionsensor at least
drewp@bigasterisk.com
parents:
182
diff
changeset
|
279 self.write(json.dumps({ |
233
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
230
diff
changeset
|
280 'host': hostname, |
347 | 281 'boards': [b.description() for b in self.settings.config.boards] |
183
634d6e477953
get piNode working, for motionsensor at least
drewp@bigasterisk.com
parents:
182
diff
changeset
|
282 }, indent=2)) |
624 | 283 |
182 | 284 def main(): |
285 arg = docopt(""" | |
286 Usage: piNode.py [options] | |
287 | |
408
0787cd64ecf8
cmdline flag on piNode to pick hub host
drewp@bigasterisk.com
parents:
382
diff
changeset
|
288 -v Verbose |
0787cd64ecf8
cmdline flag on piNode to pick hub host
drewp@bigasterisk.com
parents:
382
diff
changeset
|
289 --ow Just report onewire device URIs and readings, then exit. |
182 | 290 """) |
640
23ab244aa649
move bnode id optimization to its own file. more logging cleanups
drewp@bigasterisk.com
parents:
639
diff
changeset
|
291 verboseLogging(arg['-v']) |
233
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
230
diff
changeset
|
292 |
408
0787cd64ecf8
cmdline flag on piNode to pick hub host
drewp@bigasterisk.com
parents:
382
diff
changeset
|
293 if arg['--ow']: |
0787cd64ecf8
cmdline flag on piNode to pick hub host
drewp@bigasterisk.com
parents:
382
diff
changeset
|
294 log.setLevel(logging.INFO) |
0787cd64ecf8
cmdline flag on piNode to pick hub host
drewp@bigasterisk.com
parents:
382
diff
changeset
|
295 for stmt in devices.OneWire().poll(): |
636 | 296 print(stmt) |
408
0787cd64ecf8
cmdline flag on piNode to pick hub host
drewp@bigasterisk.com
parents:
382
diff
changeset
|
297 return |
624 | 298 |
640
23ab244aa649
move bnode id optimization to its own file. more logging cleanups
drewp@bigasterisk.com
parents:
639
diff
changeset
|
299 patchRandid() |
23ab244aa649
move bnode id optimization to its own file. more logging cleanups
drewp@bigasterisk.com
parents:
639
diff
changeset
|
300 |
226 | 301 masterGraph = PatchableGraph() |
1681 | 302 config = Config(masterGraph) |
624 | 303 |
552
98384c3ccd33
update build and deps to use invoke and to use new lib layout, plus more stats collection
drewp@bigasterisk.com
parents:
466
diff
changeset
|
304 static = pkg_resources.resource_filename('homeauto_anynode', 'static/') |
98384c3ccd33
update build and deps to use invoke and to use new lib layout, plus more stats collection
drewp@bigasterisk.com
parents:
466
diff
changeset
|
305 |
182 | 306 reactor.listenTCP(9059, cyclone.web.Application([ |
627
c3f0a98fa65d
lib upgrades; fix a static http server path
drewp@bigasterisk.com
parents:
625
diff
changeset
|
307 (r"/(|output-widgets.html)", cyclone.web.StaticFileHandler, { |
552
98384c3ccd33
update build and deps to use invoke and to use new lib layout, plus more stats collection
drewp@bigasterisk.com
parents:
466
diff
changeset
|
308 "path": static, "default_filename": "index.html"}), |
553 | 309 (r'/static/(.*)', cyclone.web.StaticFileHandler, {"path": static}), |
466
1122016d16eb
stats handler, events output fix, build updaets
drewp@bigasterisk.com
parents:
408
diff
changeset
|
310 (r'/stats/(.*)', StatsHandler, {'serverName': 'piNode'}), |
233
4ebb5cc30002
server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp@bigasterisk.com
parents:
230
diff
changeset
|
311 (r'/boards', Boards), |
226 | 312 (r"/graph", CycloneGraphHandler, {'masterGraph': masterGraph}), |
313 (r"/graph/events", CycloneGraphEventsHandler, {'masterGraph': masterGraph}), | |
182 | 314 (r'/output', OutputPage), |
466
1122016d16eb
stats handler, events output fix, build updaets
drewp@bigasterisk.com
parents:
408
diff
changeset
|
315 ], config=config, debug=arg['-v']), interface='::') |
258 | 316 log.warn('serving on 9059') |
182 | 317 reactor.run() |
318 | |
1681 | 319 if __name__ == '__main__': |
320 main() |