Add SEND_GATEWAY_ENABLED setting
This commit is contained in:
parent
26e90adbf8
commit
0efbdeebe3
1 changed files with 11 additions and 12 deletions
|
@ -12,19 +12,21 @@ import RPi.GPIO as GPIO
|
|||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
# TODO: Move these to a settings file
|
||||
GATEWAY_SEND_ENABLED = False
|
||||
GATEWAY_HOST = "router.eu.thethings.network"
|
||||
GATEWAY_PORT = 1700
|
||||
|
||||
|
||||
def log_packet(self, board, packet):
|
||||
print("[{}] [receive] freq: {}, crc: {}, signal-noise-ratio: {}, signal strength: {} (packet: {})".format(
|
||||
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'),
|
||||
payload['payload'].hex()
|
||||
))
|
||||
|
||||
|
||||
|
@ -61,7 +63,9 @@ def construct_semtec_udp(board, payload):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
|
||||
sock = None
|
||||
if GATEWAY_SEND_ENABLED:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
|
||||
|
||||
with LoraBoardDraguino(433300000, 7) as board:
|
||||
board.set_mode_rx()
|
||||
|
@ -76,15 +80,10 @@ if __name__ == "__main__":
|
|||
|
||||
payload = board.receive_package()
|
||||
|
||||
# semtec_udp = construct_semtec_udp(board, payload)
|
||||
# sock.sendto(semtec_udp, (GATEWAY_HOST, GATEWAY_PORT))
|
||||
# logging.info(semtec_udp)
|
||||
if GATEWAY_SEND_ENABLED:
|
||||
semtec_udp = construct_semtec_udp(board, payload)
|
||||
sock.sendto(semtec_udp, (GATEWAY_HOST, GATEWAY_PORT))
|
||||
logging.info(semtec_udp)
|
||||
|
||||
# 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