diff --git a/gateway/bc-gateway.py b/gateway/bc-gateway.py index 779280d..a356d62 100755 --- a/gateway/bc-gateway.py +++ b/gateway/bc-gateway.py @@ -5,7 +5,7 @@ import time import logging import argparse -import json +import simplejson as json import platform import decimal import yaml @@ -30,21 +30,6 @@ LOG_FORMAT = '%(asctime)s %(levelname)s: %(message)s' -class FakeFloat(float): - - def __init__(self, value): - self._value = value - - def __repr__(self): - return str(self._value) - - -def decimal_default(obj): - if isinstance(obj, decimal.Decimal): - return FakeFloat(obj) - raise TypeError - - def mqtt_on_connect(client, userdata, flags, rc): logging.info('Connected to MQTT broker with code %s', rc) client.subscribe(userdata['base_topic'] + '+/+/+/+/+') @@ -88,7 +73,7 @@ def run(): except Exception: logging.error('Invalid JSON message received from serial port: %s', line) try: - mqttc.publish(base_topic + talk[0], json.dumps(talk[1], default=decimal_default), qos=1) + mqttc.publish(base_topic + talk[0], json.dumps(talk[1], use_decimal=True), qos=1) except Exception: logging.error('Failed to publish MQTT message: %s', line) diff --git a/gateway/requirements.txt b/gateway/requirements.txt index 5389839..22bbf60 100644 --- a/gateway/requirements.txt +++ b/gateway/requirements.txt @@ -1,3 +1,4 @@ -paho-mqtt>=1.0 # deb:python3-paho-mqtt>=1.0 -pyserial>=2.6 # deb:python3-serial>=2.6 -PyYAML>=3.12 # deb:python3-yaml>=3.12 \ No newline at end of file +paho-mqtt>=1.0 # deb:python3-paho-mqtt>=1.0 +pyserial>=2.6 # deb:python3-serial>=2.6 +PyYAML>=3.12 # deb:python3-yaml>=3.12 +simplejson>=3.10.0 # deb:python3-simplejson>=3.10.0 \ No newline at end of file