Further simplify gateway code. Next step: A settings file
This commit is contained in:
parent
2266532db4
commit
26e90adbf8
1 changed files with 28 additions and 34 deletions
|
@ -17,21 +17,15 @@ GATEWAY_HOST = "router.eu.thethings.network"
|
|||
GATEWAY_PORT = 1700
|
||||
|
||||
|
||||
class LoRaPacketsDB(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
def log_pkg(self, board, packet):
|
||||
print("[{}] [receive] freq: {}, crc: {}, signal-noise-ratio: {}, signal strength: {} (packet: {})".format(
|
||||
payload['datetime'].isoformat(),
|
||||
board.frequency,
|
||||
payload.get('crc'),
|
||||
payload.get('pkt_snr'),
|
||||
payload.get('rssi'),
|
||||
payload.get('pkt_rssi'),
|
||||
))
|
||||
|
||||
def log_packet(self, board, packet):
|
||||
print("[{}] [receive] freq: {}, crc: {}, signal-noise-ratio: {}, signal strength: {} (packet: {})".format(
|
||||
payload['datetime'].isoformat(),
|
||||
board.frequency,
|
||||
payload.get('crc'),
|
||||
payload.get('pkt_snr'),
|
||||
payload.get('rssi'),
|
||||
payload.get('pkt_rssi'),
|
||||
))
|
||||
|
||||
|
||||
def construct_semtec_udp(board, payload):
|
||||
|
@ -69,8 +63,6 @@ def construct_semtec_udp(board, payload):
|
|||
if __name__ == "__main__":
|
||||
# sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
|
||||
|
||||
db = LoRaPacketsDB()
|
||||
|
||||
with LoraBoardDraguino(433300000, 7) as board:
|
||||
board.set_mode_rx()
|
||||
print("Listening at SF{} on {} MHz".format(
|
||||
|
@ -79,18 +71,20 @@ if __name__ == "__main__":
|
|||
))
|
||||
|
||||
while True:
|
||||
if GPIO.input(board._pin_dio0) == 1:
|
||||
payload = board.receive_package()
|
||||
if GPIO.input(board._pin_dio0) != 1:
|
||||
continue
|
||||
|
||||
# semtec_udp = construct_semtec_udp(board, payload)
|
||||
# sock.sendto(semtec_udp, (GATEWAY_HOST, GATEWAY_PORT))
|
||||
# logging.info(semtec_udp)
|
||||
payload = board.receive_package()
|
||||
|
||||
# logging.info("Received: {}".format(payload))
|
||||
print("Received at {}: {} = {}".format(
|
||||
payload['datetime'].isoformat(),
|
||||
payload['payload'].hex(),
|
||||
payload['payload'][4:]
|
||||
))
|
||||
# semtec_udp = construct_semtec_udp(board, payload)
|
||||
# sock.sendto(semtec_udp, (GATEWAY_HOST, GATEWAY_PORT))
|
||||
# logging.info(semtec_udp)
|
||||
|
||||
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)
|
||||
|
|
Reference in a new issue