#!venv/bin/python # # This script is a very simple APRS-IS LoRa igate that # runs on a raspberry pi and expects a RFM9x on the SPI bus. # # Also, there are two status LEDs on D23 and D24 that count # the incoming messages. # # It is a send-only i-gate that uses the HTTP POST mechanism described # on http://aprs-is.net/SendOnlyPorts.aspx # import datetime import socket import struct import time import busio from digitalio import DigitalInOut, Direction, Pull import board # Import the RFM9x radio module. import adafruit_rfm9x # For APRS-IS APRS_IS_SERVER = "france.aprs2.net" APRS_IS_PORT = 8080 #APRS_IS_PORT = 14580 CALLSIGN = "HB9EGM-10" PASSCODE = "22681" REPORTING_DISTANCE = "10" def decode_encoded_position_report(packet): """Returns a string with decoded latitude and longitude, or raises ValueError""" ix = packet.index(b":!/") gps_packet = packet[ix+3:] encoded_latitude = gps_packet[:4] encoded_longitude = gps_packet[4:8] (y1, y2, y3, y4) = struct.unpack(" 16: rfm9x.low_datarate_optimize = 1 else: rfm9x.low_datarate_optimize = 0 print("Waiting for packets...") while True: packet = rfm9x.receive(timeout=4, with_header=True) if packet is not None: packet = bytes(packet) # otherwise it's a bytearray print("{}: {}".format(datetime.datetime.now(), packet)) #print(" {}".format(" ".join(hex(x) for x in packet))) if b":!/" in packet: print(decode_encoded_position_report(packet)) try: send_frame_to_aprs_is(packet) except Exception as ex: print("Error sending to APRS-IS") print(ex) print(" RSSI: {}".format(rfm9x.last_rssi)) print() update_leds() except RuntimeError as error: print(f'RFM9x Error: {error}')