From 98ccf8708f186f909dd9986ef1e72b9bff19504d Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 5 Oct 2025 17:47:19 -0700 Subject: [PATCH] enhanceTelemetry logging and handlers for telemetry --- config.template | 10 ++++---- modules/settings.py | 2 ++ modules/system.py | 57 ++++++++++++++++++++++++++++++++++----------- 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/config.template b/config.template index 1b96e04..5cff0ee 100644 --- a/config.template +++ b/config.template @@ -121,6 +121,8 @@ SentryChannel = 2 SentryHoldoff = 9 # list of ignored nodes numbers ex: 2813308004,4258675309 sentryIgnoreList = +# Enable detection sensor alert, requires external sensor connected to node +detectionSensorAlert = False # HighFlying Node alert highFlyingAlert = True @@ -347,8 +349,8 @@ enableHopLogs = False # Noisy Node Telemetry Logging and packet threshold noisyNodeLogging = False noisyTelemetryLimit = 5 -# Enable detailed packet logging -debugMetadata = False +# Enable detailed packet logging all packets DEBUGpacket = False - - +# metaPacket detailed logging, the filter negates the port ID +debugMetadata = False +metadataFilter = TELEMETRY_APP, POSITION_APP diff --git a/modules/settings.py b/modules/settings.py index 8b49d0f..ff393ee 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -253,6 +253,7 @@ try: highfly_interface = config['sentry'].getint('highFlyingAlertInterface', 1) # default 1 highfly_ignoreList = config['sentry'].get('highFlyingIgnoreList', '').split(',') # default empty highfly_check_openskynetwork = config['sentry'].getboolean('highflyOpenskynetwork', True) # default True check with OpenSkyNetwork if highfly detected + detctionSensorAlert = config['sentry'].getboolean('detectionSensorAlert', False) # default False # location location_enabled = config['location'].getboolean('enabled', True) @@ -379,6 +380,7 @@ try: maxBuffer = config['messagingSettings'].getint('maxBuffer', 200) # default 200 enableHopLogs = config['messagingSettings'].getboolean('enableHopLogs', False) # default False debugMetadata = config['messagingSettings'].getboolean('debugMetadata', False) # default False + metadataFilter = config['messagingSettings'].get('metadataFilter', '').split(',') # default empty DEBUGpacket = config['messagingSettings'].getboolean('DEBUGpacket', False) # default False noisyNodeLogging = config['messagingSettings'].getboolean('noisyNodeLogging', False) # default False noisyTelemetryLimit = config['messagingSettings'].getint('noisyTelemetryLimit', 5) # default 5 packets diff --git a/modules/system.py b/modules/system.py index cdc7ce5..8c5b6d3 100644 --- a/modules/system.py +++ b/modules/system.py @@ -993,8 +993,10 @@ def displayNodeTelemetry(nodeID=0, rxNode=0, userRequested=False): positionMetadata = {} def consumeMetadata(packet, rxNode=0): + global positionMetadata, telemetryData + + # Process Telemetry and Position metadata packets try: - # keep records of recent telemetry data packet_type = '' if packet.get('decoded'): packet_type = packet['decoded']['portnum'] @@ -1002,11 +1004,18 @@ def consumeMetadata(packet, rxNode=0): # TELEMETRY packets if packet_type == 'TELEMETRY_APP': - if debugMetadata: print(f"DEBUG TELEMETRY_APP: {packet}\n\n") + if debugMetadata and 'TELEMETRY_APP' not in metadataFilter: + print(f"DEBUG TELEMETRY_APP: {packet}\n\n") # get the telemetry data telemetry_packet = packet['decoded']['telemetry'] if telemetry_packet.get('deviceMetrics'): deviceMetrics = telemetry_packet['deviceMetrics'] + #if uptime is in deviceMetrics and uptime is not 0 set uptime + # if deviceMetrics.get('uptimeSeconds') is not None and deviceMetrics['uptimeSeconds'] != 0: + # if highestUptime < deviceMetrics['uptimeSeconds']: + # highestUptime = deviceMetrics['uptimeSeconds'] + # highestUptimeNode = nodeID + if telemetry_packet.get('localStats'): localStats = telemetry_packet['localStats'] # Check if 'numPacketsTx' and 'numPacketsRx' exist and are not zero @@ -1022,7 +1031,8 @@ def consumeMetadata(packet, rxNode=0): # POSITION_APP packets if packet_type == 'POSITION_APP': - if debugMetadata: print(f"DEBUG POSITION_APP: {packet}\n\n") + if debugMetadata and 'POSITION_APP' not in metadataFilter: + print(f"DEBUG POSITION_APP: {packet}\n\n") # get the position data keys = ['altitude', 'groundSpeed', 'precisionBits'] position_data = packet['decoded']['position'] @@ -1066,42 +1076,63 @@ def consumeMetadata(packet, rxNode=0): # WAYPOINT_APP packets if packet_type == 'WAYPOINT_APP': - if debugMetadata: print(f"DEBUG WAYPOINT_APP: {packet['decoded']['waypoint']}\n\n") + if debugMetadata and 'WAYPOINT_APP' not in metadataFilter: + print(f"DEBUG WAYPOINT_APP: {packet}\n\n") # get the waypoint data - waypoint_data = packet['decoded'] + waypoint_data = packet['decoded']['waypoint'] + # if waypoint_data contains latitude and longitude log it + id = waypoint_data.get('id', 0) + latitudeI = waypoint_data.get('latitudeI', 0) + longitudeI = waypoint_data.get('longitudeI', 0) + expire = waypoint_data.get('expire', 0) + description = waypoint_data.get('description', '') + name = waypoint_data.get('name', '') + logger.info(f"System: Waypoint from NodeID:{nodeID} ID:{id} Name:{name} Desc:{description} Lat:{latitudeI/10000000} Lon:{longitudeI/10000000} Expire:{getPrettyTime(expire)}") # NEIGHBORINFO_APP if packet_type == 'NEIGHBORINFO_APP': - if debugMetadata: print(f"DEBUG NEIGHBORINFO_APP: {packet}\n\n") + if debugMetadata and 'NEIGHBORINFO_APP' not in metadataFilter: + print(f"DEBUG NEIGHBORINFO_APP: {packet}\n\n") # get the neighbor info data neighbor_data = packet['decoded'] - + neighbor_list = neighbor_data.get('neighbors', []) + logger.info(f"System: Neighbor Info from NodeID:{nodeID} Neighbors:{neighbor_list}") + # TRACEROUTE_APP if packet_type == 'TRACEROUTE_APP': - if debugMetadata: print(f"DEBUG TRACEROUTE_APP: {packet}\n\n") + if debugMetadata and 'TRACEROUTE_APP' not in metadataFilter: + print(f"DEBUG TRACEROUTE_APP: {packet}\n\n") # get the traceroute data traceroute_data = packet['decoded'] # DETECTION_SENSOR_APP if packet_type == 'DETECTION_SENSOR_APP': - if debugMetadata: print(f"DEBUG DETECTION_SENSOR_APP: {packet}\n\n") + if debugMetadata and 'DETECTION_SENSOR_APP' not in metadataFilter: + print(f"DEBUG DETECTION_SENSOR_APP: {packet}\n\n") # get the detection sensor data detection_data = packet['decoded'] detction_text = detection_data.get('text', '') if detction_text != '': logger.info(f"System: Detection Sensor Data from NodeID:{nodeID} Text:{detction_text}") - #send_message(f"📡Detection Sensor Data from NodeID:{nodeID} Text:{detction_text}", detection_sensor_channel, 0, detection_sensor_interface) - #time.sleep(responseDelay) + if detctionSensorAlert: + send_message(f"🚨Detection Sensor from NodeID:{nodeID} Alert:{detction_text}", secure_channel, 0, secure_interface) + time.sleep(responseDelay) # PAXCOUNTER_APP if packet_type == 'PAXCOUNTER_APP': - if debugMetadata: print(f"DEBUG PAXCOUNTER_APP: {packet}\n\n") + if debugMetadata and 'PAXCOUNTER_APP' not in metadataFilter: + print(f"DEBUG PAXCOUNTER_APP: {packet}\n\n") # get the paxcounter data paxcounter_data = packet['decoded'] + wifi_count = paxcounter_data.get('wifi_count', 0) + ble_count = paxcounter_data.get('ble_count', 0) + uptime = paxcounter_data.get('uptime', 0) + logger.info(f"System: Paxcounter Data from NodeID:{nodeID} WiFi:{wifi_count} BLE:{ble_count} Uptime:{uptime}s") # REMOTE_HARDWARE_APP if packet_type == 'REMOTE_HARDWARE_APP': - if debugMetadata: print(f"DEBUG REMOTE_HARDWARE_APP: {packet}\n\n") + if debugMetadata and 'REMOTE_HARDWARE_APP' not in metadataFilter: + print(f"DEBUG REMOTE_HARDWARE_APP: {packet}\n\n") # get the remote hardware data remote_hardware_data = packet['decoded'] except KeyError as e: