From 4d169139e964884e30cc6b24153a783964cf2eb8 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Thu, 13 Jul 2023 11:46:51 +0200 Subject: Update i-gate --- python/igate.py | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'python') diff --git a/python/igate.py b/python/igate.py index 9466304..91edbcc 100755 --- a/python/igate.py +++ b/python/igate.py @@ -14,6 +14,7 @@ import socket import struct import time +import requests import busio from digitalio import DigitalInOut, Direction, Pull import board @@ -23,9 +24,14 @@ 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" + +# 46°23.07' N 6°13.28' +LATITUDE = "4623.07N" +LONGITUDE = "00613.28E" +COMMENT = "RPi RFM98W Python igate, https://mpb.li/git/lora-aprs-hb9egm/tree/python/igate.py" + +PASSCODE = "17832" REPORTING_DISTANCE = "10" def decode_encoded_position_report(packet): @@ -48,14 +54,13 @@ def send_frame_to_aprs_is(frame): headers = { "Accept": "text/plain", "Content-Type": "application/octet-stream" } aprsauth = f"user {CALLSIGN} pass {PASSCODE} vers HB9EGM_lorapy 1.0 filter t/m/{CALLSIGN}/{REPORTING_DISTANCE}\n"; + data = aprsauth.encode() + frame - # Prefix igate path - path, _, message = frame[3:].partition(b":") - new_frame = path + b",qAO," + CALLSIGN.encode() + b":" + message + b"\n" - data = aprsauth.encode() + new_frame + print(data) r = requests.post(f"http://{APRS_IS_SERVER}:{APRS_IS_PORT}/", data=data, headers=headers) print(f"{r.status_code} {r.content.decode()}") + r.raise_for_status() led_yellow = DigitalInOut(board.D23) @@ -66,6 +71,7 @@ led_green.direction = Direction.OUTPUT led_counter = 0 def update_leds(): + global led_counter led_counter = (led_counter + 1) % 4 led_green.value = (led_counter & 0x1) != 0 @@ -79,6 +85,8 @@ spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) baudrate = 5000000 +last_beacon_time = time.time() + # see https://docs.circuitpython.org/projects/rfm9x/en/latest/ try: rfm9x = adafruit_rfm9x.RFM9x(spi, cs, reset, 433.775, baudrate=baudrate, preamble_length=8) @@ -107,14 +115,29 @@ try: if b":!/" in packet: print(decode_encoded_position_report(packet)) try: - send_frame_to_aprs_is(packet) + # Prefix igate path + path, _, message = packet[3:].partition(b":") + new_frame = path + b",qAO," + CALLSIGN.encode() + b":" + message + b"\n" + send_frame_to_aprs_is(new_frame) except Exception as ex: - print("Error sending to APRS-IS") + print("Error sending position report to APRS-IS") print(ex) print(" RSSI: {}".format(rfm9x.last_rssi)) print() update_leds() + + now = time.time() + + if last_beacon_time + 1800 < now: + last_beacon_time = now + packet = f"{CALLSIGN}>APLRG1,qAC:={LATITUDE}L{LONGITUDE}&{COMMENT}" + try: + send_frame_to_aprs_is(packet.encode()) + except Exception as ex: + print("Error sending beacon to APRS-IS") + print(ex) + except RuntimeError as error: print(f'RFM9x Error: {error}') -- cgit v1.2.3