Mercurial > code > home > repos > homeauto
annotate service/tomatoWifi/tomatoWifi.py @ 417:10ec2744fe8a
mongodb api upgrade
Ignore-this: 2a09182f26109a2744f98d6babc64293
author | drewp@bigasterisk.com |
---|---|
date | Sat, 30 Mar 2019 16:56:31 -0700 |
parents | 8f5a16a55f64 |
children | b3935eac90e1 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 """ | |
3 scrape the tomato router status pages to see who's connected to the | |
4 wifi access points. Includes leases that aren't currently connected. | |
5 | |
6 Returns: | |
7 json listing (for magma page) | |
8 rdf graph (for reasoning) | |
9 activity stream, when we start saving history | |
10 | |
11 Todo: this should be the one polling and writing to mongo, not entrancemusic | |
162 | 12 |
0 | 13 """ |
14 from __future__ import division | |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
50
diff
changeset
|
15 import sys, cyclone.web, json, traceback, time, pystache, datetime, logging |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
16 import web.utils |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
50
diff
changeset
|
17 from cyclone.httpclient import fetch |
383
8f5a16a55f64
various docker setups and build fixes
drewp@bigasterisk.com
parents:
340
diff
changeset
|
18 |
0 | 19 from dateutil import tz |
20 from twisted.internet import reactor, task | |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
21 from twisted.internet.defer import inlineCallbacks |
189 | 22 import docopt |
309 | 23 from influxdb import InfluxDBClient |
417 | 24 from pymongo import MongoClient as Connection, DESCENDING |
340 | 25 from rdflib import Namespace, Literal, URIRef, ConjunctiveGraph |
383
8f5a16a55f64
various docker setups and build fixes
drewp@bigasterisk.com
parents:
340
diff
changeset
|
26 |
0 | 27 from stategraph import StateGraph |
28 from wifi import Wifi | |
383
8f5a16a55f64
various docker setups and build fixes
drewp@bigasterisk.com
parents:
340
diff
changeset
|
29 |
340 | 30 from patchablegraph import PatchableGraph, CycloneGraphEventsHandler, CycloneGraphHandler |
383
8f5a16a55f64
various docker setups and build fixes
drewp@bigasterisk.com
parents:
340
diff
changeset
|
31 |
340 | 32 from rdfdb.patch import Patch |
0 | 33 |
34 from cycloneerr import PrettyErrorHandler | |
1 | 35 from logsetup import log |
0 | 36 |
36 | 37 |
0 | 38 DEV = Namespace("http://projects.bigasterisk.com/device/") |
39 ROOM = Namespace("http://projects.bigasterisk.com/room/") | |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
50
diff
changeset
|
40 reasoning = "http://bang:9071/" |
1 | 41 |
0 | 42 class Index(PrettyErrorHandler, cyclone.web.RequestHandler): |
43 def get(self): | |
44 | |
45 age = time.time() - self.settings.poller.lastPollTime | |
46 if age > 10: | |
47 raise ValueError("poll data is stale. age=%s" % age) | |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
48 |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
49 self.set_header("Content-Type", "text/html") |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
50 self.write(open("index.html").read()) |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
50
diff
changeset
|
51 |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
52 def whenConnected(mongo, macThatIsNowConnected): |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
53 lastArrive = None |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
54 for ev in mongo.find({'address': macThatIsNowConnected.upper()}, |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
55 sort=[('created', -1)], |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
56 max_scan=100000): |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
57 if ev['action'] == 'arrive': |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
58 lastArrive = ev |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
59 if ev['action'] == 'leave': |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
60 break |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
61 if lastArrive is None: |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
62 raise ValueError("no past arrivals") |
0 | 63 |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
64 return lastArrive['created'] |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
65 |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
66 def connectedAgoString(conn): |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
67 return web.utils.datestr( |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
68 conn.astimezone(tz.tzutc()).replace(tzinfo=None)) |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
69 |
0 | 70 class Table(PrettyErrorHandler, cyclone.web.RequestHandler): |
71 def get(self): | |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
72 def rowDict(row): |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
73 row['cls'] = "signal" if row.get('connected') else "nosignal" |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
74 if 'name' not in row: |
74
bca6d6c63bdc
handle wifi users with no clientHostname
drewp@bigasterisk.com
parents:
62
diff
changeset
|
75 row['name'] = row.get('clientHostname', '-') |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
76 if 'signal' not in row: |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
77 row['signal'] = 'yes' if row.get('connected') else 'no' |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
78 |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
79 try: |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
80 conn = whenConnected(self.settings.mongo, row.get('mac', '??')) |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
81 row['connectedAgo'] = connectedAgoString(conn) |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
82 except ValueError: |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
83 row['connectedAgo'] = 'yes' if row.get('connected') else '' |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
84 row['router'] = row.get('ssid', '') |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
85 return row |
0 | 86 |
87 self.set_header("Content-Type", "application/xhtml+xml") | |
88 self.write(pystache.render( | |
89 open("table.mustache").read(), | |
90 dict( | |
91 rows=sorted(map(rowDict, self.settings.poller.lastAddrs), | |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
92 key=lambda a: (not a.get('connected'), |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
93 a.get('name')))))) |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
94 |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
50
diff
changeset
|
95 |
0 | 96 class Json(PrettyErrorHandler, cyclone.web.RequestHandler): |
97 def get(self): | |
98 self.set_header("Content-Type", "application/json") | |
99 age = time.time() - self.settings.poller.lastPollTime | |
100 if age > 10: | |
101 raise ValueError("poll data is stale. age=%s" % age) | |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
50
diff
changeset
|
102 self.write(json.dumps({"wifi" : self.settings.poller.lastAddrs, |
0 | 103 "dataAge" : age})) |
104 | |
105 class Poller(object): | |
106 def __init__(self, wifi, mongo): | |
107 self.wifi = wifi | |
108 self.mongo = mongo | |
109 self.lastAddrs = [] | |
110 self.lastWithSignal = [] | |
111 self.lastPollTime = 0 | |
112 | |
113 def assertCurrent(self): | |
114 dt = time.time() - self.lastPollTime | |
115 assert dt < 10, "last poll was %s sec ago" % dt | |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
50
diff
changeset
|
116 |
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
50
diff
changeset
|
117 @inlineCallbacks |
340 | 118 def poll(self): |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
119 connectedField = 'connected' |
309 | 120 now = int(time.time()) |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
121 |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
122 # UVA mode: |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
123 addDhcpData = lambda *args: None |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
124 |
0 | 125 try: |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
50
diff
changeset
|
126 newAddrs = yield self.wifi.getPresentMacAddrs() |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
127 addDhcpData(newAddrs) |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
128 |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
129 newWithSignal = [a for a in newAddrs if a.get('connected')] |
0 | 130 |
131 actions = self.computeActions(newWithSignal) | |
309 | 132 points = [] |
0 | 133 for action in actions: |
1 | 134 log.info("action: %s", action) |
0 | 135 action['created'] = datetime.datetime.now(tz.gettz('UTC')) |
136 mongo.save(action) | |
309 | 137 points.append( |
138 self.influxPoint(now, action['address'].lower(), | |
139 1 if action['action'] == 'arrive' else 0)) | |
0 | 140 try: |
141 self.doEntranceMusic(action) | |
142 except Exception, e: | |
1 | 143 log.error("entrancemusic error: %r", e) |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
50
diff
changeset
|
144 |
309 | 145 if now // 3600 > self.lastPollTime // 3600: |
146 log.info('hourly writes') | |
147 for addr in newWithSignal: | |
148 points.append(self.influxPoint(now, addr['mac'].lower(), 1)) | |
149 | |
150 influx.write_points(points, time_precision='s') | |
0 | 151 self.lastWithSignal = newWithSignal |
50 | 152 if actions: # this doesn't currently include signal strength changes |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
50
diff
changeset
|
153 fetch(reasoning + "immediateUpdate", |
279 | 154 method='PUT', |
52 | 155 timeout=2, |
156 headers={'user-agent': ['tomatoWifi']}).addErrback(log.warn) | |
0 | 157 self.lastAddrs = newAddrs |
309 | 158 self.lastPollTime = now |
340 | 159 |
160 self.updateGraph(masterGraph) | |
0 | 161 except Exception, e: |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
162 log.error("poll error: %r\n%s", e, traceback.format_exc()) |
0 | 163 |
309 | 164 def influxPoint(self, now, address, value): |
165 return { | |
166 'measurement': 'presence', | |
167 'tags': {'sensor': 'wifi', 'address': address,}, | |
168 'fields': {'value': value}, | |
169 'time': now, | |
170 } | |
171 | |
0 | 172 def computeActions(self, newWithSignal): |
173 actions = [] | |
174 | |
175 def makeAction(addr, act): | |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
176 d = dict(sensor="wifi", |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
177 address=addr.get('mac').upper(), # mongo data is legacy uppercase |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
178 name=addr.get('name'), |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
179 networkName=addr.get('clientHostname'), |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
162
diff
changeset
|
180 action=act) |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
181 if act == 'arrive' and 'ip' in addr: |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
182 # this won't cover the possible case that you get on |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
183 # wifi but don't have an ip yet. We'll record an |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
184 # action with no ip and then never record your ip. |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
185 d['ip'] = addr['ip'] |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
186 return d |
0 | 187 |
188 for addr in newWithSignal: | |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
189 if addr['mac'] not in [r['mac'] for r in self.lastWithSignal]: |
0 | 190 actions.append(makeAction(addr, 'arrive')) |
191 | |
192 for addr in self.lastWithSignal: | |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
193 if addr['mac'] not in [r['mac'] for r in newWithSignal]: |
0 | 194 actions.append(makeAction(addr, 'leave')) |
195 | |
196 return actions | |
197 | |
198 | |
1 | 199 # these need to move out to their own service |
0 | 200 def doEntranceMusic(self, action): |
383
8f5a16a55f64
various docker setups and build fixes
drewp@bigasterisk.com
parents:
340
diff
changeset
|
201 import restkit, json |
0 | 202 dt = self.deltaSinceLastArrive(action['name']) |
1 | 203 log.debug("dt=%s", dt) |
0 | 204 if dt > datetime.timedelta(hours=1): |
205 hub = restkit.Resource( | |
206 # PSHB not working yet; "http://bang:9030/" | |
207 "http://slash:9049/" | |
208 ) | |
209 action = action.copy() | |
210 del action['created'] | |
1 | 211 del action['_id'] |
212 log.info("post to %s", hub) | |
383
8f5a16a55f64
various docker setups and build fixes
drewp@bigasterisk.com
parents:
340
diff
changeset
|
213 hub.post("visitorNet", payload=json.dumps(action)) |
0 | 214 |
215 def deltaSinceLastArrive(self, name): | |
216 results = list(self.mongo.find({'name' : name}).sort('created', | |
217 DESCENDING).limit(1)) | |
218 if not results: | |
219 return datetime.timedelta.max | |
220 now = datetime.datetime.now(tz.gettz('UTC')) | |
221 last = results[0]['created'].replace(tzinfo=tz.gettz('UTC')) | |
222 return now - last | |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
50
diff
changeset
|
223 |
340 | 224 def updateGraph(self, masterGraph): |
225 | |
226 g = ConjunctiveGraph() | |
227 ctx = DEV['wifi'] | |
228 | |
229 # someday i may also record specific AP and their strength, | |
230 # for positioning. But many users just want to know that the | |
231 # device is connected to some bigasterisk AP. | |
232 age = time.time() - self.lastPollTime | |
233 if age > 10: | |
234 raise ValueError("poll data is stale. age=%s" % age) | |
235 | |
236 for dev in self.lastAddrs: | |
237 if not dev.get('connected'): | |
238 continue | |
239 uri = URIRef("http://bigasterisk.com/mac/%s" % dev['mac'].lower()) | |
240 g.add((uri, ROOM['macAddress'], Literal(dev['mac'].lower()), ctx)) | |
241 | |
242 g.add((uri, ROOM['connected'], { | |
243 'wireless': URIRef("http://bigasterisk.com/wifiAccessPoints"), | |
244 '2.4G': URIRef("http://bigasterisk.com/wifiAccessPoints"), | |
245 '5G': URIRef("http://bigasterisk.com/wifiAccessPoints"), | |
246 'wired': URIRef("http://bigasterisk.com/houseOpenNet")}[dev['contype']], ctx)) | |
247 if 'clientHostname' in dev and dev['clientHostname']: | |
248 g.add((uri, ROOM['wifiNetworkName'], Literal(dev['clientHostname']), ctx)) | |
249 if 'name' in dev and dev['name']: | |
250 g.add((uri, ROOM['deviceName'], Literal(dev['name']), ctx)) | |
251 if 'signal' in dev: | |
252 g.add((uri, ROOM['signalStrength'], Literal(dev['signal']), ctx)) | |
253 if 'model' in dev: | |
254 g.add((uri, ROOM['networkModel'], Literal(dev['model']), ctx)) | |
255 try: | |
256 conn = whenConnected(mongo, dev['mac']) | |
257 except ValueError: | |
258 traceback.print_exc() | |
259 pass | |
260 else: | |
261 g.add((uri, ROOM['connectedAgo'], | |
262 Literal(connectedAgoString(conn)), ctx)) | |
263 g.add((uri, ROOM['connected'], Literal(conn), ctx)) | |
264 masterGraph.setToGraph(g) | |
265 | |
0 | 266 |
267 if __name__ == '__main__': | |
189 | 268 args = docopt.docopt(''' |
269 Usage: | |
270 tomatoWifi [options] | |
271 | |
272 Options: | |
273 -v, --verbose more logging | |
274 --port=<n> serve on port [default: 9070] | |
275 --poll=<freq> poll frequency [default: .2] | |
276 ''') | |
277 if args['--verbose']: | |
278 from twisted.python import log as twlog | |
279 twlog.startLogging(sys.stdout) | |
280 log.setLevel(10) | |
281 log.setLevel(logging.DEBUG) | |
0 | 282 |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
283 mongo = Connection('bang', 27017, tz_aware=True)['visitor']['visitor'] |
309 | 284 influx = InfluxDBClient('bang', 9060, 'root', 'root', 'main') |
0 | 285 |
340 | 286 masterGraph = PatchableGraph() |
0 | 287 wifi = Wifi() |
288 poller = Poller(wifi, mongo) | |
189 | 289 task.LoopingCall(poller.poll).start(1/float(args['--poll'])) |
0 | 290 |
189 | 291 reactor.listenTCP(int(args['--port']), |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
292 cyclone.web.Application( |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
293 [ |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
294 (r"/", Index), |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
295 (r'/json', Json), |
340 | 296 (r'/graph', CycloneGraphHandler, {'masterGraph': masterGraph}), |
297 (r'/graph/events', CycloneGraphEventsHandler, {'masterGraph': masterGraph}), | |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
298 (r'/table', Table), |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
299 #(r'/activity', Activity), |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
300 ], |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
301 wifi=wifi, |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
302 poller=poller, |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
303 mongo=mongo)) |
0 | 304 reactor.run() |