changeset 1378:fecbac537f63

faster keepalive from esp chip. report aliveness into the graph. more programming tasks in tasks.py Ignore-this: f8fca86291d3082cb309524fbd5baf1c darcs-hash:9ef8e6bfe77887aa8450596fd3f662acd969d8ef
author drewp <drewp@bigasterisk.com>
date Mon, 06 May 2019 21:06:08 -0700
parents 12d6ce6f6bc1
children baf1acaa9ac9
files service/frontDoorLock/door.yaml service/frontDoorLock/front_door_lock.py service/frontDoorLock/tasks.py
diffstat 3 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/service/frontDoorLock/door.yaml	Mon May 06 00:19:08 2019 -0700
+++ b/service/frontDoorLock/door.yaml	Mon May 06 21:06:08 2019 -0700
@@ -18,9 +18,10 @@
 mqtt:
   broker: '10.2.0.1'
   port: 10010
+  keepalive: 5
   username: ''
   password: ''
-
+  
 logger:
   baud_rate: 115200
   level: DEBUG
--- a/service/frontDoorLock/front_door_lock.py	Mon May 06 00:19:08 2019 -0700
+++ b/service/frontDoorLock/front_door_lock.py	Mon May 06 21:06:08 2019 -0700
@@ -171,6 +171,14 @@
                                 stateFromMqtt(payload))
 
     mqtt.subscribe(espName + b"/switch/strike/state").subscribe(on_next=toGraph)
+
+    def setEspState(payload):
+        log.info('esp state change %r', payload)
+        masterGraph.patchObject(ctx, ROOM['frontDoorLock'], ROOM['espMqttConnection'],
+                                ROOM['mqtt' + payload.decode('ascii').capitalize()])
+    
+    mqtt.subscribe(espName + b"/status").subscribe(on_next=setEspState)
+    
     port = 10011
     reactor.listenTCP(port, cyclone.web.Application(
         [
--- a/service/frontDoorLock/tasks.py	Mon May 06 00:19:08 2019 -0700
+++ b/service/frontDoorLock/tasks.py	Mon May 06 21:06:08 2019 -0700
@@ -36,3 +36,16 @@
 def monitor_usb(ctx):
     tag = 'esphome/esphome'
     ctx.run(f"docker run --rm -v `pwd`:/config --device=/dev/ttyUSB0 -it {tag} door.yaml logs", pty=True)
+
+@task
+def tail_mqtt(ctx):
+    ctx.run(f'mosquitto_sub -h bang -p 10010 -d -v -t \#')
+
+@task
+def mqtt_force_open(ctx):
+    ctx.run(f'mosquitto_pub -h bang -p 10010 -t frontdoorlock/switch/strike/command -m ON')
+
+@task
+def mqtt_force_lock(ctx):
+    ctx.run(f'mosquitto_pub -h bang -p 10010 -t frontdoorlock/switch/strike/command -m OFF')
+