Search code examples
mqttesp8266esp32thingsboard

Thingsboard, Posting Data to Two Seperate Devices From One Physical Node(ESP8266/32)


I want to post data to 2 different devices from same esp32. And I want to do it like posting all the data to one device and sharing its telemetries with the second device. Is that possible on thingsboard?

I achieved this via ESP32 but when I am posting data with two different token, I need to cut the wifi and reconnect the Thingsboard with the other devices token. This situation contributes to enormous battery consumption. When I examine the thingsboard library I could not see a function about cutting the network only with thingsboard. What can be done to overcome this situation?

Any idea will be appreciated. Thanks


Solution

  • There are an easy (with thingsboard rulechain) and hard (with esp32 firmware) way to do it, let's start with hard way first:

    You can make multiple mqtt clients in your esp32 firmware, just make sure that each client have different client id. In this case you have to manage multiple mqtt clients simultaneously, I have worked on projects that use several mqtt clients connected to different brokers simultaneously, in your case the broker is the same, but I don't think there are problems having different clients connected to same broker.

    Let's see now with the easy way:

    For example you have 2 devices in your thingsboard "Master" and "Slave", Edit your master device's relation: enter image description here

    Now go to your rulechain (the one that is receiving your device data), what we want to do here is save same data to "Slave" when you are saving data for "Master", for that we need 3 new nodes, Switch (to filter your master device), change originator (to switch to your slave device) and finally save data: enter image description here

    You can use deviceName or other fields to swich: enter image description here

    Use direction "FROM" and contains "DEVICE": enter image description here

    Finally just use same node (save timeseries) to save your data, you can do the same for attributes.