Test software-file is now main software-file
This commit is contained in:
@@ -46,6 +46,7 @@ rflog_file = ""
|
|||||||
# Make Weather data global so scheduled task can use it
|
# Make Weather data global so scheduled task can use it
|
||||||
WxData = {}
|
WxData = {}
|
||||||
APRSIS = []
|
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 = []
|
axport = []
|
||||||
axdevice = []
|
axdevice = []
|
||||||
@@ -205,6 +206,12 @@ def getAllAddress(packetAddress):
|
|||||||
|
|
||||||
def process_aprsis(packet):
|
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")
|
#print("Received APRSIS")
|
||||||
timestamp = time.strftime("%Y-%m-%d %H:%M:%S", gmtime())
|
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'
|
string = timestamp + ' ' + 'APRSIS ' + ' R ' + str(packet, 'latin-1') + '\n'
|
||||||
|
|
||||||
# Check if frame is a message to us. If so send it to mqtt
|
# 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"])
|
# Split packet at first occurance of ':', which seperates the header from the payload
|
||||||
print("Source Address = %s"%aprsis_source)
|
aprsis_payload = str(packet, 'latin-1').split(':', 1)
|
||||||
print("Destination Address = %s"%aprsis_destination)
|
|
||||||
print("Digipeaters =")
|
|
||||||
print(aprsis_digipeaters)
|
|
||||||
print("Payload = %s"%aprsis_payload)
|
|
||||||
print("")
|
|
||||||
|
|
||||||
#aprs_frame = axaddress[0] + '>' + aprsis_destination + ',' + ','.join(aprsis_digipeaters) + ':' + aprsis_payload
|
# We should have two substrings
|
||||||
#print (aprs_frame)
|
if len(aprsis_payload) == 2:
|
||||||
if aprsis_payload == 'NOT VALID' or aprsis_payload == 0:
|
# extract from_call
|
||||||
print (">>> Packet not valid, ignored.")
|
aprsis_data[0] = aprsis_payload[0].split('>',1)
|
||||||
else:
|
|
||||||
|
|
||||||
# Check if APRS frame is a message to us
|
aprsis_data[1] = aprsis_payload[1]
|
||||||
mqtt_connection.publish_aprs_messages(aprsis_source, 'aprsis', aprsis_payload)
|
aprsis_data[2] = True
|
||||||
|
|
||||||
|
#print ("In thread:")
|
||||||
|
#print (aprsis_data[0])
|
||||||
|
#print (aprsis_data[1])
|
||||||
|
|
||||||
# write APRSIS string to log file
|
# write APRSIS string to log file
|
||||||
try:
|
try:
|
||||||
@@ -541,8 +539,9 @@ def run():
|
|||||||
# by default `raw` is False, then each line is ran through aprslib.parse()
|
# by default `raw` is False, then each line is ran through aprslib.parse()
|
||||||
# Set filter on incomming feed
|
# Set filter on incomming feed
|
||||||
APRSIS.set_filter(Configuration.config_file_settings['aprsis']['filter'])
|
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
|
# create a thread
|
||||||
|
global aprsis_data
|
||||||
thread = Thread(target=APRSIS.consumer, args=(process_aprsis, True, True, True))
|
thread = Thread(target=APRSIS.consumer, args=(process_aprsis, True, True, True))
|
||||||
# run the thread
|
# run the thread
|
||||||
thread.start()
|
thread.start()
|
||||||
@@ -606,10 +605,21 @@ def run():
|
|||||||
mqtt_connection.publish_aprs_messages(source, axdevice[port], payload)
|
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
|
#time.sleep(1) # Short sleep
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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()
|
run()
|
||||||
|
Reference in New Issue
Block a user