json dumps output for better inegstion
This commit is contained in:
parent
222fe3a7f1
commit
d92feb4a23
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="meshtastic-mqtt-json",
|
name="meshtastic-mqtt-json",
|
||||||
version='1.0.9',
|
version='1.0.10',
|
||||||
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',
|
||||||
|
@ -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.9'
|
__version__ = '1.0.10'
|
||||||
__author__ = 'acidvegas'
|
__author__ = 'acidvegas'
|
||||||
__license__ = 'ISC'
|
__license__ = 'ISC'
|
||||||
|
@ -212,32 +212,38 @@ 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)
|
||||||
print(f'{clean_json(data)}')
|
msg = json.dumps(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)
|
||||||
print(f'{clean_json(data)}')
|
msg = json.dumps(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)
|
||||||
print(f'{clean_json(data)}')
|
msg = json.dumps(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)
|
||||||
print(f'{clean_json(data)}')
|
msg = json.dumps(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)
|
||||||
print(f'{clean_json(data)}')
|
msg = json.dumps(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)
|
||||||
print(f'{clean_json(data)}')
|
msg = json.dumps(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()
|
||||||
@ -262,7 +268,8 @@ 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)
|
||||||
print(f'{clean_json(data)}')
|
msg = json.dumps(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()
|
||||||
@ -273,7 +280,8 @@ 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)
|
||||||
print(f'{clean_json(data)}')
|
msg = json.dumps(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()
|
||||||
@ -284,12 +292,14 @@ 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)
|
||||||
print(f'{clean_json(data)}')
|
msg = json.dumps(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)
|
||||||
print(f'{clean_json(data)}')
|
msg = json.dumps(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()
|
||||||
@ -300,12 +310,14 @@ 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)
|
||||||
print(f'{clean_json(data)}')
|
msg = json.dumps(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)
|
||||||
print(f'{clean_json(data)}')
|
msg = json.dumps(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)}')
|
||||||
@ -325,13 +337,14 @@ 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)
|
||||||
print(f'{clean_json(data)}')
|
msg = json.dumps(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()
|
||||||
routeDiscovery.ParseFromString(mp.decoded.payload)
|
routeDiscovery.ParseFromString(mp.decoded.payload)
|
||||||
json_packet['decoded']['payload'] = clean_json(routeDiscovery)
|
json_packet['decoded']['payload'] = clean_json(routeDiscovery)
|
||||||
print(f'{json.dumps(json_packet)}')
|
print(f'{json.dumps(json_packet)}')
|
||||||
|
|
||||||
elif mp.decoded.portnum == portnums_pb2.UNKNOWN_APP:
|
elif mp.decoded.portnum == portnums_pb2.UNKNOWN_APP:
|
||||||
print(f'{clean_json(mp)}')
|
print(f'{clean_json(mp)}')
|
||||||
@ -339,16 +352,19 @@ 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)
|
||||||
print(f'{clean_json(data)}')
|
msg = json.dumps(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)
|
||||||
print(f'{clean_json(data)}')
|
msg = json.dumps(clean_json(data))
|
||||||
|
print(f'{msg}')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(f'UNKNOWN: Received Portnum name: {portnum_name}')
|
print(f'UNKNOWN: Received Portnum name: {portnum_name}')
|
||||||
print(f'UNKNOWN: {clean_json(mp)}')
|
msg = json.dumps(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}')
|
||||||
@ -359,10 +375,16 @@ 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:
|
||||||
time.sleep(5)
|
print('Attempting to reconnect...')
|
||||||
print('Attempting to reconnect...')
|
try:
|
||||||
client.reconnect()
|
client.reconnect()
|
||||||
|
except Exception as e:
|
||||||
|
print(f'Error reconnecting to MQTT broker: {e}')
|
||||||
|
time.sleep(5)
|
||||||
|
else:
|
||||||
|
print('Reconnected to MQTT broker')
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
Loading…
Reference in New Issue
Block a user