I have MQTT topics looking like this:
ABC123DE/devices/sensor1/controls/temperature
where
sensor1
is device name, andtemperature
is device type
I want them both to be passed in TB.
My mqtt.json
:
...
"mapping": [
{
"topicFilter": "+/devices/+/controls/+",
"converter": {
"type": "custom",
"deviceNameTopicExpression": "(?<=/controls/)(.*?)(?=$)",
"deviceTypeTopicExpression": "(?<=devices\/)(.*?)(?=\/controls)",
"extension": "TestMqttConverter",
"extension-config": {}
}
}
],
...
My test_mqtt_uplink_converter.py
:
...
class TestMqttConverter(MqttUplinkConverter):
def __init__(self, config):
self.__config = config.get('converter')
self.dict_result = {}
def convert(self, topic, body):
try:
self.dict_result["telemetry"] = [{"test": "123"}]
return self.dict_result
except Exception as e:
log.exception('Error in converter')
log.exception(e)
When I publish:
mosquitto_pub -t ABC123DE/devices/sensor1/controls/temperatire -m 100
I receive this error:
''2020-07-01 13:38:03' - ERROR - tb_utility - 62 - deviceName is empty in data: {"telemetry": [{"test": "123"}]}'
''2020-07-01 13:38:03' - ERROR - tb_gateway_service - 263 - Data from MQTT Broker Connector connector is invalid.'
''2020-07-01 13:38:03' - INFO - mqtt_connector - 343 - Successfully converted message from topic ABC123DE/devices/sensor1/controls/temperatire'
What else should I do to make it work?
Where are these values processed?
I've checked my expressions with https://pythex.org/