PE1RXF telemetry added
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
'''
|
||||
# A basic APRS iGate and APRS weather station with additional (optional) PE1RXF telemetry support
|
||||
#
|
||||
@@ -37,12 +38,13 @@ from threading import Thread
|
||||
|
||||
from weather_station_modbus import WeatherStation
|
||||
from config_reader import config_reader
|
||||
from aprs_telemetry_to_mqtt import aprs_telemetry_to_mqtt
|
||||
|
||||
main_config_file = "pe1rxf_aprs.yml"
|
||||
telemetry_config_file = "pe1rxf_telemetry.yml"
|
||||
rflog_file = ""
|
||||
# Make Weather data global so scheduled task can use it
|
||||
WxData = []
|
||||
WxData = {}
|
||||
APRSIS = []
|
||||
|
||||
axport = []
|
||||
@@ -365,6 +367,14 @@ def send_telemetry():
|
||||
|
||||
send_ax25('PE1RXF-3', 'PE1RXF-13', "APZMDM", 0, message)
|
||||
|
||||
def publish_weather_data(mqtt_client):
|
||||
|
||||
payload = ':' + 'PE1RXF-3 ' + ':' + str(WxData['Wind direction']) + ',' + str(WxData['Wind speed']) + ',' + str(WxData['Wind gust']) + ',' + str(WxData['Rain last hour']) + ',' + str(WxData['Rain last 24 hours']) + ',' + str(WxData['Temperature']) + ',' + str(WxData['Humidity']) + ',' + str(WxData['Pressure']) + ',' + str(WxData['Temp backup']) + ',' + str(WxData['Status bits'])
|
||||
|
||||
telemetry=mqtt_client.publish_telemetry_message("PE1RXF-13", "ax1", "PE1RXF-3", payload)
|
||||
|
||||
return 1
|
||||
|
||||
def read_weather_station(weather_station):
|
||||
global WxData
|
||||
#print ("Reading registers of weather station.")
|
||||
@@ -372,6 +382,7 @@ def read_weather_station(weather_station):
|
||||
print ('No response from ModBus, even after 5 retries. Keep trying.')
|
||||
else:
|
||||
WxData = weather_station.wx_data
|
||||
print (WxData)
|
||||
|
||||
def check_heater(weather_station):
|
||||
# Check if heater is off, if so, turn it on
|
||||
@@ -388,6 +399,19 @@ def run():
|
||||
|
||||
global WxData
|
||||
|
||||
# Fill WxData with some sensible data to start:
|
||||
WxData['ID'] = 0.0
|
||||
WxData['Wind direction'] = 0.0
|
||||
WxData['Wind speed'] = 0.0
|
||||
WxData['Wind gust'] = 0.0
|
||||
WxData['Rain last hour'] = 0.0
|
||||
WxData['Rain last 24 hours'] = 0.0
|
||||
WxData['Temperature'] = 0.0
|
||||
WxData['Humidity'] = 0.0
|
||||
WxData['Pressure'] = 0.0
|
||||
WxData['Temp backup'] = 0.0
|
||||
WxData['Status bits'] = 0.0
|
||||
|
||||
# Debug logging for aprslib
|
||||
logging.basicConfig(level=logging.DEBUG) # level=10
|
||||
|
||||
@@ -405,6 +429,10 @@ def run():
|
||||
print ("Write APRS frames to: " + rflog_file)
|
||||
print ("Read configuration files.")
|
||||
|
||||
# Setup MQTT connection
|
||||
mqtt_connection = aprs_telemetry_to_mqtt(telemetry_config_file)
|
||||
mqtt_connection.read_settings()
|
||||
|
||||
rx_socket = setup_ax25()
|
||||
|
||||
# a valid passcode for the callsign is required in order to send
|
||||
@@ -450,10 +478,6 @@ def run():
|
||||
interval = interval * 60 # from minutes to seconds
|
||||
schedule.every(interval - 59).to(interval + 59).seconds.do(send_aprs_beacon, entry)
|
||||
|
||||
# Schedule telemetry transmision
|
||||
print("Scheduled telemetry transmission.")
|
||||
schedule.every(10).minutes.do(send_telemetry)
|
||||
|
||||
# Schedule check if heater is still on
|
||||
# So when the weather station is unplugged and plugged back in, the heater will be enabled again.
|
||||
schedule.every(10).minutes.do(check_heater, weather_station)
|
||||
@@ -462,6 +486,15 @@ def run():
|
||||
print("Scheduled readout of weather station.")
|
||||
schedule.every(1).minutes.do(read_weather_station, weather_station)
|
||||
|
||||
# Schedule telemetry transmision
|
||||
print("Scheduled telemetry transmission.")
|
||||
schedule.every(10).minutes.do(send_telemetry)
|
||||
|
||||
print("Schedule mqtt weather publisher.")
|
||||
interval = mqtt_connection.config_file_settings['global']['weather_report_interval']
|
||||
if interval != 0:
|
||||
schedule.every(interval).minutes.do(publish_weather_data, mqtt_connection)
|
||||
|
||||
# Connect to incoming APRS-IS feed
|
||||
# by default `raw` is False, then each line is ran through aprslib.parse()
|
||||
# Set filter on incomming feed
|
||||
@@ -516,11 +549,19 @@ def run():
|
||||
|
||||
#aprs_frame = axaddress[0] + '>' + destination + ',' + ','.join(digipeaters) + ':' + payload
|
||||
#print (aprs_frame)
|
||||
log_ax25(axaddress[port], source, destination, ','.join(digipeaters), payload, 'R')
|
||||
digipeaters.append('qAR')
|
||||
digipeaters.append(Configuration.config_file_settings['aprsis']['call'])
|
||||
send_aprsis(source, destination, ','.join(digipeaters), payload)
|
||||
#telemetry=process_message(source, port, payload, client)
|
||||
if payload == 'NOT VALID':
|
||||
print (">>> Packet not valid, ignored.")
|
||||
else:
|
||||
log_ax25(axaddress[port], source, destination, ','.join(digipeaters), payload, 'R')
|
||||
digipeaters.append('qAR')
|
||||
digipeaters.append(Configuration.config_file_settings['aprsis']['call'])
|
||||
send_aprsis(source, destination, ','.join(digipeaters), payload)
|
||||
|
||||
# Check if APRS frame is PE1RXF telemetry
|
||||
telemetry=mqtt_connection.publish_telemetry_message(source, axdevice[port], axaddress[port], payload)
|
||||
|
||||
# Check if APRS frame is a message to us
|
||||
mqtt_connection.publish_aprs_messages(source, axdevice[port], payload)
|
||||
|
||||
|
||||
#time.sleep(1) # Short sleep
|
||||
|
Reference in New Issue
Block a user