Hi, I am trying to make OEE calculations with the help of node red and firstly I have to make production tracking of units per hour. So, I have to multiply hours with the units(example:- hours*units) and I am taking data from json(inject node ), but its not working, so could you help me find the write code or check my flow and tell me what is wrong with it.
Thank you
shubhangi
var value = flow.get('pieceValue');
var h = flow.get('hours');
var productionPerHour = flow.get('hourlyProduction');
productionPerHour = value/(h*24)||0;
if (productionPerHour.length<=1000);
productionPerHour+1;
value+2;
flow.set('pieceValue', value);
flow.set('hours', h);
flow.set('hourlyProduction', productionPerHour);
//msg.payload = { hourlyProduction: msg.payload.productionPerHour };
return msg;
FLOW
[{"id":"604bd7fa.9f54b8","type":"inject","z":"b6b3d834.5b80c8","name":"Machine 001","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":true,"onceDelay":"60","topic":"","payload":"{"machineid":"001","productid":"01","piecespercycle":2,"stdcycletime":8,"stdhourlyprodn":120,"stdloadunloadtime":6,"setupchangetime":2,"orderno":"1","status":"Running"}","payloadType":"json","x":140,"y":700,"wires":[["97e48b42.6389c8","2f65c548.85313a"]]},{"id":"97e48b42.6389c8","type":"function","z":"b6b3d834.5b80c8","name":"pieceValue","func":"pieceValue = msg.payload.piecespercycle;\nmsg.payload = pieceValue;\nreturn msg;\n\n\n\n\n\n\n\n\n\n//p=JSON.parse(msg.payload);\n//a=msg.payload;\n//node.log(typeof a);\n//msg.payload = a.piecespercycle;\n//return msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":350,"y":640,"wires":[["1b5b43da.cd6ddc"]]},{"id":"1b5b43da.cd6ddc","type":"function","z":"b6b3d834.5b80c8","name":"Hourly Production","func":"var value = flow.get('pieceValue');\nvar h = flow.get('hours');\nvar productionPerHour = flow.get('hourlyProduction');\n\n\nproductionPerHour = value/(h*24)||0;\nif (productionPerHour.length<=1000);\n productionPerHour+1;\n value+2;\n\nflow.set('pieceValue', value); \nflow.set('hours', h);\nflow.set('hourlyProduction', productionPerHour);\n \n//msg.payload = { hourlyProduction: msg.payload.productionPerHour };\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":590,"y":640,"wires":[["1afe9010.fec6c"]]},{"id":"2f65c548.85313a","type":"function","z":"b6b3d834.5b80c8","name":"Time","func":"var d = new Date();\nvar dString = d.toISOString();\nvar hours = d.getHours();\nvar minutes = d.getMinutes();\n\nmsg.payload = dString; \n\nflow.set("hours",hours);\n\nflow.set("minutes",minutes);\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":760,"wires":[["f6d52985.e094e8","e427527b.4b7d6","2caf5fa5.c115e"]]},{"id":"f6d52985.e094e8","type":"function","z":"b6b3d834.5b80c8","name":"Hours","func":"msg.payload = flow.get("hours");\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":450,"y":760,"wires":[["70c61ae8.393024","1b5b43da.cd6ddc"]]},{"id":"e427527b.4b7d6","type":"function","z":"b6b3d834.5b80c8","name":"Minutes","func":"msg.payload = flow.get("minutes");\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":460,"y":820,"wires":[["3a196f04.a430a"]]},{"id":"1afe9010.fec6c","type":"change","z":"b6b3d834.5b80c8","name":"Hourly Production","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.hourlyProduction","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":640,"wires":[["4624021a.b0812c"]]},{"id":"2caf5fa5.c115e","type":"change","z":"b6b3d834.5b80c8","name":"Time","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.Time","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":700,"wires":[["4624021a.b0812c"]]},{"id":"70c61ae8.393024","type":"change","z":"b6b3d834.5b80c8","name":"Hours","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.hours","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":760,"wires":[["4624021a.b0812c"]]},{"id":"3a196f04.a430a","type":"change","z":"b6b3d834.5b80c8","name":"Minutes","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.minutes","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":820,"wires":[["4624021a.b0812c"]]},{"id":"4624021a.b0812c","type":"join","z":"b6b3d834.5b80c8","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":910,"y":740,"wires":[["bc426181.4222c"]]},{"id":"bc426181.4222c","type":"debug","z":"b6b3d834.5b80c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1090,"y":740,"wires":}]