Search code examples
mqttthingsboardtelemetry

Thingsboard MQTT subscribe to multiple topics? Is this possible


Hi I have installed TB CE onto my Linux test server. Am really happy with it so far. But I have run into an issue. Which is probably due to me not understanding some concept properly! I have two ESP32 physical sensors that are publishing to their own local broker. Each device publishes to its own topic. The broker is running on a RUT956 device and I have created a bridge that forwards the two topics to TB CE. The bridge connects to TB CE using a CID, username and password. I have tried to create two device profiles - one for each topic. This all works fine. The problem arises when I try to create two devices, the first one works fine, I use the credentials for the RUT956 bridge, I can get the telemetry from the topic. The problem is when I try create the second device, I can't as the CID is the same as the previous one.

The problem I have run into is that I want to monitor two topics that are forwarded to TB by the one device (i.e. in this case the bridge).

Any help at all would be appreciated! Phil

Created two devices using two profiles to receive telemetry from a single bridge. The telemetry is in two different topics


Solution

  • There is a special MQTT Gateway API for the purpose of data exchange of multiple devices with a single MQTT connection: https://thingsboard.io/docs/reference/gateway-mqtt-api/

    With this API it's also possible to create new devices automatically in ThingsBoard once data of a new device arrives the first time.

    All you have to do is create a "Gateway" Device in ThingsBoard and use the credentials of this device for the MQTT connection. Then adjust the message payload to include the name of the devices (as identifier)