Further simplify gateway code. Next step: A settings file

This commit is contained in:
Starbeamrainbowlabs 2018-11-15 19:50:38 +00:00
parent 2266532db4
commit 26e90adbf8
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -17,21 +17,15 @@ GATEWAY_HOST = "router.eu.thethings.network"
GATEWAY_PORT = 1700 GATEWAY_PORT = 1700
class LoRaPacketsDB(object): def log_packet(self, board, packet):
def __init__(self): print("[{}] [receive] freq: {}, crc: {}, signal-noise-ratio: {}, signal strength: {} (packet: {})".format(
pass payload['datetime'].isoformat(),
board.frequency,
payload.get('crc'),
def log_pkg(self, board, packet): payload.get('pkt_snr'),
print("[{}] [receive] freq: {}, crc: {}, signal-noise-ratio: {}, signal strength: {} (packet: {})".format( payload.get('rssi'),
payload['datetime'].isoformat(), payload.get('pkt_rssi'),
board.frequency, ))
payload.get('crc'),
payload.get('pkt_snr'),
payload.get('rssi'),
payload.get('pkt_rssi'),
))
def construct_semtec_udp(board, payload): def construct_semtec_udp(board, payload):
@ -69,8 +63,6 @@ def construct_semtec_udp(board, payload):
if __name__ == "__main__": if __name__ == "__main__":
# sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP # sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
db = LoRaPacketsDB()
with LoraBoardDraguino(433300000, 7) as board: with LoraBoardDraguino(433300000, 7) as board:
board.set_mode_rx() board.set_mode_rx()
print("Listening at SF{} on {} MHz".format( print("Listening at SF{} on {} MHz".format(
@ -79,18 +71,20 @@ if __name__ == "__main__":
)) ))
while True: while True:
if GPIO.input(board._pin_dio0) == 1: if GPIO.input(board._pin_dio0) != 1:
payload = board.receive_package() continue
# semtec_udp = construct_semtec_udp(board, payload) payload = board.receive_package()
# sock.sendto(semtec_udp, (GATEWAY_HOST, GATEWAY_PORT))
# logging.info(semtec_udp)
# logging.info("Received: {}".format(payload)) # semtec_udp = construct_semtec_udp(board, payload)
print("Received at {}: {} = {}".format( # sock.sendto(semtec_udp, (GATEWAY_HOST, GATEWAY_PORT))
payload['datetime'].isoformat(), # logging.info(semtec_udp)
payload['payload'].hex(),
payload['payload'][4:]
))
db.log_pkg(board, payload) # logging.info("Received: {}".format(payload))
print("Received at {}: {} = {}".format(
payload['datetime'].isoformat(),
payload['payload'].hex(),
payload['payload'][4:]
))
log_packet(board, payload)