changeset 456:12f9f1838fb5

arduinoNode: build updates, stats support, etc Ignore-this: 39386eb7644e3cf522e0f72a874eadba
author drewp@bigasterisk.com
date Sat, 20 Apr 2019 23:28:29 -0700
parents 7e09c0d0a86e
children d96621e2fc08
files service/arduinoNode/Dockerfile service/arduinoNode/arduinoNode.py service/arduinoNode/config/slash.n3 service/arduinoNode/makefile service/arduinoNode/pushConfig.py service/arduinoNode/requirements.txt
diffstat 6 files changed, 42 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/service/arduinoNode/Dockerfile	Fri Apr 19 14:24:09 2019 -0700
+++ b/service/arduinoNode/Dockerfile	Sat Apr 20 23:28:29 2019 -0700
@@ -4,10 +4,12 @@
 
 COPY requirements.txt ./
 RUN pip install -r requirements.txt
+RUN apt-get install -y arduino-mk indent
 
 COPY arduino-libraries/ ./arduino-libraries/
 COPY *.py ./
 COPY static/ ./static/
+COPY config/ ./config/
 
 ADD https://projects.bigasterisk.com/rdfdb/more.tgz ./
 RUN tar xvzf more.tgz
--- a/service/arduinoNode/arduinoNode.py	Fri Apr 19 14:24:09 2019 -0700
+++ b/service/arduinoNode/arduinoNode.py	Sat Apr 20 23:28:29 2019 -0700
@@ -11,6 +11,8 @@
 from twisted.internet.threads import deferToThread
 from docopt import docopt
 import etcd3
+from greplin import scales
+from greplin.scales.cyclonehandler import StatsHandler
 
 import devices
 import write_arduino_code
@@ -41,7 +43,12 @@
 
 hostname = socket.gethostname()
 CTX = ROOM['arduinosOn%s' % hostname]
-etcd = etcd3.client(host='bang6')
+
+STATS = scales.collection('/root',
+)
+
+
+etcd = etcd3.client(host='bang6', port=9022)
 
 class Config(object):
     def __init__(self, masterGraph, slowMode=False):
@@ -123,7 +130,7 @@
         self.masterGraph = masterGraph
         self.dev = dev
 
-        self.masterGraph.patch(Patch(addQuads=self.staticStmts()))
+        self.masterGraph.setToGraph(self.staticStmts())
 
         # The order of this list needs to be consistent between the
         # deployToArduino call and the poll call.
@@ -181,18 +188,9 @@
                     new = new['latest']
                 else:
                     oneshot = None
-                prev = self._statementsFromInputs.get(i.uri, [])
-                if new or prev:
-                    self._statementsFromInputs[i.uri] = new
-                    # it's important that quads from different devices
-                    # don't clash, since that can lead to inconsistent
-                    # patches (e.g.
-                    #   dev1 changes value from 1 to 2;
-                    #   dev2 changes value from 2 to 3;
-                    #   dev1 changes from 2 to 4 but this patch will
-                    #     fail since the '2' statement is gone)
-                    self.masterGraph.patch(Patch.fromDiff(inContext(prev, i.uri),
-                                                          inContext(new, i.uri)))
+
+                self._updateMasterWithNewPollStatements(i.uri, new)
+
                 if oneshot:
                     self._sendOneshot(oneshot)
                 self._lastPollTime[i.uri] = now
@@ -218,6 +216,20 @@
             stmts.update(v)
         self._influx.exportToInflux(stmts)
 
+    def _updateMasterWithNewPollStatements(self, dev, new):
+        prev = self._statementsFromInputs.get(dev, set())
+
+        # it's important that quads from different devices
+        # don't clash, since that can lead to inconsistent
+        # patches (e.g.
+        #   dev1 changes value from 1 to 2;
+        #   dev2 changes value from 2 to 3;
+        #   dev1 changes from 2 to 4 but this patch will
+        #     fail since the '2' statement is gone)
+        self.masterGraph.patch(Patch.fromDiff(inContext(prev, dev),
+                                              inContext(new, dev)))
+        self._statementsFromInputs[dev] = new
+              
     def _sendOneshot(self, oneshot):
         body = (' '.join('%s %s %s .' % (s.n3(), p.n3(), o.n3())
                          for s,p,o in oneshot)).encode('utf8')
@@ -255,7 +267,7 @@
         if unused:
             log.info("Board %s doesn't care about these statements:", self.uri)
             for s in unused:
-                log.warn("%r", s)
+                log.info("%r", s)
 
     def syncMasterGraphToHostStatements(self, dev):
         hostStmtCtx = URIRef(dev.uri + '/host')
@@ -414,6 +426,7 @@
         (r"/()", cyclone.web.StaticFileHandler, {
             "path": "static", "default_filename": "index.html"}),
         (r'/static/(.*)', cyclone.web.StaticFileHandler, {"path": "static"}),
+        (r'/stats/(.*)', StatsHandler, {'serverName': 'arduinoNode'}),
         (r'/boards', Boards),
         (r"/graph", CycloneGraphHandler, {'masterGraph': masterGraph}),
         (r"/graph/events", CycloneGraphEventsHandler, {'masterGraph': masterGraph}),
--- a/service/arduinoNode/config/slash.n3	Fri Apr 19 14:24:09 2019 -0700
+++ b/service/arduinoNode/config/slash.n3	Sat Apr 20 23:28:29 2019 -0700
@@ -34,29 +34,6 @@
 shopPin:d12 :pinNumber 12; :connectedTo shopShift:lightClock .
 shopPin:d13 :pinNumber 13; :connectedTo shopShift:briteClock .
 
-shopPin:a4 :pinNumber "a4"; :connectedTo shopPwm:sda .
-shopPin:a5 :pinNumber "a5"; :connectedTo shopPwm:scl .
-
-shopOw: a :OneWire;
-  :connectedTo shopOw:dev-28bf08d101000026 .
-shopOw:dev-28bf08d101000026 a :TemperatureSensor;
-  :position :workshop;
-  :influxMeasurement [
-    :measurement "temperatureF";
-    :predicate :temperatureF;
-    :tag [:key "host"; :value "slash"], [:key "location"; :value "workshop"]].
-
-shopPwm:roomLights a :PwmBoard;
-  :scl shopPwm:scl;
-  :sda shopPwm:sda;
-  :output
-    [:area shopPwm:sewingLight; :channel 0; :wattage 7],
-    [:area shopPwm:shopLight0;  :channel 1; :wattage 10],
-    [:area shopPwm:shopLight1;  :channel 2; :wattage 10],
-    [:area shopPwm:ariLight;    :channel 3; :wattage 10],
-    [:area shopPwm:shopLight2;  :channel 4; :wattage 10],
-    [:area shopPwm:shopLight3;  :channel 6; :wattage 8] .
-    
 # shiftbrite EI (arduino d12) still needs to be connected to +5
 
 #barcode red: +5V
--- a/service/arduinoNode/makefile	Fri Apr 19 14:24:09 2019 -0700
+++ b/service/arduinoNode/makefile	Sat Apr 20 23:28:29 2019 -0700
@@ -3,11 +3,17 @@
 	docker build --network=host -t bang6:5000/arduino_node .
 	docker push bang6:5000/arduino_node
 
-shell:
+shell: build_image
 	docker run -it --net=host -v `pwd`/config:/opt/config bang6:5000/arduino_node  /bin/bash
 
-local_run:
+local_run: build_image
 	docker run -it -p 9059:9059 --device=/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A900cepU-if00-port0 --net=host bang6:5000/arduino_node python ./arduinoNode.py -v
 
 push_config:
 	docker run -it --net=host -v `pwd`/config:/opt/config bang6:5000/arduino_node python pushConfig.py arduino/
+
+lightsout:
+	curl http://bang:9059/output\?s\=http://projects.bigasterisk.com/room/speakersStrips\&p\=http://projects.bigasterisk.com/room/x -XPUT -d 199
+
+redeploy: build_image
+	ctl restart arduinoNodeBang_9059
--- a/service/arduinoNode/pushConfig.py	Fri Apr 19 14:24:09 2019 -0700
+++ b/service/arduinoNode/pushConfig.py	Sat Apr 20 23:28:29 2019 -0700
@@ -4,7 +4,7 @@
 
 from twisted.python.filepath import FilePath
 
-etcd = etcd3.client(host='bang6')
+etcd = etcd3.client(host='bang6', port=9022)
 
 prefix, = sys.argv[1:]
 
@@ -12,6 +12,7 @@
     existing = set(md.key for v, md in etcd.get_prefix(prefix))
     written = set()
     root = FilePath('config')
+    print 'reading at %s' % root
     for f in root.walk():
         if f.isfile() and f.path.endswith('.n3'):
             n3 = f.getContent()
--- a/service/arduinoNode/requirements.txt	Fri Apr 19 14:24:09 2019 -0700
+++ b/service/arduinoNode/requirements.txt	Sat Apr 20 23:28:29 2019 -0700
@@ -10,6 +10,7 @@
 rdflib-jsonld==0.3
 influxdb==3.0.0
 imageio==2.2.0
-https://projects.bigasterisk.com/rdfdb/rdfdb-0.3.0.tar.gz
+https://projects.bigasterisk.com/rdfdb/rdfdb-0.8.0.tar.gz
 pyserial
 etcd3
+git+http://github.com/drewp/scales.git@448d59fb491b7631877528e7695a93553bfaaa93#egg=scales