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 8ffb50e60edb4bc1dc2a9cb0a8dc775713cdf37a
parent c1b8cbfa0be6037261eeec33a8e934f680fee1b3 Author: acidvegas <acid.vegas@acid.vegas> Date: Mon, 2 Dec 2024 22:50:05 -0500 Fixed error when parsing NaN (converting to None) Diffstat:
|
1 file changed, 16 insertions(+), 1 deletion(-) |
diff --git a/src/meshtastic_mqtt_json/client.py b/src/meshtastic_mqtt_json/client.py @@ -167,7 +167,22 @@ class MeshtasticMQTT(object): if self.filters and portnum_name not in self.filters: return - json_packet = json.loads(MessageToJson(mp)) + # Convert to JSON with parsing options to handle NaN + json_packet = json.loads(MessageToJson(mp, including_default_value_fields=True, + preserving_proto_field_name=True, + float_precision=10)) + + # Replace NaN values with null in the JSON structure + def replace_nan(obj): + if isinstance(obj, dict): + return {k: replace_nan(v) for k, v in obj.items()} + elif isinstance(obj, list): + return [replace_nan(x) for x in obj] + elif isinstance(obj, str) and obj == 'NaN': + return None + return obj + + json_packet = replace_nan(json_packet) # Process the message based on its type if mp.decoded.portnum == portnums_pb2.ADMIN_APP: |