From adecfc923c03b16339b4e8046cdb1f94f68d9310 Mon Sep 17 00:00:00 2001 From: marcel Date: Sun, 26 Jan 2025 21:13:55 +0100 Subject: [PATCH] Test software-file is now main software-file --- pe1rxf_aprs.py | 56 +++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/pe1rxf_aprs.py b/pe1rxf_aprs.py index c2efa52..0c3d85f 100755 --- a/pe1rxf_aprs.py +++ b/pe1rxf_aprs.py @@ -46,6 +46,7 @@ rflog_file = "" # Make Weather data global so scheduled task can use it WxData = {} APRSIS = [] +aprsis_data = ['', '',False] # Global variable for storing received APRSIS frames. Shared between threads. [0]=from_call, [1]=payload, [2]=token (set by thread, reset by main loop) axport = [] axdevice = [] @@ -205,6 +206,12 @@ def getAllAddress(packetAddress): def process_aprsis(packet): + global aprsis_data + + # Setup MQTT connection + mqtt_connection2 = aprs_telemetry_to_mqtt(telemetry_config_file) + mqtt_connection2.read_settings() + #print("Received APRSIS") timestamp = time.strftime("%Y-%m-%d %H:%M:%S", gmtime()) @@ -214,30 +221,21 @@ def process_aprsis(packet): string = timestamp + ' ' + 'APRSIS ' + ' R ' + str(packet, 'latin-1') + '\n' # Check if frame is a message to us. If so send it to mqtt - aprsis_source, aprsis_destination, aprsis_digipeaters, aprsis_payload = parsePacket(packet) - print(packet) - # Convert byte string to normal string - try: - aprsis_payload = aprsis_payload.decode('latin-1') - except: - aprsis_payload = 'NOT VALID' - print("Packet Received by APRSIS"]) - print("Source Address = %s"%aprsis_source) - print("Destination Address = %s"%aprsis_destination) - print("Digipeaters =") - print(aprsis_digipeaters) - print("Payload = %s"%aprsis_payload) - print("") + # Split packet at first occurance of ':', which seperates the header from the payload + aprsis_payload = str(packet, 'latin-1').split(':', 1) - #aprs_frame = axaddress[0] + '>' + aprsis_destination + ',' + ','.join(aprsis_digipeaters) + ':' + aprsis_payload - #print (aprs_frame) - if aprsis_payload == 'NOT VALID' or aprsis_payload == 0: - print (">>> Packet not valid, ignored.") - else: + # We should have two substrings + if len(aprsis_payload) == 2: + # extract from_call + aprsis_data[0] = aprsis_payload[0].split('>',1) - # Check if APRS frame is a message to us - mqtt_connection.publish_aprs_messages(aprsis_source, 'aprsis', aprsis_payload) + aprsis_data[1] = aprsis_payload[1] + aprsis_data[2] = True + + #print ("In thread:") + #print (aprsis_data[0]) + #print (aprsis_data[1]) # write APRSIS string to log file try: @@ -541,8 +539,9 @@ def run(): # by default `raw` is False, then each line is ran through aprslib.parse() # Set filter on incomming feed APRSIS.set_filter(Configuration.config_file_settings['aprsis']['filter']) - # This is a blocking call, should run as seperate thread + # This is a blocking call, should run as seperate thread. Data from aprsis is stored in aprsid_data. [0]=from_call, [1]=payload, [2]=token (set by thread, reset by main loop) # create a thread + global aprsis_data thread = Thread(target=APRSIS.consumer, args=(process_aprsis, True, True, True)) # run the thread thread.start() @@ -606,10 +605,21 @@ def run(): mqtt_connection.publish_aprs_messages(source, axdevice[port], payload) + # If APRSIS read thread receives message for us, send it to MQTT + if aprsis_data[2] == True: + + aprsis_data[2] = False + print ("In loop:") + print (aprsis_data[0]) + print (aprsis_data[1]) + mqtt_connection.publish_aprs_messages(aprsis_data[0][0], 'APRSIS', aprsis_data[1]) + + #time.sleep(1) # Short sleep + if __name__ == '__main__': - #sys.stdout = sys.stderr = open('/home/marcel/pe1rxf_aprs_debug.log', 'w') + sys.stdout = sys.stderr = open('/home/marcel/pe1rxf_aprs_debug.log', 'w') run()