Cheers,
I have a data collection project with Sentilo and I need to be able to take several text inputs and send them all with a single button to a function to build a Sentilo query.
I've been trying various things but I just can't get what I need. See if you can lend me a hand and guide me a little bit in this problem that I am having.
I leave here screenshots of my dashboard, the flow with the nodes ...
Dashboard:
Flow:
[{"id":"f6e3a8fb.4368c8","type":"ui_button","z":"8a8b41a.6576c4","name":"","group":"dd4eca9a.1673b8","order":4,"width":0,"height":0,"passthru":false,"label":"Al grafana","tooltip":"","color":"","bgcolor":"","icon":"","payload":"textInput","payloadType":"flow","topic":"","x":370,"y":700,"wires":[["329bf415.0eff4c","53d12c6f.a120ec"]]},{"id":"a80d0d6a.1d327","type":"ui_text_input","z":"8a8b41a.6576c4","name":"Sensor","label":"Sensor","tooltip":"","group":"dd4eca9a.1673b8","order":1,"width":0,"height":0,"passthru":true,"mode":"text","delay":"100","topic":"sensor","x":280,"y":580,"wires":[["7dd7b550.d66454"]]},{"id":"329bf415.0eff4c","type":"function","z":"8a8b41a.6576c4","name":"Peticion sentilo","func":"context.data = context.data || {};\nvar ff = \"\";\n\nswitch(msg.topic){\n case \"sensor\":\n ff = msg.payload;\n msg = null;\n break;\n case \"url\":\n context.data.task2 = msg.payload;\n msg = null;\n break;\n case \"token\":\n context.data.task3 = msg.payload;\n msg = null;\n break; \n \n}\nvar f1 = \"curl -X GET -H \\\"IDENTITY_KEY:\" + ff;\nmsg.payload = f1;\n\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":660,"wires":[["e50ce2ec.cccbd","c3fcb7ca.30e718"]]},{"id":"b3a62f8b.48097","type":"link out","z":"8a8b41a.6576c4","name":"","links":["559eda82.d37c44"],"x":775,"y":560,"wires":[]},{"id":"d57b1932.c5614","type":"link in","z":"8a8b41a.6576c4","name":"","links":["ff7440af.242768"],"x":235,"y":680,"wires":[["f6e3a8fb.4368c8"]]},{"id":"e50ce2ec.cccbd","type":"exec","z":"8a8b41a.6576c4","command":"","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":810,"y":680,"wires":[["3808e00f.30cef","c3fcb7ca.30e718"],[],[]]},{"id":"c7de57dd.a199d8","type":"function","z":"8a8b41a.6576c4","name":"Seleccio dintre l'array","func":"msg.payload = msg.payload.observations\nreturn msg;","outputs":1,"noerr":0,"x":1160,"y":700,"wires":[["71691874.8f0788"]]},{"id":"71691874.8f0788","type":"function","z":"8a8b41a.6576c4","name":"Introducció dades InfluxDB","func":"//var a = [\"a\", \"b\", \"c\"];\n\n\na = msg.payload;\nvar f = [];\n//var t = [];\n// var ttt = [];\n/*\nfunction myFunction(item) {\n f.push(Number(item.value));\n} \n*/\n\n/*\nfor (var i = 0; i < a.length; i++){\n \n // var data;\n // var time = RED.util.cloneMessage(msg);\n// var value = RED.util.cloneMessage(msg);\n \n time.payload = a[i].time;\n value.payload = parseFloat(a[i].value);\n var time = parseFloat(a[i].value);\n var value = a[i].timestamp;\n \n new_msg.payload = parseFloat(a[i].value);\n new_msg2.payload = a[i].time;\n \n msg.payload = { \"time\" : new_msg2 , \"value\" : new_msg }\n \n f.push(msg);\n\n // ttt.push(...t, ...f);\n \n}\n*/\n\n\nfor(var i = 0; i<msg.payload.length; i++){\n if (msg.payload[i].time.toString().length <= 13 ){\n msg.payload[i].time = msg.payload[i].time * 1000000;\n }\n \n msg.payload[i]={\"time\":msg.payload[i].time,\"value\":parseFloat(msg.payload[i].value)};\n}\n\n\n\n/*\nvar json;\nvar t = [];\nfor(var i = 0; i<a.length; i++){\n /* if(i===0){\n json.payload = '{{\"time\": ' + msg.payload[i].time +', \"value\": ' + msg.payload[i].value + ' },';\n }else if(i===(msg.payload.length - 1)){\n json.payload = json.payload + '{\"time\": ' + msg.payload[i].time +', \"value\": ' + msg.payload[i].value + ' }';\n }else{\n json.payload = json.payload + ' {\"time\": ' + msg.payload[i].time +', \"value\": ' + msg.payload[i].value + ' },';\n }\n */\n \n\n // t.push(a[i].time);\n \n// }\n\n\n\n\n\n\n\n\n\n\n/*\na.forEach(function(entry) {\n f += entry.value[0] + \" \";\n});\n*/\n\n\nreturn msg;","outputs":1,"noerr":0,"x":1320,"y":760,"wires":[["9b7e2665.d5436"]]},{"id":"9b7e2665.d5436","type":"function","z":"8a8b41a.6576c4","name":"Sustracció de dades","func":"var i;\nvar ff = [];\n\nfor (i = 0; i < msg.payload.length; i++){\n var new_msg = RED.util.cloneMessage(msg);\n new_msg.payload = msg.payload[i];\n ff.push(new_msg);\n\n}\n\nreturn [ff];\n\n\n\n\n","outputs":1,"noerr":0,"x":1640,"y":700,"wires":[["71936e58.bee8a8"]]},{"id":"71936e58.bee8a8","type":"function","z":"8a8b41a.6576c4","name":"Formatting","func":"var data = {\n \"time\": msg.payload.time,\n \"value\": msg.payload.value\n}\nmsg.payload = data\nreturn msg","outputs":1,"noerr":0,"x":1810,"y":760,"wires":[["89087604.83ee28"]]},{"id":"89087604.83ee28","type":"influxdb out","z":"8a8b41a.6576c4","influxdb":"94d61e04.194d48","name":"","measurement":"pruebagrafica","precision":"","retentionPolicy":"","x":1770,"y":860,"wires":[]},{"id":"c3fcb7ca.30e718","type":"debug","z":"8a8b41a.6576c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":810,"y":800,"wires":[]},{"id":"3808e00f.30cef","type":"json","z":"8a8b41a.6576c4","name":"","property":"payload","action":"","pretty":true,"x":950,"y":720,"wires":[["c7de57dd.a199d8"]]},{"id":"8cbc8f1c.b7df28","type":"ui_text_input","z":"8a8b41a.6576c4","name":"Token","label":"Token","tooltip":"","group":"dd4eca9a.1673b8","order":2,"width":0,"height":0,"passthru":true,"mode":"password","delay":300,"topic":"token","x":270,"y":480,"wires":[["2f52e739.49a96"]]},{"id":"4db826a0.43218","type":"ui_text_input","z":"8a8b41a.6576c4","name":"url","label":"Url","tooltip":"","group":"dd4eca9a.1673b8","order":3,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"url","x":270,"y":540,"wires":[["b68d3fda.981538"]]},{"id":"ff7440af.242768","type":"link out","z":"8a8b41a.6576c4","name":"","links":["d57b1932.c5614"],"x":775,"y":460,"wires":[]},{"id":"8cad9d38.1c3f28","type":"link out","z":"8a8b41a.6576c4","name":"","links":["963e03a5.5dc2f8"],"x":775,"y":520,"wires":[]},{"id":"53d12c6f.a120ec","type":"debug","z":"8a8b41a.6576c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":540,"y":800,"wires":[]},{"id":"963e03a5.5dc2f8","type":"link in","z":"8a8b41a.6576c4","name":"","links":["8cad9d38.1c3f28"],"x":235,"y":720,"wires":[["f6e3a8fb.4368c8"]]},{"id":"559eda82.d37c44","type":"link in","z":"8a8b41a.6576c4","name":"","links":["b3a62f8b.48097"],"x":235,"y":760,"wires":[["f6e3a8fb.4368c8"]]},{"id":"b68d3fda.981538","type":"change","z":"8a8b41a.6576c4","name":"","rules":[{"t":"set","p":"textinput","pt":"flow","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":540,"wires":[["8cad9d38.1c3f28"]]},{"id":"2f52e739.49a96","type":"change","z":"8a8b41a.6576c4","name":"","rules":[{"t":"set","p":"textinput","pt":"flow","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":480,"wires":[["ff7440af.242768"]]},{"id":"7dd7b550.d66454","type":"change","z":"8a8b41a.6576c4","name":"","rules":[{"t":"set","p":"textinput","pt":"flow","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":580,"wires":[["b3a62f8b.48097"]]},{"id":"dd4eca9a.1673b8","type":"ui_group","z":"","name":"Sentilo","tab":"cb193cda.89a768","disp":true,"width":"6","collapse":false},{"id":"94d61e04.194d48","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"Mesures","name":"","usetls":false,"tls":""},{"id":"cb193cda.89a768","type":"ui_tab","z":"","name":"Principal","icon":"dashboard","disabled":false,"hidden":false}]
Query Sentilo example:
curl -X GET -H "IDENTITY_KEY: <YOUR_KEY>" http://<your sentilo url>/data/<your provider>/<your sensor>
Thank you.
A greeting.