Thingsboard Intergration - Basic Node-Red Flow

This is just a basic integration for the moment. This does not include any outbound RPC commands yet. I am still figuring that out.

A lot of the work we do, our customers are asking for a central dashboard. This is just one of many ways to get started. I am using Node-Red as a gateway to Thingsboard. This does not need the PE version, it works well in the Community Version.

[{"id":"1861182e.5ccf28","type":"inject","z":"f10784d0.015068","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1100,"y":100,"wires":[["3f07c87f.569638"]]},{"id":"3f07c87f.569638","type":"groov-read-ds","z":"f10784d0.015068","dataStore":"f216f435.690668","tagName":"58","tableStartIndex":"","tableLength":"","value":"","valueType":"msg.payload","topic":"","topicType":"none","name":"","x":1270,"y":100,"wires":[["6a6c2daa.930a94"]]},{"id":"6a6c2daa.930a94","type":"function","z":"f10784d0.015068","name":"ThingsBoard JSON Convertor","func":"var data = msg.payload;\n\n\n    data = msg.payload;\n    msg.topic = \"v1/gateway/telemetry\";\n    //Ranger1 is the Device in thingsboard you want to send your telemetry  data\n    //Device can be already created or it will dynamiclly create a device.    \n    \n    msg.payload =  {\"Ranger1\":[{\"a1\":data}]};\n\n\nreturn msg;","outputs":1,"noerr":0,"x":1550,"y":100,"wires":[["fa550721.5aef68","272a610f.1ddb2e"]]},{"id":"fa550721.5aef68","type":"mqtt out","z":"f10784d0.015068","name":"","topic":"","qos":"","retain":"","broker":"c3294db9.0eddf","x":1810,"y":100,"wires":[]},{"id":"272a610f.1ddb2e","type":"debug","z":"f10784d0.015068","name":"SendMQTT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1830,"y":60,"wires":[]},{"id":"f216f435.690668","type":"groov-data-store","z":"","project":"f7cad6e5.05f6f8","dsName":"sfr"},{"id":"c3294db9.0eddf","type":"mqtt-broker","z":"","name":"TBGateway","broker":"159.203.8.160","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"f7cad6e5.05f6f8","type":"groov-project","z":"","address":"localhost"}]

If there is any real interest, I will publish a guide on howto do this. Some screenshots below:

Node-Red Flow

Latest Telemetry in Thingsboard

Basic Dashboard

**If you want help, feel free to contact me

Best Regards,
Dan

I know you have used both, how does ThingsBoard compare to groov View?

I know we have many customers with a central groov View (usually a Windows server on a rack in an IT department) for their clients/users to connect to…

Hi Ben,
I would say for 95% of the use cases out there, Groov view on a central server is the easiest way.

Groov view is definitely way easier to build an HMI and deal with controlling devices. But when you need to be able to add devices on the fly or easily assign a dashboard with a variable amount of devices/sensors, Thingsboard is better equipped for that scenario.

I have 2 customers in Oil/Gas that need to be able to move devices to a customers list and dashboard. I know this can be accomplished with Groov, but the people who are managing this don’t have the time/patience to copy/paste different devices & setup the pages. With thingsboard this is easier to manage.

In our case, the clients use groov view to run and control their pumps/devices, and we use thingsboard to provide an external dynamic read only dashboard for their clients.

1 Like

Hello Sir, we facing in challenges to connect to thingsboard over mqtt using nodered…please guide us … How can we do if you share one video regarding same that would be great…

Welcome to the forums.

What have you tried?
What Opto 22 product are you using?
What does your debug node show?
Did you download, import and test the flow from the first post in this thread?

We would like to try and help, but need some more information.

Hi,
do you know a way how I can replace “Ranger 1” into to “msg.topic” of the injection?
So that the created device in thingsboard get the name of the timestamp?
br Mirko

It will be a two step process I suspect.
First make your timestamp, then put it in the function block code.

Try something like this (I have not tested since I don’t have Thingsboard access).

//desired UTC format. hh:mm:ssZ dd-mm-yyyy, ex: `15:38:44Z 20-12-2020`
// twoDig helper function to give leading zeros on single-digit values:
function twoDig(val) {return (('0'+val).slice(-2));}
var d = new Date();
msg.utcdts = twoDig(d.getUTCHours())+':'+twoDig(d.getUTCMinutes())+':'+twoDig(d.getUTCSeconds())+'Z ' +
    twoDig(d.getUTCDate())+'-'+twoDig((d.getUTCMonth()+1))+'-'+d.getUTCFullYear();

var data = msg.payload;


    data = msg.payload;
    msg.topic = "v1/gateway/telemetry";
    //Ranger1 is the Device in thingsboard you want to send your telemetry  data
    //Device can be already created or it will dynamiclly create a device.    
    
    msg.payload =  {msg.utcdts:[{"a1":data}]};


return msg;

1 Like

Thanks for the quick reply. I think that was a small misunderstanding. I want in the funtion-node where the name “Ranger1” is, the name of the node before.

br

Again, untested as I don’t have access to a Thingsboard.
But, I did test it on my EPIC and it does not throw an error… may or may not work for you.
‘Name 1:2’ has an example payload just so I could test everything end to end.

[{"id":"1861182e.5ccf28","type":"inject","z":"4118d274.45b1fc","name":"timestamp","props":[{"p":"name","v":"$now()","vt":"jsonata"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":620,"y":320,"wires":[["6a6c2daa.930a94"]]},{"id":"6a6c2daa.930a94","type":"function","z":"4118d274.45b1fc","name":"ThingsBoard JSON Convertor","func":"var data = msg.payload;\nvar tname = msg.name;\n\n\n    data = msg.payload;\n    msg.topic = \"v1/gateway/telemetry\";\n    //Ranger1 is the Device in thingsboard you want to send your telemetry  data\n    //Device can be already created or it will dynamiclly create a device.    \n    \n    msg.payload =  {tname:[{\"a1\":data}]};\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":910,"y":380,"wires":[["272a610f.1ddb2e"]]},{"id":"272a610f.1ddb2e","type":"debug","z":"4118d274.45b1fc","name":"SendMQTT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1190,"y":340,"wires":[]},{"id":"7022f7ac.2dfd","type":"inject","z":"4118d274.45b1fc","name":"Name 1:2","props":[{"p":"name","v":"name 1:2","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Hello World","payloadType":"str","x":620,"y":380,"wires":[["6a6c2daa.930a94"]]},{"id":"de2bf771.e4454","type":"inject","z":"4118d274.45b1fc","name":"Name 1:4","props":[{"p":"name","v":"name 1:4","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":620,"y":440,"wires":[["6a6c2daa.930a94"]]}]
1 Like

Hi, now I thingsboard created the device “name”. To node red don’t change the name correctly.
Attached you can see me logs. The first one from you and the last on with the old one “Ranger”. I think where “name” is must stand the “msg.name” Do you habe any Idea?

Thanks for the screenshot, it helps to see what you need.

Ok, third time lucky?

Try this…
First the screen shot to show the name is now part of the payload.
First a time stamp, and then a fixed thing name.

And here is the flow.

[{"id":"1861182e.5ccf28","type":"inject","z":"4118d274.45b1fc","name":"timestamp","props":[{"p":"name","v":"$now()","vt":"jsonata"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":620,"y":320,"wires":[["6a6c2daa.930a94"]]},{"id":"6a6c2daa.930a94","type":"function","z":"4118d274.45b1fc","name":"ThingsBoard JSON Convertor","func":"var data = msg.payload;\n\n    data = msg.payload;\n    msg.topic = \"v1/gateway/telemetry\";\n    //Ranger1 is the Device in thingsboard you want to send your telemetry  data\n    //Device can be already created or it will dynamiclly create a device.    \n    \n    msg.payload =  {[msg.name]:[{\"a1\":data}]};\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":910,"y":380,"wires":[["272a610f.1ddb2e"]]},{"id":"272a610f.1ddb2e","type":"debug","z":"4118d274.45b1fc","name":"SendMQTT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1190,"y":340,"wires":[]},{"id":"7022f7ac.2dfd","type":"inject","z":"4118d274.45b1fc","name":"Name 1:2","props":[{"p":"name","v":"name 1:2","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Hello World","payloadType":"str","x":620,"y":380,"wires":[["6a6c2daa.930a94"]]},{"id":"de2bf771.e4454","type":"inject","z":"4118d274.45b1fc","name":"Name 1:4","props":[{"p":"name","v":"name 1:4","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":620,"y":440,"wires":[["6a6c2daa.930a94"]]}]

Please let us know if this finally works for you.

1 Like