CO2 History File Browser

CO2-Browser Flow:

GUI:

See http://blog.wenzlaff.de/?p=15430

[{"id":"b1b75497.a979a8","type":"tab","label":"History Browser","disabled":false,"info":""},{"id":"125619d1.c0fa4e","type":"group","z":"b1b75497.a979a8","name":"","style":{"fill":"#e3f3d3","label":true},"nodes":["e009e08a.487648","34b3eeda.b20502","956f27cf.e605a8","c6e89da7.c766e8","d94d7129.0b514"],"x":34,"y":539,"w":1012,"h":82},{"id":"4c1e7f93.0d14a8","type":"group","z":"b1b75497.a979a8","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["7a5c9ad4.dfa78c","e21faf7f.a00908","7c53b6d4.2ab54","eabf420f.1be678","7595a620.d7a3c8"],"x":34,"y":119,"w":172,"h":242},{"id":"b3b06e0a.0b2088","type":"group","z":"b1b75497.a979a8","name":"","style":{"label":true,"color":"#000000","fill":"#ffbfbf"},"nodes":["60f0508c.618a58","506dd40c.705c4c","25242708.318c2","49fcd691.c0d9a","1a5bc125.122db7","866568c4.55361"],"x":34,"y":439,"w":1012,"h":82},{"id":"c054ed48.ca24e","type":"group","z":"b1b75497.a979a8","name":"","style":{"fill":"#bfdbef","label":true},"nodes":["cd6a932d.015208","333f28f3.fc738","b24a5eef.1429c","adfa0d99.c7b57","17b507de.c7f3d8"],"x":494,"y":219,"w":752,"h":142},{"id":"c151a9f4.a134a8","type":"group","z":"b1b75497.a979a8","name":"","style":{"fill":"#ffffbf","label":true},"nodes":["acdcd1ef.c5d6d8","86ace8a1.dccee8","f10a0f15.7ab608","bc4f62d5.8fe8a8","845236bb.3006d","32282c2b.fd6f0c"],"x":34,"y":639,"w":1012,"h":82},{"id":"e7ab9317.044c3","type":"group","z":"b1b75497.a979a8","name":"","style":{"fill":"#bfbfbf","label":true},"nodes":["bed6f55c.70e99","d70a6028.665f28","c5b21a26.849748","d8df9471.b5d4c8","182da13.eb7735f","e890e960.b88ad","6ca7019c.dfbc"],"x":494,"y":39,"w":752,"h":142},{"id":"de2a4a70.8a65c8","type":"comment","z":"b1b75497.a979a8","name":"CO2 History File Browser","info":"1) Update the default folder in the Init node\n2) Update the default folder in the Reset node as well\n3) You can duplicate the Reset nodes and use them as saved shortcuts\n4) Check the Convert Timestamps function node if you want to see your dates in a different format. I just used the Javascript toISOString format.\n5) The Graph button can read any CSV file which have any number of values, but the first column always contains a timestamp column with javascript timestamp of the data point.","x":150,"y":40,"wires":[]},{"id":"373188f3.0b289","type":"inject","z":"b1b75497.a979a8","name":"Init","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"change","payload":"/data/co2data","payloadType":"str","x":110,"y":80,"wires":[["b78577b6.70c94"]]},{"id":"7a5c9ad4.dfa78c","type":"ui_button","z":"b1b75497.a979a8","g":"4c1e7f93.0d14a8","name":"","group":"5345d7a1.deddd8","order":1,"width":"2","height":"1","passthru":false,"label":"Refresh","tooltip":"","color":"","bgcolor":"","icon":"refresh","payload":"","payloadType":"str","topic":"refresh","topicType":"str","x":120,"y":160,"wires":[["b78577b6.70c94"]]},{"id":"bed6f55c.70e99","type":"ui_dropdown","z":"b1b75497.a979a8","g":"e7ab9317.044c3","name":"File Selector","label":"","tooltip":"","place":"Select a file","group":"5345d7a1.deddd8","order":9,"width":"5","height":"1","passthru":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":950,"y":80,"wires":[["e890e960.b88ad"]]},{"id":"d70a6028.665f28","type":"function","z":"b1b75497.a979a8","g":"e7ab9317.044c3","name":"Format data","func":"// format the data for the dropdown\nmsg.options = [];\nfor (var i=0; i<msg.payload.length; i++) {\n    // This is a file\n    obj = {};\n    obj [msg.payload[i].name.replace(/^.*(\\\\|\\/|\\:)/, '')]=msg.payload[i].name;\n msg.options.push(obj);\n}\nmsg.payload={};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":750,"y":80,"wires":[["bed6f55c.70e99"]]},{"id":"c5b21a26.849748","type":"ui_template","z":"b1b75497.a979a8","g":"e7ab9317.044c3","group":"5345d7a1.deddd8","name":"","order":6,"width":"18","height":"6","format":"<div ng-bind-html=\"msg.payload\" height=\"400\" style=\"height: 400px;\"><br/>\n</div>\n\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":1120,"y":140,"wires":[[]]},{"id":"d8df9471.b5d4c8","type":"template","z":"b1b75497.a979a8","g":"e7ab9317.044c3","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<table width=\"100%\">\n    <tr><th>File Name</th><th>Size</th><th>Created</th><th>Changed</th></tr>\n {{#payload}}\n        <tr>\n            <td><a href=\"/download?filename={{name}}\" target=\"blank\">{{fname}}</a></td>\n <td>{{stat.size}}</td>\n            <td>{{stat.created}}</td>\n    <td>{{stat.changed}}</td>\n        </tr>\n {{/payload}}\n</table>\n","output":"str","x":980,"y":140,"wires":[["c5b21a26.849748"]]},{"id":"182da13.eb7735f","type":"function","z":"b1b75497.a979a8","g":"e7ab9317.044c3","name":"Convert timestamps","func":"for (var i=0; i<msg.payload.length; i++) {\n msg.payload[i].stat.created = msg.payload[i].stat.created.toISOString().slice(0, 19).replace('T', ' ');\n    msg.payload[i].stat.changed = msg.payload[i].stat.changed.toISOString().slice(0, 19).replace('T', ' ');\n    msg.payload[i].stat.accessed = msg.payload[i].stat.accessed.toISOString().slice(0, 19).replace('T', ' ');\n    msg.payload[i].stat.statusChanged = msg.payload[i].stat.statusChanged.toISOString().slice(0, 19).replace('T', ' ');\n    msg.payload[i].fname = msg.payload[i].name.replace(/^.*(\\\\|\\/|\\:)/, '');\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":780,"y":140,"wires":[["d8df9471.b5d4c8"]]},{"id":"60f0508c.618a58","type":"ui_button","z":"b1b75497.a979a8","g":"b3b06e0a.0b2088","name":"","group":"5345d7a1.deddd8","order":10,"width":"2","height":"1","passthru":false,"label":"Delete","tooltip":"","color":"","bgcolor":"","icon":"delete","payload":"","payloadType":"str","topic":"","topicType":"str","x":110,"y":480,"wires":[["1a5bc125.122db7"]]},{"id":"506dd40c.705c4c","type":"function","z":"b1b75497.a979a8","g":"b3b06e0a.0b2088","name":"Get filename","func":"// Get the filename from the flow context\nlet filename = flow.get(\"fileselected\");\n\n// check, if the filename is undefined that means it does not exist yet, nothing is selected yet\n// return: do not output anything\nif (filename===undefined) {\n return;\n}\n\n// return the filename to the file-in node to delete\nmsg.filename = filename;\n\nif (msg.filename.replace(/^.*(\\\\|\\/|\\:)/, '')[0]!==\".\") {\n    // Only do this if this is a file, we don't delete folders\n    // and delete the context/selection as we are deleting the file as well\n flow.set(\"fileselected\");\n    return msg;\n}","outputs":1,"noerr":0,"x":790,"y":480,"wires":[["25242708.318c2"]]},{"id":"25242708.318c2","type":"file","z":"b1b75497.a979a8","g":"b3b06e0a.0b2088","name":"Delete file","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"delete","encoding":"none","x":960,"y":480,"wires":[["6ca7019c.dfbc","17b507de.c7f3d8"]]},{"id":"e009e08a.487648","type":"http in","z":"b1b75497.a979a8","g":"125619d1.c0fa4e","name":"","url":"/download","method":"get","upload":false,"swaggerDoc":"","x":140,"y":580,"wires":[["956f27cf.e605a8"]]},{"id":"34b3eeda.b20502","type":"http response","z":"b1b75497.a979a8","g":"125619d1.c0fa4e","name":"","statusCode":"","headers":{},"x":970,"y":580,"wires":[]},{"id":"956f27cf.e605a8","type":"function","z":"b1b75497.a979a8","g":"125619d1.c0fa4e","name":"Get the file name","func":"msg.filename = msg.req.query.filename;\nmsg.contentdisposition = \"attachment; filename=\\\"\" + msg.req.query.filename.replace(/^.*(\\\\|\\/|\\:)/, '') + \"\\\"\";\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":580,"wires":[["c6e89da7.c766e8"]],"outputLabels":["Folder selected"]},{"id":"c6e89da7.c766e8","type":"file in","z":"b1b75497.a979a8","g":"125619d1.c0fa4e","name":"","filename":"","format":"","chunk":false,"sendError":false,"encoding":"none","x":580,"y":580,"wires":[["d94d7129.0b514"]]},{"id":"d94d7129.0b514","type":"change","z":"b1b75497.a979a8","g":"125619d1.c0fa4e","name":"Set Headers","rules":[{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.content-type","pt":"msg","to":"text/csv","tot":"str"},{"t":"set","p":"headers.Content-Disposition","pt":"msg","to":"contentdisposition","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":580,"wires":[["34b3eeda.b20502"]]},{"id":"acdcd1ef.c5d6d8","type":"ui_button","z":"b1b75497.a979a8","g":"c151a9f4.a134a8","name":"","group":"5345d7a1.deddd8","order":11,"width":"2","height":"1","passthru":false,"label":"Graph","tooltip":"","color":"","bgcolor":"","icon":"show_chart","payload":"","payloadType":"str","topic":"","topicType":"str","x":110,"y":680,"wires":[["86ace8a1.dccee8"]]},{"id":"86ace8a1.dccee8","type":"function","z":"b1b75497.a979a8","g":"c151a9f4.a134a8","name":"Get filename","func":"// Get the filename from the flow context\nlet filename = flow.get(\"fileselected\");\n\n// check, if the filename is undefined that means it does not exist yet, nothing is selected yet\n// return: do not output anything\nif (filename===undefined) {\n return;\n}\n\n// return the filename to the file-in node to delete\nmsg.filename = filename;\n\nif (msg.filename.replace(/^.*(\\\\|\\/|\\:)/, '')[0]!==\".\") {\n    // Only do this if this is a file, we don't delete folders\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":680,"wires":[["f10a0f15.7ab608"]]},{"id":"f10a0f15.7ab608","type":"file in","z":"b1b75497.a979a8","g":"c151a9f4.a134a8","name":"","filename":"","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":450,"y":680,"wires":[["bc4f62d5.8fe8a8"]]},{"id":"bc4f62d5.8fe8a8","type":"csv","z":"b1b75497.a979a8","g":"c151a9f4.a134a8","name":"","sep":",","hdrin":true,"hdrout":"","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":false,"include_null_values":false,"x":590,"y":680,"wires":[["845236bb.3006d"]]},{"id":"845236bb.3006d","type":"function","z":"b1b75497.a979a8","g":"c151a9f4.a134a8","name":"Format data for chart","func":"var chart = [{\n    \"series\":[],\n \"data\":[],\n    \"labels\":[msg.filename]\n}];\n\n\n/*\nvar pressure = [];\nvar out2 = [];\n\nfor (var i=0; i<msg.payload.length; i++) {\n pressure.push({\"x\":msg.payload[i].timestamp, \"y\":msg.payload[i].pressure});\n out2.push({\"x\":msg.payload[i].timestamp, \"y\":msg.payload[i].out2*200});\n\n}\nchart[0].data.push(pressure);\nchart[0].data.push(out2);\n*/\n\nlet columns = 0;\n\nfor(var series in msg.payload[0]) {\n if(series!==\"timestamp\") {\n        chart[0].series.push(series);\n      chart[0].data.push([]);\n      columns++;\n    }\n}\n\n\nfor (var j=0; j<msg.payload.length; j++) {\n   for(var i=0;i<columns;i++) {\n       chart[0].data[i].push({\"x\":msg.payload[j].timestamp, \"y\":msg.payload[j][chart[0].series[i]]});\n   } \n}\n\n\n\n\nmsg.payload = chart;\n\nreturn msg;","outputs":1,"noerr":0,"x":780,"y":680,"wires":[["32282c2b.fd6f0c"]]},{"id":"32282c2b.fd6f0c","type":"ui_chart","z":"b1b75497.a979a8","g":"c151a9f4.a134a8","name":"","group":"5345d7a1.deddd8","order":12,"width":"18","height":"6","label":"","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"x":970,"y":680,"wires":[[]]},{"id":"49fcd691.c0d9a","type":"ui_toast","z":"b1b75497.a979a8","g":"b3b06e0a.0b2088","position":"dialog","displayTime":"3","highlight":"","sendall":false,"outputs":1,"ok":"Yes","cancel":"No","raw":false,"topic":"","name":"Confirmation","x":470,"y":480,"wires":[["866568c4.55361"]]},{"id":"1a5bc125.122db7","type":"change","z":"b1b75497.a979a8","g":"b3b06e0a.0b2088","name":"Set message","rules":[{"t":"set","p":"topic","pt":"msg","to":"Delete confirmation","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"Bist Du sicher das die Datei gelöscht werden soll?","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":480,"wires":[["49fcd691.c0d9a"]]},{"id":"866568c4.55361","type":"switch","z":"b1b75497.a979a8","g":"b3b06e0a.0b2088","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Yes","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":630,"y":480,"wires":[["506dd40c.705c4c"]]},{"id":"b78577b6.70c94","type":"function","z":"b1b75497.a979a8","name":"Folder handling","func":"let folder = context.get(\"folder\");\nif (folder===undefined) {\n    folder=\"/\";\n    context.set(\"folder\", folder);\n}\n\nlet hidden = context.get(\"hidden\");\nif (hidden===undefined) {\n    hidden=false;\n    context.set(\"hidden\", hidden);\n}\n\nif (msg.topic===\"up\") {\n    var the_arr = folder.split('/');\n    the_arr.pop();\n    folder=the_arr.join('/'); \n    context.set(\"folder\", folder);\n}\nif (msg.topic===\"change\") {\n    folder=msg.payload;    \n    context.set(\"folder\", folder);\n}\nif (msg.topic===\"hidden\") {\n    hidden=msg.payload;    \n context.set(\"hidden\", hidden);\n}\n\nmsg.payload = {\"start\":folder, \"hidden\": hidden};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":340,"y":260,"wires":[["6ca7019c.dfbc","cd6a932d.015208","17b507de.c7f3d8"]]},{"id":"cd6a932d.015208","type":"ui_text","z":"b1b75497.a979a8","g":"c054ed48.ca24e","group":"5345d7a1.deddd8","order":4,"width":"9","height":"1","name":"","label":"Folder:","format":"{{msg.payload.start}}","layout":"row-left","x":580,"y":260,"wires":[]},{"id":"e21faf7f.a00908","type":"ui_button","z":"b1b75497.a979a8","g":"4c1e7f93.0d14a8","name":"","group":"5345d7a1.deddd8","order":3,"width":"2","height":"1","passthru":false,"label":"Up","tooltip":"","color":"","bgcolor":"","icon":"arrow_upwards","payload":"","payloadType":"str","topic":"up","topicType":"str","x":130,"y":240,"wires":[["b78577b6.70c94"]]},{"id":"7c53b6d4.2ab54","type":"ui_button","z":"b1b75497.a979a8","g":"4c1e7f93.0d14a8","name":"","group":"5345d7a1.deddd8","order":8,"width":"2","height":"1","passthru":false,"label":"Open","tooltip":"","color":"","bgcolor":"","icon":"folder_open","payload":"","payloadType":"str","topic":"","topicType":"str","x":130,"y":320,"wires":[["db641113.d9fb1"]]},{"id":"db641113.d9fb1","type":"function","z":"b1b75497.a979a8","name":"Change folder","func":"// Get the filename from the flow context\nlet folderselected = flow.get(\"folderselected\");\n\n// check, if the filename is undefined that means it does not exist yet, nothing is selected yet\n// return: do not output anything\nif (folderselected===undefined) {\n    return;\n}\n\nmsg.topic = \"change\";\nmsg.payload = folderselected;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":340,"y":320,"wires":[["b78577b6.70c94"]]},{"id":"eabf420f.1be678","type":"ui_button","z":"b1b75497.a979a8","g":"4c1e7f93.0d14a8","name":"","group":"5345d7a1.deddd8","order":2,"width":"2","height":"1","passthru":false,"label":"Reset","tooltip":"","color":"","bgcolor":"","icon":"autorenew","payload":"/data/co2data","payloadType":"str","topic":"change","topicType":"str","x":130,"y":200,"wires":[["b78577b6.70c94"]]},{"id":"333f28f3.fc738","type":"ui_dropdown","z":"b1b75497.a979a8","g":"c054ed48.ca24e","name":"Folder Selector","label":"","tooltip":"","place":"Select a folder","group":"5345d7a1.deddd8","order":7,"width":"5","height":"1","passthru":false,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","topicType":"str","x":940,"y":320,"wires":[["adfa0d99.c7b57"]]},{"id":"b24a5eef.1429c","type":"function","z":"b1b75497.a979a8","g":"c054ed48.ca24e","name":"Format data","func":"// format the data for the dropdown\nmsg.options = [];\nfor (var i=0; i<msg.payload.length; i++) {\n    // This is a foler\n    obj = {};\n    obj [\"[\"+msg.payload[i].name.replace(/^.*(\\\\|\\/|\\:)/, '')+\"]\"]=msg.payload[i].name;\n msg.options.push(obj);\n}\nmsg.payload={};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":750,"y":320,"wires":[["333f28f3.fc738"]]},{"id":"e890e960.b88ad","type":"change","z":"b1b75497.a979a8","g":"e7ab9317.044c3","name":"Save selection","rules":[{"t":"set","p":"fileselected","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1140,"y":80,"wires":[[]]},{"id":"adfa0d99.c7b57","type":"change","z":"b1b75497.a979a8","g":"c054ed48.ca24e","name":"Save selection","rules":[{"t":"set","p":"folderselected","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1140,"y":320,"wires":[[]]},{"id":"7595a620.d7a3c8","type":"ui_switch","z":"b1b75497.a979a8","d":true,"g":"4c1e7f93.0d14a8","name":"","label":"Hidden","tooltip":"Show hidden files or not","group":"5345d7a1.deddd8","order":5,"width":"2","height":"1","passthru":false,"decouple":"false","topic":"hidden","topicType":"str","style":"","onvalue":"true","onvalueType":"bool","onicon":"check_box","oncolor":"#000000","offvalue":"false","offvalueType":"bool","officon":"check_box_outline_blank","offcolor":"#000000","animate":true,"x":120,"y":280,"wires":[["b78577b6.70c94"]]},{"id":"ed5d9d89.b59408","type":"comment","z":"b1b75497.a979a8","name":"Install: node-red-contrib-fs","info":"","x":570,"y":760,"wires":[]},{"id":"83fefc4d.7fe8c8","type":"comment","z":"b1b75497.a979a8","name":"(c) 2020 - 2021 Thomas Wenzlaff www.wenzlaff.info","info":"","x":230,"y":760,"wires":[]},{"id":"6ca7019c.dfbc","type":"fs-file-lister","z":"b1b75497.a979a8","g":"e7ab9317.044c3","name":"Files","start":"/data/co2data","pattern":"*.*","folders":"*","hidden":false,"lstype":"files","path":true,"single":true,"depth":0,"stat":true,"showWarnings":false,"x":570,"y":80,"wires":[["d70a6028.665f28","182da13.eb7735f"]]},{"id":"17b507de.c7f3d8","type":"fs-file-lister","z":"b1b75497.a979a8","g":"c054ed48.ca24e","name":"Folders","start":"/data/co2data","pattern":"*.*","folders":"*","hidden":false,"lstype":"directories","path":true,"single":true,"depth":0,"stat":true,"showWarnings":false,"x":580,"y":320,"wires":[["b24a5eef.1429c"]]},{"id":"291a6bb0.227b1c","type":"comment","z":"b1b75497.a979a8","name":"Pfad anpassen in: Init + Reset + Files + Folder","info":"","x":870,"y":760,"wires":[]},{"id":"5345d7a1.deddd8","type":"ui_group","name":"History Browser","tab":"2bbf4e2.8db68b2","order":1,"disp":true,"width":"18","collapse":false},{"id":"2bbf4e2.8db68b2","type":"ui_tab","name":"CO2 History","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

Collection Info

Flow Info

Created 1 month, 3 weeks ago
Rating: not yet rated

Owner

Node Types

Core
  • change (x4)
  • comment (x4)
  • csv (x1)
  • file (x1)
  • file in (x2)
  • function (x9)
  • http in (x1)
  • http response (x1)
  • inject (x1)
  • switch (x1)
  • tab (x1)
  • template (x1)
Other
  • fs-file-lister (x2)
  • group (x6)
  • ui_button (x6)
  • ui_chart (x1)
  • ui_dropdown (x2)
  • ui_group (x1)
  • ui_switch (x1)
  • ui_tab (x1)
  • ui_template (x1)
  • ui_text (x1)
  • ui_toast (x1)

Tags

  • Co2
  • history
  • co2-history
  • co2-ampel
  • co2
  • CO2-Browser
  • NodeRed
  • Wenzlaff.de
  • Kleinhirn.eu
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option