Skip to content

Instantly share code, notes, and snippets.

@gdziuba
Created January 26, 2024 21:14
Show Gist options
  • Save gdziuba/66f37bb739b6cdb0c7ad3a4e2edd68ef to your computer and use it in GitHub Desktop.
Save gdziuba/66f37bb739b6cdb0c7ad3a4e2edd68ef to your computer and use it in GitHub Desktop.
Sample flow for sending data to InfluxDB using balena and FlowFuse

This simple set of flows will help you get started when you want to integrate your Node-RED instance with InfluxDB deployed on a device running balena and deployed with FlowFuse.

[{"id":"f16d9612ce35dd9b","type":"group","z":"925a6cec9304970f","name":"Test Data Insert","style":{"label":true},"nodes":["e979340cbc21e8f1","1d4eb90b13bcdb51","1f1a5f78c2786fa8"],"x":74,"y":219,"w":612,"h":82},{"id":"e979340cbc21e8f1","type":"influxdb out","z":"925a6cec9304970f","g":"f16d9612ce35dd9b","influxdb":"2dae11cc17ca8f62","name":"","measurement":"truck","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":580,"y":260,"wires":[]},{"id":"1d4eb90b13bcdb51","type":"inject","z":"925a6cec9304970f","g":"f16d9612ce35dd9b","name":"","props":[{"p":"timestamp","v":"","vt":"date"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":260,"wires":[["1f1a5f78c2786fa8"]]},{"id":"1f1a5f78c2786fa8","type":"template","z":"925a6cec9304970f","g":"f16d9612ce35dd9b","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"[\n {\n \"time\": 1688987984,\n \"temperature\": 24\n },\n {\n \"device\": \"dQBgXeWLRE\",\n \"deviceType\": \"Pi4\",\n \"deviceName\": \"demo-pi-rob\"\n }\n]","output":"json","x":380,"y":260,"wires":[["e979340cbc21e8f1"]]},{"id":"2dae11cc17ca8f62","type":"influxdb","hostname":"localhost","port":"8086","protocol":"http","database":"mydb","name":"Test","usetls":false,"tls":"","influxdbVersion":"1.x","url":"http://localhost:8086","timeout":"10","rejectUnauthorized":true},{"id":"176c8d11b62a6b8f","type":"group","z":"925a6cec9304970f","name":"Initial Database Creation. Should happen on startup","style":{"label":true},"nodes":["cd8aff5caa0894a5","a3cdabdbe05f5285","431d7bb6e5ab0b88"],"x":74,"y":319,"w":652,"h":82},{"id":"cd8aff5caa0894a5","type":"influxdb in","z":"925a6cec9304970f","g":"176c8d11b62a6b8f","influxdb":"2baafc75547ced92","name":"Initial database creation","query":"CREATE DATABASE mydb\n","rawOutput":false,"precision":"","retentionPolicy":"","org":"organisation","x":390,"y":360,"wires":[["431d7bb6e5ab0b88"]]},{"id":"a3cdabdbe05f5285","type":"inject","z":"925a6cec9304970f","g":"176c8d11b62a6b8f","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":360,"wires":[["cd8aff5caa0894a5"]]},{"id":"431d7bb6e5ab0b88","type":"debug","z":"925a6cec9304970f","g":"176c8d11b62a6b8f","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":360,"wires":[]},{"id":"2baafc75547ced92","type":"influxdb","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"mydb","name":"Local","usetls":false,"tls":"","influxdbVersion":"1.x","url":"http://localhost:8086","timeout":"10","rejectUnauthorized":true},{"id":"2ffb74012b0f72f3","type":"group","z":"925a6cec9304970f","name":"Read from Database","style":{"label":true},"nodes":["d7bc28e5bb14ab52","5cd1e2c3d9c32f52","ef63ccc3a2edd110"],"x":74,"y":419,"w":532,"h":82},{"id":"d7bc28e5bb14ab52","type":"influxdb in","z":"925a6cec9304970f","g":"2ffb74012b0f72f3","influxdb":"2baafc75547ced92","name":"Read","query":"SELECT * FROM \"truck\"\n","rawOutput":false,"precision":"","retentionPolicy":"","org":"organisation","x":330,"y":460,"wires":[["ef63ccc3a2edd110"]]},{"id":"5cd1e2c3d9c32f52","type":"inject","z":"925a6cec9304970f","g":"2ffb74012b0f72f3","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":460,"wires":[["d7bc28e5bb14ab52"]]},{"id":"ef63ccc3a2edd110","type":"debug","z":"925a6cec9304970f","g":"2ffb74012b0f72f3","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":500,"y":460,"wires":[]},{"id":"f68f8fa49117beee","type":"group","z":"925a6cec9304970f","name":"Data Generation","style":{"label":true},"nodes":["94f484a713181156","8a0d222974736218","dacec682fb34f5d3","b34ddb4b14e0e824","7af451d29c8a1288","a8506e3dce57a8fa","6c644a173c583d6b","4bf3d54dca2e213e","7373d04f07cfa646"],"x":74,"y":59,"w":1372,"h":142},{"id":"94f484a713181156","type":"inject","z":"925a6cec9304970f","g":"f68f8fa49117beee","name":"","props":[{"p":"timestamp","v":"","vt":"date"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":160,"wires":[["8a0d222974736218"]]},{"id":"8a0d222974736218","type":"data-generator","z":"925a6cec9304970f","g":"f68f8fa49117beee","name":"","field":"store","fieldType":"msg","syntax":"json","template":"{\n \"lat\": \"{{lat}}\",\n \"long\": \"{{long}}\",\n \"speed\": \"{{float 55 75}}\",\n \"distanceLeftOnGas\": \"{{int 1 500}}\",\n \"country\": \"{{country}}\"\n}","x":320,"y":160,"wires":[["b34ddb4b14e0e824"]]},{"id":"dacec682fb34f5d3","type":"debug","z":"925a6cec9304970f","g":"f68f8fa49117beee","name":"debug 2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1340,"y":100,"wires":[]},{"id":"b34ddb4b14e0e824","type":"Uptime","z":"925a6cec9304970f","g":"f68f8fa49117beee","name":"","x":500,"y":160,"wires":[["a8506e3dce57a8fa"]]},{"id":"7af451d29c8a1288","type":"Memory","z":"925a6cec9304970f","g":"f68f8fa49117beee","name":"","scale":"Byte","x":860,"y":160,"wires":[["6c644a173c583d6b"]]},{"id":"a8506e3dce57a8fa","type":"change","z":"925a6cec9304970f","g":"f68f8fa49117beee","name":"","rules":[{"t":"set","p":"store.uptime","pt":"msg","to":"payload.uptime","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":160,"wires":[["7af451d29c8a1288"]]},{"id":"6c644a173c583d6b","type":"change","z":"925a6cec9304970f","g":"f68f8fa49117beee","name":"","rules":[{"t":"set","p":"store.totalmem","pt":"msg","to":"payload.totalmem","tot":"msg"},{"t":"set","p":"store.freemem","pt":"msg","to":"payload.freemem","tot":"msg"},{"t":"set","p":"store.memusage","pt":"msg","to":"payload.memusage","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"store","tot":"msg","dc":true},{"t":"set","p":"topic","pt":"msg","to":"'trucks/' & $env('FF_INSTANCE_ID')","tot":"jsonata"},{"t":"set","p":"payload.deviceID","pt":"msg","to":"$env('FF_DEVICE_ID')","tot":"jsonata"},{"t":"set","p":"payload.deviceName","pt":"msg","to":"$env('FF_DEVICE_NAME')","tot":"jsonata"},{"t":"set","p":"payload.deviceType","pt":"msg","to":"$env('FF_DEVICE_TYPE')","tot":"jsonata"},{"t":"set","p":"payload.snapShotId","pt":"msg","to":"$env('FF_SNAPSHOT_ID')","tot":"jsonata"},{"t":"set","p":"payload.snapShotName","pt":"msg","to":"$env('FF_SNAPSHOT_NAME')","tot":"jsonata"},{"t":"set","p":"payload.timestamp","pt":"msg","to":"timestamp","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1020,"y":160,"wires":[["4bf3d54dca2e213e"]]},{"id":"4bf3d54dca2e213e","type":"template","z":"925a6cec9304970f","g":"f68f8fa49117beee","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"[\n {\n \"measurement\": \"truck\",\n \"fields\": {\n \"speed\": {{payload.speed}},\n \"distanceOnGas\": {{payload.distanceLeftOnGas}},\n \"uptime\": {{payload.uptime}},\n \"memUsage\": {{payload.memusage}},\n \"lat\": {{payload.lat}},\n \"long\": {{payload.long}}\n },\n \"tags\":{\n \"location\":\"{{payload.country}}\",\n \"deviceId\": \"{{payload.deviceID}}\",\n \"deviceName\": \"{{payload.deviceName}}\",\n \"deviceType\": \"{{payload.deviceType}}\",\n \"snapShotID\": \"{{payload.snapShotId}}\",\n \"snapShotName\": \"{{payload.snapShotName}}\"\n },\n \"timestamp\": {{payload.timestamp}}\n }\n]\n","output":"json","x":1180,"y":160,"wires":[["dacec682fb34f5d3","7373d04f07cfa646"]]},{"id":"7373d04f07cfa646","type":"influxdb batch","z":"925a6cec9304970f","g":"f68f8fa49117beee","influxdb":"2baafc75547ced92","precision":"","retentionPolicy":"","name":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":1350,"y":160,"wires":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment