This repository has been archived on 2019-08-15. You can view files and clone it, but cannot push or open issues or pull requests.
TheThingsNetworkGateway/Gateway-Python/print_db.py

37 lines
1.1 KiB
Python
Raw Normal View History

2018-11-15 18:21:45 +00:00
#!/usr/bin/env python3
from decode_msg import decode_msg, pretty_print_header, pretty_print_payload, MSG_TYPES
import sqlite3
if __name__ == "__main__":
conn = sqlite3.connect('gateway_packages.db')
c = conn.cursor()
c.execute('SELECT * FROM `PACKETS`')
for line in c.fetchall():
try:
line = list(line)
msg = {'id': line[0],
'datetime': line[1],
'data': bytes(line[2]).hex(),
'frequency': line[3],
'crc': line[4],
'pkt_snr': line[5],
'pkt_rssi': line[6],
'rssi': line[7]}
decoded = decode_msg(msg['data'])
color = '\033[92m' if msg['crc'] else '\033[91m'
print(color, '### {id:04d} ({datetime}): {header}\033[0m (PKT_SNR={pkt_snr}, PKT_RSSI={pkt_rssi}, RSSI={rssi}) '.format(**msg, header=pretty_print_header(decoded)))
# weather report
if decoded['type'] == 0x10:
print(pretty_print_payload(decoded))
except:
print("ERROR in: ", line)