Compare commits

..

No commits in common. "main" and "v1.0.9" have entirely different histories.
main ... v1.0.9

3 changed files with 26 additions and 48 deletions

View File

@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup( setup(
name="meshtastic-mqtt-json", name="meshtastic-mqtt-json",
version='1.0.10', version='1.0.9',
author='acidvegas', author='acidvegas',
author_email='acid.vegas@acid.vegas', author_email='acid.vegas@acid.vegas',
description='A lightweight Python library for parsing Meshtastic MQTT messages', description='A lightweight Python library for parsing Meshtastic MQTT messages',

View File

@ -4,6 +4,6 @@ Meshtastic MQTT Interface - A lightweight Python library for parsing Meshtastic
from .client import MeshtasticMQTT from .client import MeshtasticMQTT
__version__ = '1.0.10' __version__ = '1.0.9'
__author__ = 'acidvegas' __author__ = 'acidvegas'
__license__ = 'ISC' __license__ = 'ISC'

View File

@ -212,38 +212,32 @@ class MeshtasticMQTT(object):
if mp.decoded.portnum == portnums_pb2.ADMIN_APP: if mp.decoded.portnum == portnums_pb2.ADMIN_APP:
data = mesh_pb2.Admin() data = mesh_pb2.Admin()
data.ParseFromString(mp.decoded.payload) data.ParseFromString(mp.decoded.payload)
msg = json.dumps(clean_json(data)) print(f'{clean_json(data)}')
print(f'{msg}')
elif mp.decoded.portnum == portnums_pb2.ATAK_FORWARDER: elif mp.decoded.portnum == portnums_pb2.ATAK_FORWARDER:
data = mesh_pb2.AtakForwarder() data = mesh_pb2.AtakForwarder()
data.ParseFromString(mp.decoded.payload) data.ParseFromString(mp.decoded.payload)
msg = json.dumps(clean_json(data)) print(f'{clean_json(data)}')
print(f'{msg}')
elif mp.decoded.portnum == portnums_pb2.ATAK_PLUGIN: elif mp.decoded.portnum == portnums_pb2.ATAK_PLUGIN:
data = mesh_pb2.AtakPlugin() data = mesh_pb2.AtakPlugin()
data.ParseFromString(mp.decoded.payload) data.ParseFromString(mp.decoded.payload)
msg = json.dumps(clean_json(data)) print(f'{clean_json(data)}')
print(f'{msg}')
elif mp.decoded.portnum == portnums_pb2.AUDIO_APP: elif mp.decoded.portnum == portnums_pb2.AUDIO_APP:
data = mesh_pb2.Audio() data = mesh_pb2.Audio()
data.ParseFromString(mp.decoded.payload) data.ParseFromString(mp.decoded.payload)
msg = json.dumps(clean_json(data)) print(f'{clean_json(data)}')
print(f'{msg}')
elif mp.decoded.portnum == portnums_pb2.DETECTION_SENSOR_APP: elif mp.decoded.portnum == portnums_pb2.DETECTION_SENSOR_APP:
data = mesh_pb2.DetectionSensor() data = mesh_pb2.DetectionSensor()
data.ParseFromString(mp.decoded.payload) data.ParseFromString(mp.decoded.payload)
msg = json.dumps(clean_json(data)) print(f'{clean_json(data)}')
print(f'{msg}')
elif mp.decoded.portnum == portnums_pb2.IP_TUNNEL_APP: elif mp.decoded.portnum == portnums_pb2.IP_TUNNEL_APP:
data = mesh_pb2.IPTunnel() data = mesh_pb2.IPTunnel()
data.ParseFromString(mp.decoded.payload) data.ParseFromString(mp.decoded.payload)
msg = json.dumps(clean_json(data)) print(f'{clean_json(data)}')
print(f'{msg}')
elif mp.decoded.portnum == portnums_pb2.MAP_REPORT_APP: elif mp.decoded.portnum == portnums_pb2.MAP_REPORT_APP:
map_report = mesh_pb2.MapReport() map_report = mesh_pb2.MapReport()
@ -268,8 +262,7 @@ class MeshtasticMQTT(object):
elif mp.decoded.portnum == portnums_pb2.PAXCOUNTER_APP: elif mp.decoded.portnum == portnums_pb2.PAXCOUNTER_APP:
data = mesh_pb2.Paxcounter() data = mesh_pb2.Paxcounter()
data.ParseFromString(mp.decoded.payload) data.ParseFromString(mp.decoded.payload)
msg = json.dumps(clean_json(data)) print(f'{clean_json(data)}')
print(f'{msg}')
elif mp.decoded.portnum == portnums_pb2.POSITION_APP: elif mp.decoded.portnum == portnums_pb2.POSITION_APP:
position = mesh_pb2.Position() position = mesh_pb2.Position()
@ -280,8 +273,7 @@ class MeshtasticMQTT(object):
elif mp.decoded.portnum == portnums_pb2.PRIVATE_APP: elif mp.decoded.portnum == portnums_pb2.PRIVATE_APP:
data = mesh_pb2.Private() data = mesh_pb2.Private()
data.ParseFromString(mp.decoded.payload) data.ParseFromString(mp.decoded.payload)
msg = json.dumps(clean_json(data)) print(f'{clean_json(data)}')
print(f'{msg}')
elif mp.decoded.portnum == portnums_pb2.RANGE_TEST_APP: elif mp.decoded.portnum == portnums_pb2.RANGE_TEST_APP:
data = mesh_pb2.RangeTest() data = mesh_pb2.RangeTest()
@ -292,14 +284,12 @@ class MeshtasticMQTT(object):
elif mp.decoded.portnum == portnums_pb2.REMOTE_HARDWARE_APP: elif mp.decoded.portnum == portnums_pb2.REMOTE_HARDWARE_APP:
data = mesh_pb2.RemoteHardware() data = mesh_pb2.RemoteHardware()
data.ParseFromString(mp.decoded.payload) data.ParseFromString(mp.decoded.payload)
msg = json.dumps(clean_json(data)) print(f'{clean_json(data)}')
print(f'{msg}')
elif mp.decoded.portnum == portnums_pb2.REPLY_APP: elif mp.decoded.portnum == portnums_pb2.REPLY_APP:
data = mesh_pb2.Reply() data = mesh_pb2.Reply()
data.ParseFromString(mp.decoded.payload) data.ParseFromString(mp.decoded.payload)
msg = json.dumps(clean_json(data)) print(f'{clean_json(data)}')
print(f'{msg}')
elif mp.decoded.portnum == portnums_pb2.ROUTING_APP: elif mp.decoded.portnum == portnums_pb2.ROUTING_APP:
routing = mesh_pb2.Routing() routing = mesh_pb2.Routing()
@ -310,14 +300,12 @@ class MeshtasticMQTT(object):
elif mp.decoded.portnum == portnums_pb2.SERIAL_APP: elif mp.decoded.portnum == portnums_pb2.SERIAL_APP:
data = mesh_pb2.Serial() data = mesh_pb2.Serial()
data.ParseFromString(mp.decoded.payload) data.ParseFromString(mp.decoded.payload)
msg = json.dumps(clean_json(data)) print(f'{clean_json(data)}')
print(f'{msg}')
elif mp.decoded.portnum == portnums_pb2.SIMULATOR_APP: elif mp.decoded.portnum == portnums_pb2.SIMULATOR_APP:
data = mesh_pb2.Simulator() data = mesh_pb2.Simulator()
data.ParseFromString(mp.decoded.payload) data.ParseFromString(mp.decoded.payload)
msg = json.dumps(clean_json(data)) print(f'{clean_json(data)}')
print(f'{msg}')
elif mp.decoded.portnum == portnums_pb2.STORE_FORWARD_APP: elif mp.decoded.portnum == portnums_pb2.STORE_FORWARD_APP:
print(f'{clean_json(mp)}') print(f'{clean_json(mp)}')
@ -337,8 +325,7 @@ class MeshtasticMQTT(object):
elif mp.decoded.portnum == portnums_pb2.TEXT_MESSAGE_COMPRESSED_APP: elif mp.decoded.portnum == portnums_pb2.TEXT_MESSAGE_COMPRESSED_APP:
data = mesh_pb2.TextMessageCompressed() data = mesh_pb2.TextMessageCompressed()
data.ParseFromString(mp.decoded.payload) data.ParseFromString(mp.decoded.payload)
msg = json.dumps(clean_json(data)) print(f'{clean_json(data)}')
print(f'{msg}')
elif mp.decoded.portnum == portnums_pb2.TRACEROUTE_APP: elif mp.decoded.portnum == portnums_pb2.TRACEROUTE_APP:
routeDiscovery = mesh_pb2.RouteDiscovery() routeDiscovery = mesh_pb2.RouteDiscovery()
@ -352,19 +339,16 @@ class MeshtasticMQTT(object):
elif mp.decoded.portnum == portnums_pb2.WAYPOINT_APP: elif mp.decoded.portnum == portnums_pb2.WAYPOINT_APP:
data = mesh_pb2.Waypoint() data = mesh_pb2.Waypoint()
data.ParseFromString(mp.decoded.payload) data.ParseFromString(mp.decoded.payload)
msg = json.dumps(clean_json(data)) print(f'{clean_json(data)}')
print(f'{msg}')
elif mp.decoded.portnum == portnums_pb2.ZPS_APP: elif mp.decoded.portnum == portnums_pb2.ZPS_APP:
data = mesh_pb2.Zps() data = mesh_pb2.Zps()
data.ParseFromString(mp.decoded.payload) data.ParseFromString(mp.decoded.payload)
msg = json.dumps(clean_json(data)) print(f'{clean_json(data)}')
print(f'{msg}')
else: else:
print(f'UNKNOWN: Received Portnum name: {portnum_name}') print(f'UNKNOWN: Received Portnum name: {portnum_name}')
msg = json.dumps(clean_json(mp)) print(f'UNKNOWN: {clean_json(mp)}')
print(f'UNKNOWN: {msg}')
except Exception as e: except Exception as e:
print(f'Error processing message: {e}') print(f'Error processing message: {e}')
@ -375,16 +359,10 @@ class MeshtasticMQTT(object):
def event_mqtt_disconnect(self, client, userdata, rc, packet_from_broker=None, properties=None, reason_code=None): def event_mqtt_disconnect(self, client, userdata, rc, packet_from_broker=None, properties=None, reason_code=None):
'''Callback for when the client disconnects from the server.''' '''Callback for when the client disconnects from the server.'''
print(f'Disconnected with result code: {rc}') print(f'Disconnected with result code: {rc}')
while True:
print('Attempting to reconnect...')
try:
client.reconnect()
except Exception as e:
print(f'Error reconnecting to MQTT broker: {e}')
time.sleep(5) time.sleep(5)
else: print('Attempting to reconnect...')
print('Reconnected to MQTT broker') client.reconnect()
break
def main(): def main():