-1

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

raymurai
  • 1
  • 1
  • 2
    what has posting to thingsboard with two different tokens to do with WiFi connection? – Juraj Aug 04 '22 at 09:48
  • Let's assume that I am connected with a device with token1. If I wanted to connect another device with token2 I shut down the wifi to lose network with thingsboard. In thingsboard library could not find any function to close connection with thingsboard. So I solve this with shutting down the wifi. As I mentioned in the post, this causes unwanted battery consumption in my case. – raymurai Aug 04 '22 at 09:54
  • 2
    by 'device' you mean a device configuration in thingsboard? because normally device is some hardware. there is no reason to disconnect from network to do a different request. to a server – Juraj Aug 04 '22 at 11:49

3 Answers3

0

One way I could think of, would be using ThingsBoard Integrations. Where one input payload can have multiple outgoing payloads (works even for multiple target devices or assets): https://thingsboard.io/docs/user-guide/integrations/#converter-output

But this requires ThingsBoard PE & an external MQTT Broker in between your ESP32 & TB.

Or you could try the MQTT Gateway API: https://thingsboard.io/docs/reference/gateway-mqtt-api/

mdeuchert
  • 248
  • 2
  • 8
0

I had similar problem and recognized there is disconnect() method which works for me perfectly. Then I coded sendTBdata() function to send multiple device telemetry without cutting WiFi connection. (I used Arduino UNO with ESP8266 and included ThingsBoard.h library they provide.)

void sendTBdata (token, key, data) {    
  if (tb.connected()) tb.disconnect();
  tb.connect(THINGSBOARD_SERVER, token, THINGSBOARD_PORT);
  tb.sendTelemetryFloat(key, data);
}
0

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.

Sdaia
  • 122
  • 6