Closed mircopz closed 2 years ago
Hi @mircopz, pls, send your config file and if you are using a custom converter, send it too. Also, I see that there are 4 messages which successful converted and 5 is unsuccessful. Are you sure that you send the correct data to the Gateway?
Thanks for your interest in ThingsBoard IoT Gateway!
Hi @samson0v
Data sent to the gateway is the first 4-elements array reported in my first message. I think the unsuccessful data validation is related to my 4 message, the log is right after data conversion. For further information, on thingsboard I received only 2 and 3 message, missing the 1 and 4.
This is my MQTT config file:
{
"broker": {
"name": "MQTT Broker",
"host": "**********",
"port": 1883,
"clientId": "TB_gateway",
"maxMessageNumberPerWorker": 10,
"maxNumberOfWorkers": 100,
"security": {
"type": "basic",
"username": "*****",
"password": "*****"
}
},
"mapping": [
{
"topicFilter": "device/+/attributes",
"converter": {
"type": "custom",
"extension": "MyMqttUplinkConverter",
"extension-config": {
}
}
},
{
"topicFilter": "device/+/telemetry",
"converter": {
"type": "custom",
"extension": "MyMqttUplinkConverter",
"extension-config": {
}
}
}
],
"connectRequests": [
{
"topicFilter": "device/+/connect",
"deviceNameTopicExpression": "(?<=device\/)(.*?)(?=\/connect)",
"deviceTypeJsonExpression": "${deviceType}"
}
],
"disconnectRequests": [
{
"topicFilter": "device/+/disconnect",
"deviceNameTopicExpression": "(?<=device\/)(.*?)(?=\/disconnect)"
}
]
}
and that is MyMqttUplinkConverter function
from thingsboard_gateway.connectors.converter import Converter, log
import re
class MyMqttUplinkConverter(Converter):
def __init__(self, config):
self.__config = config
self.result_dict = {
"deviceType": config.get("deviceType", "MY-DEVICE"),
"attributes": [],
"telemetry": []
}
def convert(self, topic, data):
self.result_dict["attributes"] = []
self.result_dict["telemetry"] = []
deviceName = re.search("(?<=airy\/)(.*?)(?=\/)", topic).group()
deviceName = deviceName[:14] + "/" + deviceName[15:]
deviceName = self.result_dict["deviceType"] + "_" + deviceName[12:]
msgType = re.search("([^\/]+$)", topic).group()
self.result_dict["deviceName"] = deviceName
self.result_dict[msgType] = []
self.result_dict[msgType].append(data)
log.debug("Converted data: %s", self.result_dict)
return self.result_dict
@mircopz We tested your converter and not be able to reproduce your problem
@samson0v thank you anyway, I haven't been able to reproduce it either
Describe the bug My device sent the following array of telemetry
It is processed by my custom function, and the final message (before validation) has always the following format:
As you can see from logs, the first three elements are correctly processed, while the fourth cannot be validated, even if it has the same format but function
validate_converted_data
received an empty array. Is it a problem of a multiple telemetry message received? I've not been able to reproduce it anymore.Connector name (If bug in the some connector): MQTT Connector
Error traceback (If available):
Versions (please complete the following information):