2016-11-02 15:35:10 +00:00
|
|
|
import select
|
|
|
|
import psycopg2
|
|
|
|
import psycopg2.extensions
|
|
|
|
|
2016-11-02 15:44:33 +00:00
|
|
|
channel = "lora"
|
|
|
|
|
2016-11-02 15:35:10 +00:00
|
|
|
conn = psycopg2.connect("dbname=lorawan")
|
|
|
|
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
|
|
|
|
|
|
|
|
curs = conn.cursor()
|
2016-11-02 15:44:33 +00:00
|
|
|
curs.execute("LISTEN {};".format(channel))
|
2016-11-02 15:35:10 +00:00
|
|
|
|
2016-11-02 15:44:33 +00:00
|
|
|
print("Waiting for notifications on channel {}".format(channel))
|
2016-11-02 15:35:10 +00:00
|
|
|
while True:
|
|
|
|
if select.select([conn],[],[]) == ([],[],[]):
|
|
|
|
print("Timeout")
|
|
|
|
else:
|
|
|
|
conn.poll()
|
|
|
|
while conn.notifies:
|
|
|
|
notify = conn.notifies.pop(0)
|
|
|
|
print("Got NOTIFY: {} {} {}".format(notify.pid, notify.channel, notify.payload))
|