thingsboard / thingsboard-gateway

Open-source IoT Gateway - integrates devices connected to legacy and third-party systems with ThingsBoard IoT Platform using Modbus, CAN bus, BACnet, BLE, OPC-UA, MQTT, ODBC and REST protocols
https://thingsboard.io/docs/iot-gateway/what-is-iot-gateway/
Apache License 2.0
1.75k stars 845 forks source link

[HELP] MQTT Connector unable to parse message from Publisher #462

Closed jsperatan closed 3 years ago

jsperatan commented 3 years ago

Hi I am ran into this error when trying to parse a message into my MQTT connector. As you can see, I have passed deviceName into the converter but it still showed an error message where deviceName is null. Btw I am running tb-gateway from a Docker.

sudo docker attach tb-gateway ""2021-01-17 16:20:07" - ERROR - [json_mqtt_uplink_converter.py] - json_mqtt_uplink_converter - 56 - Error in converter, for config: {"type": "json", "deviceNameJsonExpression": "${deviceName}", "deviceTypeJsonExpression": "${deviceType}", "timeout": 60000, "attributes": [], "timeseries": [{"type": "double", "key": "temperature", "value": "${temp}"}, {"type": "double", "key": "humidity", "value": "${hum}"}]} and message: "{"deviceName": "SN-001", "deviceType": "Thermometer", "temp": 42, "hum": 58} " ""2021-01-17 16:20:07" - ERROR - [json_mqtt_uplink_converter.py] - json_mqtt_uplink_converter - 57 - Extra data: line 1 column 4 - line 1 column 78 (char 3 - 77)" Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/thingsboard_gateway-2.5.5.2-py3.8.egg/thingsboard_gateway/connectors/mqtt/json_mqtt_uplink_converter.py", line 34, in convert dict_result["deviceName"] = TBUtility.get_value(self.config.get("deviceNameJsonExpression"), data, expression_instead_none=True) File "/usr/local/lib/python3.8/site-packages/thingsboard_gateway-2.5.5.2-py3.8.egg/thingsboard_gateway/tb_utility/tb_utility.py", line 124, in get_value body = loads(body) File "/usr/local/lib/python3.8/site-packages/simplejson-3.17.2-py3.8-linux-x86_64.egg/simplejson/init__.py", line 525, in loads return _default_decoder.decode(s) File "/usr/local/lib/python3.8/site-packages/simplejson-3.17.2-py3.8-linux-x86_64.egg/simplejson/decoder.py", line 373, in decode raise JSONDecodeError("Extra data", s, end, len(s)) simplejson.errors.JSONDecodeError: Extra data: line 1 column 4 - line 1 column 78 (char 3 - 77) ""2021-01-17 16:20:07" - ERROR - [json_mqtt_uplink_converter.py] - json_mqtt_uplink_converter - 77 - Error in converter, for config: {"type": "json", "deviceNameJsonExpression": "${deviceName}", "deviceTypeJsonExpression": "${deviceType}", "timeout": 60000, "attributes": [], "timeseries": [{"type": "double", "key": "temperature", "value": "${temp}"}, {"type": "double", "key": "humidity", "value": "${hum}"}]} and message: "{"deviceName": "SN-001", "deviceType": "Thermometer", "temp": 42, "hum": 58} " ""2021-01-17 16:20:07" - ERROR - [json_mqtt_uplink_converter.py] - json_mqtt_uplink_converter - 78 - Extra data: line 1 column 4 - line 1 column 78 (char 3 - 77)" Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/thingsboard_gateway-2.5.5.2-py3.8.egg/thingsboard_gateway/connectors/mqtt/json_mqtt_uplink_converter.py", line 62, in convert value = TBUtility.get_value(datatype_config["value"], data, datatype_config["type"], expression_instead_none=True) File "/usr/local/lib/python3.8/site-packages/thingsboard_gateway-2.5.5.2-py3.8.egg/thingsboard_gateway/tb_utility/tb_utility.py", line 124, in get_value body = loads(body) File "/usr/local/lib/python3.8/site-packages/simplejson-3.17.2-py3.8-linux-x86_64.egg/simplejson/init.py", line 525, in loads return _default_decoder.decode(s) File "/usr/local/lib/python3.8/site-packages/simplejson-3.17.2-py3.8-linux-x86_64.egg/simplejson/decoder.py", line 373, in decode raise JSONDecodeError("Extra data", s, end, len(s)) simplejson.errors.JSONDecodeError: Extra data: line 1 column 4 - line 1 column 78 (char 3 - 77) ""2021-01-17 16:20:07" - ERROR - [tb_utility.py] - tb_utility - 63 - deviceName is empty in data: {"deviceName": null, "deviceType": null, "attributes": [], "telemetry": []}" ""2021-01-17 16:20:07" - ERROR - [tb_gateway_service.py] - tb_gateway_service - 322 - Data from MQTT Broker Connector connector is invalid."

Here is my MQTT config file mqtt.txt

imbeacon commented 3 years ago

Hi @jsperatan ,

Thank you for your interest in ThingsBoard IoT gateway. According to your logs, you sent a wrong json:

ERROR - [json_mqtt_uplink_converter.py] - json_mqtt_uplink_converter - 78 - Extra data: line 1 column 4 - line 1 column 78 (char 3 - 77)"

Probably there is a line separator in the message, so the gateway cannot parse this json.