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
|
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):
|
||||||
|
@ -68,29 +62,29 @@ 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(
|
||||||
board.sf,
|
board.sf,
|
||||||
board.frequency / 1000000
|
board.frequency / 1000000
|
||||||
))
|
))
|
||||||
|
|
||||||
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)
|
# semtec_udp = construct_semtec_udp(board, payload)
|
||||||
|
# sock.sendto(semtec_udp, (GATEWAY_HOST, GATEWAY_PORT))
|
||||||
# logging.info("Received: {}".format(payload))
|
# logging.info(semtec_udp)
|
||||||
print("Received at {}: {} = {}".format(
|
|
||||||
payload['datetime'].isoformat(),
|
# logging.info("Received: {}".format(payload))
|
||||||
payload['payload'].hex(),
|
print("Received at {}: {} = {}".format(
|
||||||
payload['payload'][4:]
|
payload['datetime'].isoformat(),
|
||||||
))
|
payload['payload'].hex(),
|
||||||
|
payload['payload'][4:]
|
||||||
db.log_pkg(board, payload)
|
))
|
||||||
|
|
||||||
|
log_packet(board, payload)
|
||||||
|
|
Reference in a new issue