Hi, i try to upload sensor data from NR to ThingsBoard via MQTT, but i can't connect.
I use mqtt node and use this set ups, but can't upload any data. Can someone help me?
Any help ?
Is there a reason why you have left the QoS field & the config Password field blank.
I'm not familiar with 'thingsboard' but I assume a password is a requirement?
I watch this video (how to send data to Thingsboard via Nodered MQTT - YouTube), and in it there is not used Pass, but still the data is upload. But what pass i should use, where to find it?
I try different QoS level, but no effect.
Have you read the Thingsboard guides about authentication? If you use the "Acces token" authentication you don't need to provide a password, only the token as username.
Following device credentials/flow should work:
[{"id":"d5239a92.af914","type":"mqtt out","z":"d139e5bb.4e2c78","name":"","topic":"v1/devices/me/telemetry","qos":"","retain":"","broker":"638dea7a.2939dc","x":530,"y":1220,"wires":[]},{"id":"f5bc04e5.96315","type":"inject","z":"d139e5bb.4e2c78","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":1220,"wires":[["418b93af.3eed5c"]]},{"id":"418b93af.3eed5c","type":"function","z":"d139e5bb.4e2c78","name":"","func":"ts = new Date().getTime();\n\nmsg.payload = \n{\n \"values\":{\n \"lol\": Math.sin(ts*2*3.141592/1000)*5*Math.sin(ts*2*3.141592*100),\n \"data1\": Math.random(),\n \"data2\": Math.random(),\n \"data3\": Math.random(),\n \"data4\": Math.random(),\n \"string\" : \"jajajajaeenlangestring\",\n \"bool\" : Math.random() > 0.5,\n \"bool2\": Math.random() > 0.5,\n },\n \"ts\": ts , \n};\n\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":1220,"wires":[["d5239a92.af914"]]},{"id":"638dea7a.2939dc","type":"mqtt-broker","z":"","name":"","broker":"demo.thingsboard.io","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
Yes, i read this and i use the token (you can see it in the photo) without pass (like in the photo). Yes i use the device credentials. I use my DHT sensors from which i wish to send data to things board.
Is the mqtt node connecting (green status led) or does is stays red?
Have you tried the flow I send you? You can use the credentials, I will throw them away later.
Edit: You just need to enter the token in the username field as it's not exported with the flow.
Your flow work, but main is not. Can you take a look and tell me what is the problem?
[{"id":"84e7c8e4.500eb8","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"96af2c4c.5e1a6","type":"debug","z":"84e7c8e4.500eb8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":350,"y":180,"wires":[]},{"id":"f8a1bdd5.d9ff3","type":"mqtt out","z":"84e7c8e4.500eb8","name":"","topic":"v1/devices/me/telemetry","qos":"0","retain":"false","broker":"5f1422e2.aad9ac","x":250,"y":220,"wires":[]},{"id":"5037cc7d.229de4","type":"inject","z":"84e7c8e4.500eb8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":80,"y":100,"wires":[["d760e7b4.4149d8"]]},{"id":"10611b72.de1be5","type":"function","z":"84e7c8e4.500eb8","name":"Temp","func":"msg.payload = msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":190,"y":100,"wires":[["22a3160e.78fd7a"]]},{"id":"17e708b0.4c1807","type":"function","z":"84e7c8e4.500eb8","name":"Humid","func":"msg.payload = msg.humidity;\nreturn msg;","outputs":1,"noerr":0,"x":190,"y":140,"wires":[["2fcfa267.e3d63e"]]},{"id":"ba17619.432a8a","type":"function","z":"84e7c8e4.500eb8","name":"MQTT","func":"\nvar fieldString = \"field1=\" + \n msg.payload.toString() +\n \"&field2=\" +\n msg.humidity.toString();\n\nvar newMsg = {\n payload:fieldString\n}\n\nreturn newMsg;","outputs":1,"noerr":0,"x":90,"y":180,"wires":[["96af2c4c.5e1a6","f8a1bdd5.d9ff3"]]},{"id":"2fcfa267.e3d63e","type":"ui_gauge","z":"84e7c8e4.500eb8","name":"humidity","group":"d2339c0f.0ff3e","order":4,"width":"5","height":"2","gtype":"gage","title":"Humidity","label":"%","format":"{{value}}","min":"-10","max":"100","colors":["#ffffff","#dedeed","#f30b27"],"seg1":"25","seg2":"50","x":340,"y":140,"wires":[]},{"id":"22a3160e.78fd7a","type":"ui_gauge","z":"84e7c8e4.500eb8","name":"","group":"88a5f774.23c158","order":2,"width":"5","height":"2","gtype":"gage","title":"Temp","label":"C","format":"{{value}}","min":"10","max":"50","colors":["#0ac9f7","#e4d010","#f51212"],"seg1":"20","seg2":"40","x":330,"y":100,"wires":[]},{"id":"d760e7b4.4149d8","type":"rpi-dht22","z":"84e7c8e4.500eb8","name":"DHT","topic":"rpi-dht22","dht":"11","pintype":"0","pin":"23","x":170,"y":20,"wires":[["10611b72.de1be5","17e708b0.4c1807","ba17619.432a8a"]]},{"id":"5f1422e2.aad9ac","type":"mqtt-broker","name":"","broker":"demo.thingsboard.io","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"d2339c0f.0ff3e","type":"ui_group","name":"Status","tab":"e1c3a48c.2de5b8","order":1,"disp":false,"width":"6","collapse":false},{"id":"88a5f774.23c158","type":"ui_group","name":"Indoor Climate and Outdoor Status","tab":"e1c3a48c.2de5b8","order":1,"disp":false,"width":"6","collapse":false},{"id":"e1c3a48c.2de5b8","type":"ui_tab","name":"ENV","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
I assume that the mqtt node is connecting correctly (green status led). Please give this information if you want to be helped better. You initial stated that you can't connect. But if the mqtt node is green, you are connected, but you are just sending the data in the wrong format.
From what I see in your flow, you are sending a string while you need an object as payload. See thingsboard mqtt-api.
This is what you are currently sending:
msg.payload = "field1=50&field2=23.2";
While you need one of these options:
msg.payload = {"field1":50, "field2":23.2};
msg.payload = [ {"field1":50} , {"field2":23.2} ];
msg.payload = {"ts":1451649600512, "values":{"field1":50, "field2":23.2} };
Have a look at the function node in my flow if you want an example on how to achieve this.
I also suggest you change your credentials after you get it working, else other people can spam data to your device. (Although I would suspect that demo.thingsboard.io automatically gets a reset.)
The connection is periodic (appear and disappear).
I'm very bad in programing, so i can't fully understand the code (and modify it). Is there option to add change or switch node, to get the DHT sensor data to the right format and to ThingsBoard ?
Bay the way, with your code i manage to upload some data.
I will change the credentials
The periodic connection is because there are two or more nodes trying to connect to the same device. This also counts for other people using your credentials to connect. I believe it's a restriction of Thingsboard and not mqtt, but I'm not sure about that.
You can use the change node like this:
Or with a function node:
msg.payload = {
"field1": msg.payload,
"field2": msg.humidity
}
return msg;
I suggest you start with understanding the basic mechanismes in node-red, like setting values, before you move on.
It worked!
I can't thank you enough for the help!
I keep trying to learn the basic mechanisms in node-red, but still don't fully understand everything.
With practice i will get better.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.