changeset 1428:56e07d3f0930

frontdoor configs; move device class timing to greplin stats Ignore-this: f32495ae0d3b4c6f50fe1ba46c57abcd darcs-hash:c8b6f8460b858868837dc9c98f844528531fe98c
author drewp <drewp@bigasterisk.com>
date Thu, 08 Aug 2019 16:50:14 -0700
parents 6bd36e5e109f
children 262ad47a9743
files service/piNode/Dockerfile service/piNode/config/frontdoor.n3 service/piNode/devices.py service/piNode/piNode.py
diffstat 4 files changed, 47 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/service/piNode/Dockerfile	Thu Aug 08 16:48:40 2019 -0700
+++ b/service/piNode/Dockerfile	Thu Aug 08 16:50:14 2019 -0700
@@ -1,7 +1,7 @@
 FROM bang6:5000/base_pi
 
 # super slow build
-RUN pip install grpcio==1.18.0
+RUN pip install grpcio==1.22.0
 
 WORKDIR /opt
 
@@ -16,4 +16,6 @@
 COPY *.py ./
 COPY config/ ./config/
 
+EXPOSE 9059
+
 CMD [ "python", "./piNode.py" ]
--- a/service/piNode/config/frontdoor.n3	Thu Aug 08 16:48:40 2019 -0700
+++ b/service/piNode/config/frontdoor.n3	Thu Aug 08 16:50:14 2019 -0700
@@ -7,22 +7,37 @@
 
 @prefix pin: <http://bigasterisk.com/homeauto/piFrontdoor/pin/> .
 
+# beware of frontdoor vs frontDoor
+
+# 26 gry  cs
+# 18 grn  dc
+# 19 blu  sda oled
+# 23 vio  scl
+#  3 org  txd/sda rfid
+#  5 yel  rxd/sda
+
 ha:piFrontdoor a :PiBoard;
   :hostname "frontdoor";
   :onboardDevice ha:frontdoorPiTemp;
   :hasPin
     pin:GPIO4, # open
-    pin:GPIO5, # motion
-    pin:GPIO17, # OW temp
-    pin:GPIO18 .   # rgb
+    pin:GPIO5, # 
+    pin:GPIO17, #
+    pin:GPIO22, #
+    pin:GPIO27, #
+    pin:GPIO18 .   #
 
 ha:frontdoorPiTemp a :OnboardTemperature;
   :influxMeasurement "temperatureF";
   :influxTag [:key "location"; :value "frontdoorPi"] .
 
-pin:GPIO4 :gpioNumber 4; :connectedTo :frontdoorOpenSwitch .
-:frontdoorOpenSwitch a :Pushbutton; :style :inverted;
-:influxMeasurement [
+pin:GPIO22 :gpioNumber 22; :connectedTo :frontDoorScreenButton1 . :frontDoorScreenButton1 a :Pushbutton .
+pin:GPIO27 :gpioNumber 27; :connectedTo :frontDoorScreenButton2 . :frontDoorScreenButton2 a :Pushbutton .
+pin:GPIO17 :gpioNumber 17; :connectedTo :frontDoorScreenButton3 . :frontDoorScreenButton3 a :Pushbutton .
+
+pin:GPIO4 :gpioNumber 4; :connectedTo :frontDoorOpenSwitch .
+:frontDoorOpenSwitch a :Pushbutton; :style :inverted;
+c:influxMeasurement [
     :measurement "state";
     :predicate :buttonState;
     :tag [:key "host"; :value "frontdoor"],
@@ -30,8 +45,8 @@
       [:key "location"; :value "frontDoor"]];.
 
 
-pin:GPIO5 :gpioNumber 5; :connectedTo sensor:motionFrontdoorInside .
-sensor:motionFrontdoorInside a :MotionSensor;
+pin:GPIO5 :gpioNumber 5; :connectedTo sensor:motionFrontDoorInside .
+sensor:motionFrontDoorInside a :MotionSensor;
   :influxMeasurement [
     :measurement "presence";
     :predicate :sees;
@@ -43,12 +58,12 @@
 # 23 GPIO11 through 100R, and signal->220R->LED->gnd
 # 25 gnd
 
-pin:GPIO18 :gpioNumber 18; :connectedTo :frontdoorRgb .
-:frontdoorRgb a :RgbPixels;
+pin:GPIO18 :gpioNumber 18; :connectedTo :frontDoorRgb .
+:frontDoorRgb a :RgbPixels_disabled_pending_pi4_support;
   :colorOrder order:GRB;
-  :pixelGroup :frontdoorRgb .
+  :pixelGroup :frontDoorRgb .
 
-:frontdoorRgb
+:frontDoorRgb
   :startIndex 0;
   :endIndex 2;
   :src "rainbow.png";
--- a/service/piNode/devices.py	Thu Aug 08 16:48:40 2019 -0700
+++ b/service/piNode/devices.py	Thu Aug 08 16:50:14 2019 -0700
@@ -59,6 +59,11 @@
     def __init__(self, graph, uri, pi, pinNumber):
         self.graph, self.uri, self.pi = graph, uri, pi
         self.pinNumber = pinNumber
+        scales.init(self, self.__class__.__name__)
+        self.stats = scales.collection(self.__class__.__name__,
+                                       scales.PmfStat('poll'),
+                                       scales.PmfStat('output'),
+        )
         self.hostStateInit()
 
     def hostStateInit(self):
@@ -542,8 +547,8 @@
     def updateOutput(self):
         if 0:
             for _, _, sg in self.anim.groups.values():
-                print sg.uri, sg.current
-            print list(self.anim.currentColors())
+                print (sg.uri, sg.current)
+            print (list(self.anim.currentColors()))
             return
 
         with pixelStats.currentColors.time():
--- a/service/piNode/piNode.py	Thu Aug 08 16:48:40 2019 -0700
+++ b/service/piNode/piNode.py	Thu Aug 08 16:50:14 2019 -0700
@@ -43,6 +43,7 @@
 STATS = scales.collection('/root',
                           scales.PmfStat('configReread'),
                           scales.IntStat('pollException'),
+                          scales.PmfStat('pollAll'),
                           scales.PmfStat('boardPoll'),
                           scales.PmfStat('sendOneshot'),
                           scales.PmfStat('outputStatements'),
@@ -153,15 +154,14 @@
 
 
     @inlineCallbacks
-    def _pollOneDev(self, i, pollTime):
+    def _pollOneDev(self, i):
         now = time.time()
         if (hasattr(i, 'pollPeriod') and
             self._lastPollTime.get(i.uri, 0) + i.pollPeriod > now):
             return
-        #need something like:
-        #  with i.pollTiming.time():
-        new = yield maybeDeferred(i.poll)
-        pollTime[i.uri] = time.time() - now
+        with i.stats.poll.time():
+            new = yield maybeDeferred(i.poll)
+
         if isinstance(new, dict): # new style
             oneshot = new['oneshot']
             new = new['latest']
@@ -176,19 +176,10 @@
 
     @inlineCallbacks
     def _pollMaybeError(self):
-        pollTime = {} # uri: sec
-        start = time.time()
-        yield gatherResults([self._pollOneDev(i, pollTime)
-                             for i in self._devs], consumeErrors=True)
+        with STATS.pollAll.time():
+            yield gatherResults([self._pollOneDev(i)
+                                 for i in self._devs], consumeErrors=True)
 
-        if log.isEnabledFor(logging.DEBUG):
-            log.debug('poll times:')
-            for u, s in sorted(pollTime.items()):
-                log.debug("  %.4f ms %s", s * 1000, u)
-            log.debug('total poll time: %f ms done in %f ms elapsed',
-                      sum(pollTime.values()) * 1000,
-                      (time.time() - start) * 1000)
-            
         pollResults = map(set, self._statementsFromInputs.values())
         if pollResults:
             self._influx.exportToInflux(set.union(*pollResults))
@@ -236,7 +227,8 @@
                         unused.discard(stmt)
             if stmtsForDev:
                 log.info("output goes to action handler for %s" % dev.uri)
-                dev.sendOutput(stmtsForDev)
+                with dev.stats.output.time():
+                    dev.sendOutput(stmtsForDev)
 
                 # Dev *could* change hostStatements at any time, and
                 # we're not currently tracking that, but the usual is