annotate service/arduinoNode/arduinoNode.py @ 1423:ba56263fe3b2

arduinonode to docker Ignore-this: 8f689c7491819bc47200018b517fd7de darcs-hash:e3602fc781c7b66e98ca950d5782ecc41e506bad
author drewp <drewp@bigasterisk.com>
date Wed, 07 Aug 2019 20:23:04 -0700
parents 672a3d830e7f
children 686079900c20
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
1 from __future__ import division
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
2 import glob, sys, logging, subprocess, socket, hashlib, time, tempfile, pkg_resources
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
3 import shutil, json
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
4 import serial
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
5 import cyclone.web
1056
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1048
diff changeset
6 from cyclone.httpclient import fetch
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
7 from rdflib import Graph, Namespace, URIRef, Literal, RDF, ConjunctiveGraph
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
8 from rdflib.parser import StringInputSource
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
9 from twisted.internet import reactor, task
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
10 from twisted.internet.defer import inlineCallbacks
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
11 from twisted.internet.threads import deferToThread
981
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
12 from docopt import docopt
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
13 import etcd3
1259
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
14 from greplin import scales
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
15 from greplin.scales.cyclonehandler import StatsHandler
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
16
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
17 import devices
1034
43a2170bbdb8 refactor to write_arduino_node
drewp <drewp@bigasterisk.com>
parents: 1027
diff changeset
18 import write_arduino_code
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
19 import dotrender
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
20 import rdflib_patch
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
21 rdflib_patch.fixQnameOfUriWithTrailingSlash()
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
22
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
23 logging.basicConfig(level=logging.DEBUG)
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
24
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
25 from loggingserial import LoggingSerial
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
26
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
27 from patchablegraph import PatchableGraph, CycloneGraphHandler, CycloneGraphEventsHandler
1136
1e43ec4a5f23 build and import updates for rdfdb, etc
drewp <drewp@bigasterisk.com>
parents: 1110
diff changeset
28 from export_to_influxdb import InfluxExporter
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
29
1136
1e43ec4a5f23 build and import updates for rdfdb, etc
drewp <drewp@bigasterisk.com>
parents: 1110
diff changeset
30 from rdfdb.patch import Patch
1e43ec4a5f23 build and import updates for rdfdb, etc
drewp <drewp@bigasterisk.com>
parents: 1110
diff changeset
31 from rdfdb.rdflibpatch import inContext
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
32
1018
651e5c5b1f3d write some values to carbon/graphite upon polling
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
33
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
34 log = logging.getLogger()
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
35 logging.getLogger('serial').setLevel(logging.WARN)
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
36
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
37 ROOM = Namespace('http://projects.bigasterisk.com/room/')
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
38 HOST = Namespace('http://bigasterisk.com/ruler/host/')
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
39
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
40 ACTION_BASE = 10 # higher than any of the fixed command numbers
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
41
1038
ffe6a00c6cef server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp <drewp@bigasterisk.com>
parents: 1035
diff changeset
42 hostname = socket.gethostname()
ffe6a00c6cef server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp <drewp@bigasterisk.com>
parents: 1035
diff changeset
43 CTX = ROOM['arduinosOn%s' % hostname]
1259
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
44
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
45 STATS = scales.collection('/root',
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
46 )
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
47
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
48
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
49 etcd = etcd3.client(host='bang6', port=9022)
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
50
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
51 class Config(object):
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
52 def __init__(self, masterGraph, slowMode=False):
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
53 self.masterGraph = masterGraph
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
54 self.slowMode = slowMode
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
55 self.configGraph = ConjunctiveGraph()
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
56
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
57 self.etcPrefix = 'arduino/'
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
58
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
59 self.boards = []
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
60 self.reread()
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
61
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
62 deferToThread(self.watchEtcd)
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
63
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
64 def watchEtcd(self):
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
65 events, cancel = etcd.watch_prefix(self.etcPrefix)
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
66 reactor.addSystemEventTrigger('before', 'shutdown', cancel)
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
67 for ev in events:
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
68 log.info('%s changed', ev.key)
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
69 reactor.callFromThread(self.configChanged)
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
70
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
71 def configChanged(self):
1148
8b4eda2cf0bd fix pushconfig
drewp <drewp@bigasterisk.com>
parents: 1140
diff changeset
72 self.cancelRead()
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
73 self.rereadLater = reactor.callLater(.1, self.reread)
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
74
1148
8b4eda2cf0bd fix pushconfig
drewp <drewp@bigasterisk.com>
parents: 1140
diff changeset
75 def cancelRead(self):
8b4eda2cf0bd fix pushconfig
drewp <drewp@bigasterisk.com>
parents: 1140
diff changeset
76 if getattr(self, 'rereadLater', None):
8b4eda2cf0bd fix pushconfig
drewp <drewp@bigasterisk.com>
parents: 1140
diff changeset
77 self.rereadLater.cancel()
8b4eda2cf0bd fix pushconfig
drewp <drewp@bigasterisk.com>
parents: 1140
diff changeset
78 self.rereadLater = None
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
79
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
80 def reread(self):
1148
8b4eda2cf0bd fix pushconfig
drewp <drewp@bigasterisk.com>
parents: 1140
diff changeset
81 self.cancelRead()
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
82 log.info('read config')
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
83 self.configGraph = ConjunctiveGraph()
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
84 for v, md in etcd.get_prefix(self.etcPrefix):
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
85 log.info(' read file %r', md.key)
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
86 self.configGraph.parse(StringInputSource(v), format='n3')
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
87 self.configGraph.bind('', ROOM) # not working
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
88 self.configGraph.bind('rdf', RDF)
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
89 # config graph is too noisy; maybe make it a separate resource
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
90 #masterGraph.patch(Patch(addGraph=self.configGraph))
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
91 self.setupBoards()
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
92
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
93 def serialDevices(self):
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
94 return dict([(row.dev, row.board) for row in self.configGraph.query(
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
95 """SELECT ?board ?dev WHERE {
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
96 ?board :device ?dev;
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
97 a :ArduinoBoard .
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
98 }""", initNs={'': ROOM})])
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
99
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
100 def setupBoards(self):
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
101 current = currentSerialDevices()
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
102
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
103 self.boards = []
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
104 for dev, board in self.serialDevices().items():
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
105 if str(dev) not in current:
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
106 continue
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
107 log.info("we have board %s connected at %s" % (board, dev))
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
108 b = Board(dev, self.configGraph, self.masterGraph, board)
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
109 self.boards.append(b)
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
110
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
111 for b in self.boards:
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
112 b.deployToArduino()
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
113
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
114 log.info('open boards')
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
115 for b in self.boards:
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
116 b.startPolling(period=.1 if not self.slowMode else 10)
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
117
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
118
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
119 class Board(object):
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
120 """an arduino connected to this computer"""
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
121 baudrate = 115200
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
122 def __init__(self, dev, configGraph, masterGraph, uri):
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
123 """
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
124 each connected thing has some pins.
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
125 """
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
126 self.uri = uri
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
127 self.configGraph = configGraph
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
128 self.masterGraph = masterGraph
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
129 self.dev = dev
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
130
1259
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
131 self.masterGraph.setToGraph(self.staticStmts())
1038
ffe6a00c6cef server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp <drewp@bigasterisk.com>
parents: 1035
diff changeset
132
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
133 # The order of this list needs to be consistent between the
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
134 # deployToArduino call and the poll call.
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
135 self._devs = devices.makeDevices(configGraph, self.uri)
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
136 self._devCommandNum = dict((dev.uri, ACTION_BASE + devIndex)
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
137 for devIndex, dev in enumerate(self._devs))
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
138 self._polledDevs = [d for d in self._devs if d.generatePollCode()]
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
139
990
11fff6301027 support for device code in the idle loop
drewp <drewp@bigasterisk.com>
parents: 981
diff changeset
140 self._statementsFromInputs = {} # input device uri: latest statements
1048
f3c7f617c335 piNode poll switches much faster. mirror the logic in arduinoNode though vari-rate poll is not supported yet
drewp <drewp@bigasterisk.com>
parents: 1038
diff changeset
141 self._lastPollTime = {} # input device uri: time()
1098
b5906f6fce3f save data to influxdb, not graphite
drewp <drewp@bigasterisk.com>
parents: 1061
diff changeset
142 self._influx = InfluxExporter(self.configGraph)
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
143 self.open()
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
144 for d in self._devs:
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
145 self.syncMasterGraphToHostStatements(d)
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
146
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
147 def description(self):
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
148 """for web page"""
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
149 return {
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
150 'uri': self.uri,
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
151 'dev': self.dev,
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
152 'baudrate': self.baudrate,
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
153 'devices': [d.description() for d in self._devs],
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
154 }
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
155
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
156 def open(self):
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
157 self.ser = LoggingSerial(port=self.dev, baudrate=self.baudrate,
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
158 timeout=2)
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
159
1061
ef635e9b9dce polling timing and error catching
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
160 def startPolling(self, period=.5):
ef635e9b9dce polling timing and error catching
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
161 task.LoopingCall(self._poll).start(period)
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
162
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
163 def _poll(self):
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
164 """
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
165 even boards with no inputs need some polling to see if they're
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
166 still ok
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
167 """
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
168 try:
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
169 self._pollWork()
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
170 except serial.SerialException:
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
171 reactor.crash()
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
172 raise
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
173 except Exception as e:
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
174 import traceback; traceback.print_exc()
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
175 log.warn("poll: %r" % e)
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
176
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
177 def _pollWork(self):
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
178 t1 = time.time()
1048
f3c7f617c335 piNode poll switches much faster. mirror the logic in arduinoNode though vari-rate poll is not supported yet
drewp <drewp@bigasterisk.com>
parents: 1038
diff changeset
179 self.ser.write("\x60\x00") # "poll everything"
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
180 for i in self._polledDevs:
1061
ef635e9b9dce polling timing and error catching
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
181 try:
ef635e9b9dce polling timing and error catching
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
182 now = time.time()
ef635e9b9dce polling timing and error catching
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
183 new = i.readFromPoll(self.ser.read)
ef635e9b9dce polling timing and error catching
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
184 if isinstance(new, dict): # new style
ef635e9b9dce polling timing and error catching
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
185 oneshot = new['oneshot']
ef635e9b9dce polling timing and error catching
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
186 new = new['latest']
ef635e9b9dce polling timing and error catching
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
187 else:
ef635e9b9dce polling timing and error catching
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
188 oneshot = None
1259
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
189
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
190 self._updateMasterWithNewPollStatements(i.uri, new)
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
191
1061
ef635e9b9dce polling timing and error catching
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
192 if oneshot:
ef635e9b9dce polling timing and error catching
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
193 self._sendOneshot(oneshot)
ef635e9b9dce polling timing and error catching
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
194 self._lastPollTime[i.uri] = now
ef635e9b9dce polling timing and error catching
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
195 except:
ef635e9b9dce polling timing and error catching
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
196 log.warn('while polling %r:', i.uri)
ef635e9b9dce polling timing and error catching
drewp <drewp@bigasterisk.com>
parents: 1056
diff changeset
197 raise
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
198 #plus statements about succeeding or erroring on the last poll
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
199 byte = self.ser.read(1)
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
200 if byte != 'x':
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
201 raise ValueError("after poll, got %x instead of 'x'" % byte)
1140
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
202 for i in self._devs:
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
203 if i.wantIdleOutput():
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
204 self.ser.write("\x60" + chr(self._devCommandNum[i.uri]))
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
205 i.outputIdle(self.ser.write)
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
206 if self.ser.read(1) != 'k':
f349fe25789c rgb strip animation support in arduinoNode
drewp <drewp@bigasterisk.com>
parents: 1139
diff changeset
207 raise ValueError('no ack after outputIdle')
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
208 elapsed = time.time() - t1
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
209 if elapsed > 1.0:
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
210 log.warn('poll took %.1f seconds' % elapsed)
1098
b5906f6fce3f save data to influxdb, not graphite
drewp <drewp@bigasterisk.com>
parents: 1061
diff changeset
211
1110
6ee834a6f970 influx output for arduino, update web lib path
drewp <drewp@bigasterisk.com>
parents: 1098
diff changeset
212 stmts = set()
6ee834a6f970 influx output for arduino, update web lib path
drewp <drewp@bigasterisk.com>
parents: 1098
diff changeset
213 for v in self._statementsFromInputs.values():
6ee834a6f970 influx output for arduino, update web lib path
drewp <drewp@bigasterisk.com>
parents: 1098
diff changeset
214 stmts.update(v)
6ee834a6f970 influx output for arduino, update web lib path
drewp <drewp@bigasterisk.com>
parents: 1098
diff changeset
215 self._influx.exportToInflux(stmts)
1018
651e5c5b1f3d write some values to carbon/graphite upon polling
drewp <drewp@bigasterisk.com>
parents: 997
diff changeset
216
1259
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
217 def _updateMasterWithNewPollStatements(self, dev, new):
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
218 prev = self._statementsFromInputs.get(dev, set())
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
219
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
220 # it's important that quads from different devices
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
221 # don't clash, since that can lead to inconsistent
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
222 # patches (e.g.
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
223 # dev1 changes value from 1 to 2;
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
224 # dev2 changes value from 2 to 3;
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
225 # dev1 changes from 2 to 4 but this patch will
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
226 # fail since the '2' statement is gone)
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
227 self.masterGraph.patch(Patch.fromDiff(inContext(prev, dev),
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
228 inContext(new, dev)))
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
229 self._statementsFromInputs[dev] = new
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
230
1056
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1048
diff changeset
231 def _sendOneshot(self, oneshot):
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1048
diff changeset
232 body = (' '.join('%s %s %s .' % (s.n3(), p.n3(), o.n3())
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1048
diff changeset
233 for s,p,o in oneshot)).encode('utf8')
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1048
diff changeset
234 fetch(method='POST',
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
235 url='http://bang6:9071/oneShot',
1056
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1048
diff changeset
236 headers={'Content-Type': ['text/n3']}, postdata=body,
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1048
diff changeset
237 timeout=5)
d2007482aec5 start sending oneshot events from some devices
drewp <drewp@bigasterisk.com>
parents: 1048
diff changeset
238
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
239 def outputStatements(self, stmts):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
240 unused = set(stmts)
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
241 for dev in self._devs:
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
242 stmtsForDev = []
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
243 for pat in dev.outputPatterns():
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
244 if [term is None for term in pat] != [False, False, True]:
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
245 raise NotImplementedError
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
246 for stmt in stmts:
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
247 if stmt[:2] == pat[:2]:
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
248 stmtsForDev.append(stmt)
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
249 unused.discard(stmt)
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
250 if stmtsForDev:
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
251 log.info("output goes to action handler for %s" % dev.uri)
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
252 self.ser.write("\x60" + chr(self._devCommandNum[dev.uri]))
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
253 dev.sendOutput(stmtsForDev, self.ser.write, self.ser.read)
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
254 if self.ser.read(1) != 'k':
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
255 raise ValueError(
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
256 "%s sendOutput/generateActionCode didn't use "
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
257 "matching output bytes" % dev.__class__)
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
258 # Dev *could* change hostStatements at any time, and
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
259 # we're not currently tracking that, but the usual is
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
260 # to change them in response to sendOutput so this
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
261 # should be good enough. The right answer is to give
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
262 # each dev the masterGraph for it to write to.
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
263 self.syncMasterGraphToHostStatements(dev)
1038
ffe6a00c6cef server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp <drewp@bigasterisk.com>
parents: 1035
diff changeset
264 log.info("output and masterGraph sync complete")
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
265 if unused:
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 1019
diff changeset
266 log.info("Board %s doesn't care about these statements:", self.uri)
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
267 for s in unused:
1259
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
268 log.info("%r", s)
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
269
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
270 def syncMasterGraphToHostStatements(self, dev):
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
271 hostStmtCtx = URIRef(dev.uri + '/host')
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
272 newQuads = inContext(dev.hostStatements(), hostStmtCtx)
1038
ffe6a00c6cef server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp <drewp@bigasterisk.com>
parents: 1035
diff changeset
273 p = self.masterGraph.patchSubgraph(hostStmtCtx, newQuads)
ffe6a00c6cef server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp <drewp@bigasterisk.com>
parents: 1035
diff changeset
274 log.debug("patch master with these host stmts %s", p)
ffe6a00c6cef server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp <drewp@bigasterisk.com>
parents: 1035
diff changeset
275
ffe6a00c6cef server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp <drewp@bigasterisk.com>
parents: 1035
diff changeset
276 def staticStmts(self):
ffe6a00c6cef server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp <drewp@bigasterisk.com>
parents: 1035
diff changeset
277 return [(HOST[hostname], ROOM['connectedTo'], self.uri, CTX)]
ffe6a00c6cef server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp <drewp@bigasterisk.com>
parents: 1035
diff changeset
278
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
279 def generateArduinoCode(self):
1038
ffe6a00c6cef server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp <drewp@bigasterisk.com>
parents: 1035
diff changeset
280 code = write_arduino_code.writeCode(self.baudrate, self._devs,
ffe6a00c6cef server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp <drewp@bigasterisk.com>
parents: 1035
diff changeset
281 self._devCommandNum)
1034
43a2170bbdb8 refactor to write_arduino_node
drewp <drewp@bigasterisk.com>
parents: 1027
diff changeset
282 code = write_arduino_code.indent(code)
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
283 cksum = hashlib.sha1(code).hexdigest()
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
284 code = code.replace('CODE_CHECKSUM', cksum)
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
285 return code, cksum
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
286
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
287 def _readBoardChecksum(self, length):
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
288 # this is likely right after reset, so it might take 2 seconds
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
289 for tries in range(6):
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
290 self.ser.write("\x60\x01")
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
291 try:
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
292 return self.ser.read(length)
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
293 except ValueError:
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
294 if tries == 5:
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
295 raise
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
296 time.sleep(.5)
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
297 raise ValueError
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
298
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
299 def _boardIsCurrent(self, currentChecksum):
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
300 try:
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
301 boardCksum = self._readBoardChecksum(len(currentChecksum))
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
302 if boardCksum == currentChecksum:
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
303 log.info("board has current code (%s)" % currentChecksum)
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
304 return True
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
305 else:
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
306 log.info("board responds with incorrect code version")
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
307 except Exception as e:
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
308 log.info("can't get code version from board: %r" % e)
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
309 return False
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
310
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
311 def deployToArduino(self):
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
312 code, cksum = self.generateArduinoCode()
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
313
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
314 if self._boardIsCurrent(cksum):
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
315 return
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
316
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
317 try:
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
318 if hasattr(self, 'ser'):
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
319 self.ser.close()
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
320 workDir = tempfile.mkdtemp(prefix='arduinoNode_board_deploy')
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
321 try:
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
322 self._arduinoMake(workDir, code)
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
323 finally:
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
324 shutil.rmtree(workDir)
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
325 finally:
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
326 self.open()
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
327
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
328 def _arduinoMake(self, workDir, code):
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
329 with open(workDir + '/makefile', 'w') as makefile:
1034
43a2170bbdb8 refactor to write_arduino_node
drewp <drewp@bigasterisk.com>
parents: 1027
diff changeset
330 makefile.write(write_arduino_code.writeMakefile(
43a2170bbdb8 refactor to write_arduino_node
drewp <drewp@bigasterisk.com>
parents: 1027
diff changeset
331 dev=self.dev,
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
332 tag=self.configGraph.value(self.uri, ROOM['boardTag']),
1034
43a2170bbdb8 refactor to write_arduino_node
drewp <drewp@bigasterisk.com>
parents: 1027
diff changeset
333 allLibs=sum((d.generateArduinoLibs() for d in self._devs), [])))
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
334
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
335 with open(workDir + '/main.ino', 'w') as main:
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
336 main.write(code)
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
337
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
338 subprocess.check_call(['make', 'upload'], cwd=workDir)
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
339
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
340
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
341 def currentGraph(self):
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
342 g = Graph()
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
343
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
344
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
345 for dev in self._devs:
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
346 for stmt in dev.hostStatements():
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
347 g.add(stmt)
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
348 return g
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
349
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
350 class Dot(cyclone.web.RequestHandler):
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
351 def get(self):
971
fbe72d44f15a only recompile if the C code is new. redo Device class api. single temperature sensor is working
drewp <drewp@bigasterisk.com>
parents: 969
diff changeset
352 configGraph = self.settings.config.graph
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
353 dot = dotrender.render(configGraph, self.settings.config.boards)
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
354 self.write(dot)
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
355
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
356 class ArduinoCode(cyclone.web.RequestHandler):
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
357 def get(self):
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
358 board = [b for b in self.settings.config.boards if
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
359 b.uri == URIRef(self.get_argument('board'))][0]
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 1019
diff changeset
360 self.set_header('Content-Type', 'text/plain')
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
361 code, cksum = board.generateArduinoCode()
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
362 self.write(code)
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
363
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
364 def rdfGraphBody(body, headers):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
365 g = Graph()
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
366 g.parse(StringInputSource(body), format='nt')
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
367 return g
981
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
368
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
369 class OutputPage(cyclone.web.RequestHandler):
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
370 def post(self):
981
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
371 # for old ui; use PUT instead
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
372 stmts = list(rdfGraphBody(self.request.body, self.request.headers))
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
373 for b in self.settings.config.boards:
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
374 b.outputStatements(stmts)
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
375
981
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
376 def put(self):
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
377 subj = URIRef(self.get_argument('s'))
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
378 pred = URIRef(self.get_argument('p'))
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
379
981
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
380 turtleLiteral = self.request.body
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
381 try:
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
382 obj = Literal(float(turtleLiteral))
990
11fff6301027 support for device code in the idle loop
drewp <drewp@bigasterisk.com>
parents: 981
diff changeset
383 except ValueError:
981
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
384 obj = Literal(turtleLiteral)
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
385
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
386 stmt = (subj, pred, obj)
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
387 for b in self.settings.config.boards:
981
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
388 b.outputStatements([stmt])
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
389
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
390
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
391 class Boards(cyclone.web.RequestHandler):
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
392 def get(self):
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
393 self.set_header('Content-type', 'application/json')
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
394 self.write(json.dumps({
1038
ffe6a00c6cef server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp <drewp@bigasterisk.com>
parents: 1035
diff changeset
395 'host': hostname,
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
396 'boards': [b.description() for b in self.settings.config.boards]
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
397 }, indent=2))
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
398
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
399 def currentSerialDevices():
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
400 log.info('find connected boards')
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
401 return glob.glob('/dev/serial/by-id/*')
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
402
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
403 def main():
981
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
404 arg = docopt("""
1023
3e6fac8569cd multi-boards on one service, new devices, devices return their current
drewp <drewp@bigasterisk.com>
parents: 1019
diff changeset
405 Usage: arduinoNode.py [options]
981
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
406
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
407 -v Verbose
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
408 -s serial logging
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
409 -l slow polling
981
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
410 """)
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
411 log.setLevel(logging.WARN)
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
412 if arg['-v']:
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
413 from twisted.python import log as twlog
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
414 twlog.startLogging(sys.stdout)
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
415
d9bbbd8d86f6 arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
drewp <drewp@bigasterisk.com>
parents: 975
diff changeset
416 log.setLevel(logging.DEBUG)
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
417 if arg['-s']:
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
418 logging.getLogger('serial').setLevel(logging.INFO)
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
419
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
420 masterGraph = PatchableGraph()
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
421 config = Config(masterGraph, slowMode=arg['-l'])
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
422 static = pkg_resources.resource_filename('homeauto_anynode', 'static/')
995
f72068e9d9d8 serve ipv6 and use localhost's ipv6 name for getting updates
drewp <drewp@bigasterisk.com>
parents: 990
diff changeset
423
1038
ffe6a00c6cef server/browser graph sync. cut dependency on the WS version. merge some changes between arduino/pi code.
drewp <drewp@bigasterisk.com>
parents: 1035
diff changeset
424 reactor.listenTCP(9059, cyclone.web.Application([
1423
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
425 (r"/(|output-widgets.html)", cyclone.web.StaticFileHandler, {
ba56263fe3b2 arduinonode to docker
drewp <drewp@bigasterisk.com>
parents: 1259
diff changeset
426 "path": static, "default_filename": "index.html"}),
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
427 (r'/static/(.*)', cyclone.web.StaticFileHandler, {"path": "static"}),
1259
672a3d830e7f arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents: 1148
diff changeset
428 (r'/stats/(.*)', StatsHandler, {'serverName': 'arduinoNode'}),
975
f3023410d875 polymer board debug page with working output widgets
drewp <drewp@bigasterisk.com>
parents: 974
diff changeset
429 (r'/boards', Boards),
1035
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
430 (r"/graph", CycloneGraphHandler, {'masterGraph': masterGraph}),
f01d9892ed79 update arduinoNode to support streamed graph output
drewp <drewp@bigasterisk.com>
parents: 1034
diff changeset
431 (r"/graph/events", CycloneGraphEventsHandler, {'masterGraph': masterGraph}),
974
f707210c13bd new /output to post statements which devices can handle. led and lcd output working
drewp <drewp@bigasterisk.com>
parents: 971
diff changeset
432 (r'/output', OutputPage),
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
433 (r'/arduinoCode', ArduinoCode),
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
434 (r'/dot', Dot),
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1136
diff changeset
435 ], config=config), interface='::')
969
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
436 reactor.run()
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
437
70a5392b24d3 start arduinonode
drewp <drewp@bigasterisk.com>
parents:
diff changeset
438 main()