RaspyRFM/apps/mqttdash.py
Stefan Seegel d7bdeb11be added PDM32 rc protocol
added mqtt dashbutton app
2020-02-11 20:05:33 +01:00

37 lines
856 B
Python
Executable file

#!/usr/bin/env python2.7
import rcprotocols
import time
import paho.mqtt.client as mqtt
mqttClient = mqtt.Client()
mqttClient.connect("localhost", 1883, 60)
mqttClient.loop_start()
rx = rcprotocols.PulseReceiver(1)
lastEvents = {}
def publish(proto, code):
print("Publish: " + str(proto) + " / " + str(code))
mqttClient.publish("home/rcbuttons/" + proto, code)
while True:
time.sleep(0.1)
evts = rx.getEvents()
if evts:
for e in evts:
if e["protocol"] in lastEvents:
le = lastEvents[e["protocol"]]
if e["code"] != le["code"]:
publish(e["protocol"], e["code"])
le["code"] = e["code"]
elif (time.time() - le["ts"] > 1):
publish(e["protocol"], e["code"])
le["ts"] = time.time()
else:
lastEvents[e["protocol"]] = {
"ts": time.time(),
"code": e["code"]
}
publish(e["protocol"], e["code"])