meshtastic_mqtt

- Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.acid.vegas/-c.git
Log | Files | Refs | Archive | README | LICENSE

commit 8a7b14e0176e55fcbcb9b115f80ca706baf39e31
parent 8ff2e6b04ac48f9c35347564876f6f9ee3239638
Author: acidvegas <acid.vegas@acid.vegas>
Date: Mon, 2 Dec 2024 21:19:30 -0500

Fixed error handling on inproper service envelopes

Diffstat:
Msrc/meshtastic_mqtt_json/client.py | 16+++++++++++-----

1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/meshtastic_mqtt_json/client.py b/src/meshtastic_mqtt_json/client.py
@@ -135,15 +135,20 @@ class MeshtasticMQTT(object):
 
 		:param client:   The client instance for this callback
 		:param userdata: The private user data as set in Client() or user_data_set()
-		:param msg:      An instance of MQTTMessage. This is a
+		:param msg:      An instance of MQTTMessage
 		'''
-
+		
 		try:
 			# Define the service envelope
 			service_envelope = mqtt_pb2.ServiceEnvelope()
 
-			# Parse the message payload
-			service_envelope.ParseFromString(msg.payload)
+			try:
+				# Parse the message payload
+				service_envelope.ParseFromString(msg.payload)
+			except Exception as e:
+				print(f'Error parsing service envelope: {e}')
+				print(f'Raw payload: {msg.payload}')
+				return
 
 			# Extract the message packet from the service envelope
 			mp = service_envelope.packet
@@ -299,7 +304,8 @@ class MeshtasticMQTT(object):
 
 		except Exception as e:
 			print(f'Error processing message: {e}')
-			print(mp)
+			print(f'Topic: {msg.topic}')
+			print(f'Payload: {msg.payload}')
 
 
 def main():