Send data to node-red
This commit is contained in:
parent
3fcd397fcb
commit
9516ca3617
12
notify.py
12
notify.py
|
@ -1,3 +1,8 @@
|
||||||
|
# Send lora packet to node-red when being triggered by postgresql
|
||||||
|
# Nico Schottelius <nico.schottelius -at- ungleich.ch>
|
||||||
|
# 2016-11-02
|
||||||
|
# GPLv3+
|
||||||
|
|
||||||
import select
|
import select
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import psycopg2.extensions
|
import psycopg2.extensions
|
||||||
|
@ -5,11 +10,11 @@ import websocket
|
||||||
|
|
||||||
channels = [ "loriot", "swisscom", "ttn" ]
|
channels = [ "loriot", "swisscom", "ttn" ]
|
||||||
|
|
||||||
def to_nodered(self, data):
|
def to_nodered(self, provider, data):
|
||||||
dev = self.devEUI(data)
|
dev = self.devEUI(data)
|
||||||
text = self.payload(data)
|
text = self.payload(data)
|
||||||
|
|
||||||
ws = websocket.create_connection("ws://localhost:1880/")
|
ws = websocket.create_connection("ws://localhost:1880/{}".format(provider))
|
||||||
ws.send("%s" % data)
|
ws.send("%s" % data)
|
||||||
ws.close()
|
ws.close()
|
||||||
|
|
||||||
|
@ -21,6 +26,7 @@ def wait_for_pkg(conns):
|
||||||
while conn.notifies:
|
while conn.notifies:
|
||||||
notify = conn.notifies.pop(0)
|
notify = conn.notifies.pop(0)
|
||||||
print("Got NOTIFY: {} {} {}".format(notify.pid, notify.channel, notify.payload))
|
print("Got NOTIFY: {} {} {}".format(notify.pid, notify.channel, notify.payload))
|
||||||
|
to_nodered(notify.channel, notify.payload)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
conns = []
|
conns = []
|
||||||
|
@ -36,4 +42,4 @@ if __name__ == '__main__':
|
||||||
print("Waiting for notifications on channel {}".format(channel))
|
print("Waiting for notifications on channel {}".format(channel))
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
wait_for_pkg(conns):
|
wait_for_pkg(conns)
|
||||||
|
|
Loading…
Reference in New Issue