-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsvLog.json
1 lines (1 loc) · 19 KB
/
csvLog.json
1
[{"id":"c4906d1a.66eff","type":"tab","label":"CSV Settings","disabled":false,"info":""},{"id":"beef850b.c7da58","type":"fs-ops-access","z":"c4906d1a.66eff","name":"pl08officeEnergyMeter.csv","path":"","pathType":"str","filename":"/home/pi/Desktop/pl08officeEnergyMeter.csv","filenameType":"str","read":true,"write":false,"throwerror":false,"x":780,"y":300,"wires":[["b8891c5.0fa7ee"],["bccc19fb.818e58","cd87ab26.bf5aa8"]]},{"id":"bccc19fb.818e58","type":"function","z":"c4906d1a.66eff","name":"StructTitleString","func":"msg.payload=\"Date,Time,Location,FWh,Active Power, R Current, Y Current, B Current\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":980,"y":420,"wires":[["554964af.80a95c"]]},{"id":"554964af.80a95c","type":"file","z":"c4906d1a.66eff","name":"pl08officeEnergyMeter.csv","filename":"/home/pi/Desktop/pl08officeEnergyMeter.csv","appendNewline":true,"createDir":true,"overwriteFile":"false","x":1240,"y":420,"wires":[[]]},{"id":"b8891c5.0fa7ee","type":"file","z":"c4906d1a.66eff","name":"pl08officeEnergyMeter.csv","filename":"/home/pi/Desktop/pl08officeEnergyMeter.csv","appendNewline":true,"createDir":false,"overwriteFile":"false","x":1240,"y":300,"wires":[[]]},{"id":"cd87ab26.bf5aa8","type":"delay","z":"c4906d1a.66eff","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":980,"y":360,"wires":[["b8891c5.0fa7ee"]]},{"id":"e025304c.74ae","type":"function","z":"c4906d1a.66eff","name":"csv data","func":"var timestamp= new Date();\nvar time = timestamp.getTime()\nvar Local_time=new Date(time).toLocaleString()\n\n\nvar str=Local_time +\",Pl 08 Office\" + \",\" + global.get(\"sensor[14][1]\") + \",\" + global.get(\"sensor[14][2]\") + \",\" + global.get(\"sensor[14][3]\") + \",\" + global.get(\"sensor[14][4]\") + \",\" + global.get(\"sensor[14][5]\")\nmsg.payload=str\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":520,"y":300,"wires":[["beef850b.c7da58"]]},{"id":"c07a13db.f0c2a","type":"inject","z":"c4906d1a.66eff","name":"","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":300,"wires":[["3494e42a.631a5c","86117ae6.79dd58"]]},{"id":"3494e42a.631a5c","type":"function","z":"c4906d1a.66eff","name":"csvDelay14","func":"flow.set(\"csvDelay14\", flow.get(\"csvDelay14\") + 1);\n\nif(flow.get(\"csvDelay14\") > (global.get(\"Tank1csvLogDelay\")*60))\n{\n flow.set(\"csvDelay14\", 0);\n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":350,"y":300,"wires":[["e025304c.74ae"]]},{"id":"86117ae6.79dd58","type":"function","z":"c4906d1a.66eff","name":"IP Address","func":"var ip=global.get('IP_Address')\nmsg.payload=\"http://\"+ip+\":1880/pl08officeEnergyMeter.csv\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":350,"y":380,"wires":[["4c8323fc.c1457c"]]},{"id":"4c8323fc.c1457c","type":"ui_template","z":"c4906d1a.66eff","group":"7ca9f5c7.e6858c","name":"Download Button","order":2,"width":4,"height":1,"format":"<!DOCTYPE html>\n<html>\n<body>\n \n<md-button ng-style=\"{background: '#0000FF', \n color:'white',\n padding: '10px',\n cursor: 'allowed'\n \n }\"\n\n ng-click href=\"{{msg.payload}}\"\n>\n<i class=\"fa fa-download\" style = \"color: white;\"></i>\npl08officeEnergyMeter.csv\n</md-button>\n</body>\n</html>\n","storeOutMessages":false,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":550,"y":380,"wires":[[]]},{"id":"32711bf2.93de44","type":"inject","z":"c4906d1a.66eff","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":150,"y":100,"wires":[["87cfb9f2.f3ad58","5d6fab56.0fc414"]]},{"id":"87cfb9f2.f3ad58","type":"file in","z":"c4906d1a.66eff","name":"csvlogdelay.txt","filename":"/home/pi/Desktop/csvlogdelay.txt","format":"utf8","chunk":false,"sendError":false,"x":360,"y":100,"wires":[["6e46a9b8.825be8"]]},{"id":"6e46a9b8.825be8","type":"function","z":"c4906d1a.66eff","name":"settings obj","func":"//global.set(\"settings\",msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":100,"wires":[["8ad3f8c7.2a64b8"]]},{"id":"8ad3f8c7.2a64b8","type":"json","z":"c4906d1a.66eff","name":"","property":"payload","action":"","pretty":false,"x":670,"y":100,"wires":[["433c9750.102c08"]]},{"id":"433c9750.102c08","type":"ui_template","z":"c4906d1a.66eff","group":"7ca9f5c7.e6858c","name":"csv log delay","order":1,"width":24,"height":8,"format":"<html>\n <head>\n \n </head>\n <body>\n<style>\ntable, th, tr, td\n{\n border: 1px black solid;\n border-collapse: collapse;\n text-align: center;\n}\n\ninput[type = number], input[type = text]\n{\n background-color: white;\n border: none;\n word-wrap: break-word;\n word-break: break-all;\n text-align: center;\n}\n\nth\n{\n background-color: #2a92b5;\n padding : 7px 3px;\n color: white;\n}\n\n</style>\n \n\n <form id=\"TableForm\" ng-submit=\"MyTableFormAction()\" >\n <table align = \"center\" id=\"EmptableWithEditDelete1\">\n <tr>\n <th>\n Sr. No.\n </th>\n <th>\n csv log delay\n </th>\n <th>\n Edit\n </th>\n <th>\n Delete\n </th>\n </tr>\n \n <tr ng-repeat=\"Set in IntMsg.payload.SetData\" >\n <td disabled=\"true\">\n {{$index+1}}\n </td>\n <td>\n <input type=\"number\" step=\"0.01\" id=\"EmpHighInput{{$index}}\" ng-model=\"Set.csvLogDelay\" disabled=\"true\" required> <!--ng-model=\"IntMsg.payload.SetData[$index].Name\"-->\n </td>\n <td>\n <button type=\"button\" ng-click=\"TableFormRowEditBtn($index)\" ng-style=\"{background: '#ffc399', color:'black', border : '1px solid #0093dc', cursor: 'allowed'}\">\n Edit\n </button>\n </td>\n <td>\n <button type=\"button\" ng-click=\"TableFormRowDeleteBtn($index)\" ng-style=\"{background: '#ffc399', color:'black', border : '1px solid #0093dc', cursor: 'allowed'}\">\n Delete\n </button>\n </td>\n </tr>\n </table>\n <br>\n <br>\n\n <button type=\"Submit\" name=\"Submit\" ng-style=\"{float: 'right', background: '#54e18a', color:'Black',padding: '4px 6px', border: 'none', cursor: 'allowed'}\"> \n Submit Data\n </button>\n <button type=\"button\" ng-click=\"TableAddFirstRecord()\" ng-style=\"{float: 'left', background: '#54e18a', color:'Black',padding: '4px 6px', border: 'none', cursor: 'allowed'}\"> Add Record\n \n </button>\n \n \n </form>\n\n<script>\n//send({payload:myFunction1()})\n//few learnigs: if msg.pyload is used to link data to html tags like \n//<input type=\"text\" id=\"EmpId\" name=\"fname\" value={{msg.payload.TSetData.Selectedobj}} disabled > \n//then \n//ensure orginal data variables in msg.payload are intact through out the session/user interaction. \n\n//\"{{angular_var}}\" syntax is used in html to pass varible data from angular to html tags\n//angular function send({payload:var/funct}) is used to send the msg to node red using ng-click directives. it updates msg.payload of entire template. \n// if your html view tags like input msg/table/dropdowns are getting reset that means\n//while sending msg, orginal msg got disturbed.\n// to solve this issue you can preserve original msg by adding new varibles to orginal msg.payload .\n// this is allowed but you should not disturb incoming msg.payload varibales data structure.\n// i.e say incoming msg.payload had data structure like msg={\"payload\":{\"emp\":employees}}\n//employees=[{\"name\":\"e1\",\"id\":1,\"dept\":\"dept1\",\"div\":\"div1\"},{\"name\":\"e2\",\"id\":2,\"dept\":\"dept2\",\"div\":\"div2\"},{\"name\":\"e3\",\"id\":3,\"dept\":\"dept3\",\"div\":\"div3\"}]\n// in this case you can add msg={\"payload\":{\"emp\":employees},{\"newVar\":newVarData}} this will works as orignal msg.payload.emp is not disturbed and new object \"NewVar is added\"\n// you can chage values of all varibles . that will not create any error or reset of view.\n\n\n// to check node-red ui is working properly , type \"http://127.0.0.1:1880/ui/\" in chrome browser and click\n//on broweser three dots menu-->more tools-->developer tools ensure at riht side of broweser debug window is opend\n// click on Consol tab to see error/status mssages.\n// you can use console.log(\"your_var_name\"); to see the value\n\n var test=document.getElementById(\"EmpId\");\n\n(function(scope) {\n // use this func\n scope.IntMsg={\"payload\":{\"SetData\":[{}]}};\n \n scope.$watch('msg', function(msg) {\n if (msg) {\n // Do something when msg arrives\n scope.IntMsg=msg;\n \n console.log(msg.payload);\n }\n });\n\n \n //\n scope.TableFormRowEditBtn=function MyTableFormEditBtn(index){\n document.getElementById(\"EmptableWithEditDelete1\").rows[index+1].cells[1].getElementsByTagName(\"input\")[0].disabled=false\n //document.getElementById(\"DivtableWithEditDelete\").rows[index+1].cells[1] provides row-1 column 1 cell. in this cell. as index in JS starts with zero,need to do +1 to get first row.\n //to access input tag from row-1,column-1, \"getElementsByTagName(\"input\")[0]\" is used.[0] provides first input tag in this context.\n \n //console.log(scope.msg.payload.MyFormData.Edit[index]);\n \n }\n\n\n scope.TableAddFirstRecord=function MyTableAddFirstRecordBtn(){\n //Array index in JS variable starts from Zero where as table row index starts from 1 so index is added with +1\n console.log(\"TableAddFirstRecord clicked\");\n var dummy={\"Pressure\":\"\",};\n scope.IntMsg.payload.SetData.push(dummy);\n }\n\n\n scope.TableFormAddRowBtn=function MyTableFormAddRowBtn(index){\n //Array index in JS variable starts from Zero where as table row index starts from 1 so index is added with +1\n var dummy={\"Pressure\":\"\"};\n scope.IntMsg.payload.SetData.splice(index+1, 0, dummy);\n }\n scope.MyTableFormAction= function MyTableFormData(){\n var i;\n for (i = 0; i < scope.IntMsg.payload.SetData.length; i++) {\n document.getElementById(\"EmptableWithEditDelete1\").rows[i+1].cells[1].getElementsByTagName(\"input\")[0].disabled=true\n }\n \n console.log(\"MyTableFormData\");\n console.log(scope.IntMsg.payload.SetData);\n window.confirm(\"Data Saved\");\n scope.send({\"payload\":(scope.IntMsg.payload)});\n \n }\n scope.TableFormRowDeleteBtn=function MyTableFormRowDeleteBtn(index){\n var txt;\n var r = confirm(\"Press OK to Confim Delete \");\n if (r == true) {\n scope.IntMsg.payload.SetData.splice(index,1);\n scope.MyTableFormAction();\n console.log([\"TableFormRowDeleteBtn\"],index);\n }\n \n\n }\n \n})(scope);\n\n</script>\n</body>\n</html>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":830,"y":100,"wires":[["dac36a26.7dff28"]]},{"id":"dac36a26.7dff28","type":"file","z":"c4906d1a.66eff","name":"csvlogdelay.txt","filename":"/home/pi/Desktop/csvlogdelay.txt","appendNewline":false,"createDir":true,"overwriteFile":"true","x":1060,"y":100,"wires":[["68bc21e3.1e646","76d09f89.e84a3"]]},{"id":"68bc21e3.1e646","type":"debug","z":"c4906d1a.66eff","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1390,"y":100,"wires":[]},{"id":"76d09f89.e84a3","type":"function","z":"c4906d1a.66eff","name":"SetVal","func":"var data = msg.payload.SetData;\nvar n= data.length;\n\n\nfor(i=0;i<n;i++)\n{\n global.set('Tank'+(i+1) + 'description', msg.payload.SetData[i].Description);\n global.set('Tank'+(i+1) + 'csvLogDelay', msg.payload.SetData[i].csvLogDelay);\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1230,"y":140,"wires":[["68bc21e3.1e646"]]},{"id":"d515af97.1d27f","type":"inject","z":"c4906d1a.66eff","name":"CSV BACKUP","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"string"}],"repeat":"10","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":540,"wires":[["6ae33592.e1c57c"]]},{"id":"6ae33592.e1c57c","type":"function","z":"c4906d1a.66eff","name":"","func":"var timestamp= new Date();\nvar Month=(timestamp.getMonth()+1);\nvar mon=[\"Jan\",\"Feb\",\"Mar\",\"Apr\",\"May\",\"June\",\"Jul\",\"Aug\",\"Sept\",\"Oct\",\"Nov\",\"Dec\"];\nif((Month-2)==-1)\n{\nmsg.month=\"Dec\" \n}\nelse\n{\nmsg.month=mon[Month-2]\n}\nmsg.payload= Month;\n//node.warn(msg)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":540,"wires":[["fe9c5082.d68e7"]]},{"id":"fe9c5082.d68e7","type":"rbe","z":"c4906d1a.66eff","name":"","func":"rbei","gap":"","start":"","inout":"out","property":"payload","x":530,"y":540,"wires":[["9ff7e017.71a62"]]},{"id":"9ff7e017.71a62","type":"function","z":"c4906d1a.66eff","name":"","func":"var month=msg.month;\nmsg.payload=\"pl08officeEnergyMeterBackup\"+\"_\"+month+\".csv\";\nmsg.path=global.get('path');\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":700,"y":540,"wires":[["accb679b.9503c8","3e2cd41a.e2676c"]]},{"id":"accb679b.9503c8","type":"fs-ops-copy","z":"c4906d1a.66eff","name":"pl08officeEnergyMeter.csv","sourcePath":"/home/pi/Desktop/","sourcePathType":"str","sourceFilename":"pl08officeEnergyMeter.csv","sourceFilenameType":"str","destPath":"path","destPathType":"msg","destFilename":"payload","destFilenameType":"msg","link":false,"overwrite":false,"x":940,"y":520,"wires":[[]]},{"id":"3e2cd41a.e2676c","type":"delay","z":"c4906d1a.66eff","name":"","pauseType":"delay","timeout":"20","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":880,"y":560,"wires":[["d0f6b284.519a4"]]},{"id":"d0f6b284.519a4","type":"fs-ops-move","z":"c4906d1a.66eff","name":"pl08officeEnergyMeter.csv","sourcePath":"/home/pi/Desktop/","sourcePathType":"str","sourceFilename":"pl08officeEnergyMeter.csv","sourceFilenameType":"str","destPath":"/home/pi/Desktop/","destPathType":"str","destFilename":"payload","destFilenameType":"msg","link":false,"x":1100,"y":560,"wires":[[]]},{"id":"eef6b400.6a54c8","type":"comment","z":"c4906d1a.66eff","name":"csv settings table","info":"","x":140,"y":60,"wires":[]},{"id":"87980d73.a8918","type":"comment","z":"c4906d1a.66eff","name":"transferring records to csv file","info":"","x":180,"y":260,"wires":[]},{"id":"70414432.ef525c","type":"comment","z":"c4906d1a.66eff","name":"monthly backup of csv file","info":"","x":170,"y":500,"wires":[]},{"id":"5d6fab56.0fc414","type":"function","z":"c4906d1a.66eff","name":"flow variables","func":"flow.set(\"csvDelay14\", 0);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":180,"wires":[[]]},{"id":"7ca9f5c7.e6858c","type":"ui_group","name":"CSV delay settings","tab":"","order":1,"disp":true,"width":"24","collapse":false}]