Add SEND_GATEWAY_ENABLED setting

This commit is contained in:
Starbeamrainbowlabs 2018-11-15 19:56:17 +00:00
parent 26e90adbf8
commit 0efbdeebe3
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -12,19 +12,21 @@ import RPi.GPIO as GPIO
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
# TODO: Move these to a settings file
GATEWAY_SEND_ENABLED = False
GATEWAY_HOST = "router.eu.thethings.network" GATEWAY_HOST = "router.eu.thethings.network"
GATEWAY_PORT = 1700 GATEWAY_PORT = 1700
def log_packet(self, board, packet): 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(), payload['datetime'].isoformat(),
board.frequency, board.frequency,
payload.get('crc'), payload.get('crc'),
payload.get('pkt_snr'), payload.get('pkt_snr'),
payload.get('rssi'), payload.get('rssi'),
payload.get('pkt_rssi'), payload.get('pkt_rssi'),
payload['payload'].hex()
)) ))
@ -61,7 +63,9 @@ def construct_semtec_udp(board, payload):
if __name__ == "__main__": 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: with LoraBoardDraguino(433300000, 7) as board:
board.set_mode_rx() board.set_mode_rx()
@ -76,15 +80,10 @@ if __name__ == "__main__":
payload = board.receive_package() payload = board.receive_package()
# semtec_udp = construct_semtec_udp(board, payload) if GATEWAY_SEND_ENABLED:
# sock.sendto(semtec_udp, (GATEWAY_HOST, GATEWAY_PORT)) semtec_udp = construct_semtec_udp(board, payload)
# logging.info(semtec_udp) 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) log_packet(board, payload)