3rd Order Polynomial

[{"id":"4c828c67.58a5a4","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"4094cc06.612324","type":"regression","z":"4c828c67.58a5a4","name":"","dataSetSize":0,"regressionType":"polynomial","polynomialOrder":"2","precision":"10","xInputField":"payload.x","xInputFieldType":"msg","yInputField":"payload.y","yInputFieldType":"msg","yOutputField":"payload.y","yOutputFieldType":"msg","functionOutputField":"function","functionOutputFieldType":"msg","resultOnly":false,"x":768,"y":360,"wires":[["5a4517f8.78ec88"]]},{"id":"218e19.6f6f31e8","type":"inject","z":"4c828c67.58a5a4","name":"","topic":"","payload":"{\"x\":[[700,45],[740,46.5],[780,47.5],[820,47.7],[860,46.5],[900,45]]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":75,"y":140,"wires":[[]],"l":false},{"id":"a18d51c2.ced9b","type":"debug","z":"4c828c67.58a5a4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1150,"y":380,"wires":[]},{"id":"5a4517f8.78ec88","type":"switch","z":"4c828c67.58a5a4","name":"","property":"function.r2","propertyType":"msg","rules":[{"t":"gte","v":".98","vt":"num"},{"t":"lt","v":".98","vt":"num"}],"checkall":"false","repair":false,"outputs":2,"x":950,"y":360,"wires":[["adb820ef.0d4d4"],["29ab43a5.9d457c"]]},{"id":"29ab43a5.9d457c","type":"regression","z":"4c828c67.58a5a4","name":"","dataSetSize":0,"regressionType":"polynomial","polynomialOrder":"3","precision":"10","xInputField":"payload.x","xInputFieldType":"msg","yInputField":"payload.y","yInputFieldType":"msg","yOutputField":"payload.y","yOutputFieldType":"msg","functionOutputField":"function","functionOutputFieldType":"msg","resultOnly":false,"x":950,"y":420,"wires":[["d55b41e6.c7e42"]]},{"id":"fbe8ef9.920811","type":"debug","z":"4c828c67.58a5a4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1150,"y":460,"wires":[]},{"id":"d55b41e6.c7e42","type":"function","z":"4c828c67.58a5a4","name":"Curve Drawing","func":"var xyData = msg.payload.x;\nvar lastYValue = xyData[xyData.length - 1][0];\nvar firstYValue = xyData[0][0];\nvar regression = msg.function.equation;\nvar ax = regression[0];\nvar bx = regression[1];\nvar cx = regression[2];\nvar d = regression[3];\nvar yCurve = [];\nvar xCurve = [];\nvar y = 0;\nvar xData = msg.x;\nvar yData = msg.y;\n\nfor (var i = firstYValue; i <= (lastYValue); i++) {\n    xCurve.push(i);\n    y = (ax*(i*i*i)+bx*(i*i)+cx*(i)+d);\n    yCurve.push(y);\n    //Do something\n}\nfor (i = (xyData.length + 1); i <= (xCurve.length + xyData.length); i++) {\n    xData[i] = xCurve[i - (xyData.length + 1)];\n    yData[i] = yCurve[i - (xyData.length + 1)];\n}\nmsg.payload.xcurve = xCurve;\nmsg.payload.ycurve = yCurve;\nmsg.payload.ymax = Math.max(...(yCurve));\nvar pumpMaxKnockPosition = xCurve[yCurve.indexOf(msg.payload.ymax)];\nmsg.payload.pumpmaxknockposition = pumpMaxKnockPosition\nmsg.x = xData;\nmsg.y = yData;\nreturn msg;","outputs":1,"noerr":0,"x":1180,"y":420,"wires":[["fbe8ef9.920811"]]},{"id":"adb820ef.0d4d4","type":"function","z":"4c828c67.58a5a4","name":"Curve Drawing","func":"var xyData = msg.payload.x;\nvar lastYValue = xyData[xyData.length - 1][0];\nvar firstYValue = xyData[0][0];\nvar regression = msg.function.equation;\nvar ax = regression[0];\nvar bx = regression[1];\nvar c = regression[2];\nvar yCurve = [];\nvar xCurve = [];\nvar y = 0;\nvar xData = msg.x;\nvar yData = msg.y;\n\nfor (var i = firstYValue; i <= (lastYValue); i++) {\n    xCurve.push(i);\n    y = (ax*(i*i)+bx*(i)+c);\n    yCurve.push(y);\n    //Do something\n}\n\nfor (i = (xyData.length + 1); i <= (xCurve.length + xyData.length); i++) {\n    xData[i] = xCurve[i - (xyData.length + 1)];\n    yData[i] = yCurve[i - (xyData.length + 1)];\n}\nmsg.payload.xcurve = xCurve;\nmsg.payload.ycurve = yCurve;\nmsg.payload.ymax = Math.max(...(yCurve));\nvar pumpMaxKnockPosition = xCurve[yCurve.indexOf(msg.payload.ymax)];\nmsg.payload.pumpmaxknockposition = pumpMaxKnockPosition\nmsg.payload.xx = xData;\nmsg.payload.yy = yData;\nreturn msg;","outputs":1,"noerr":0,"x":1180,"y":341,"wires":[["a18d51c2.ced9b","ae789e38.08edc"]]},{"id":"fefaafa.5cec25","type":"inject","z":"4c828c67.58a5a4","name":"","topic":"","payload":"{}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":70,"y":360,"wires":[["e5503036.7bc89"]]},{"id":"e5503036.7bc89","type":"pac-read","z":"4c828c67.58a5a4","device":"5902c719.eca318","dataType":"int32-table","tagName":"EventFlag","tableStartIndex":"6","tableLength":"1","value":"drawCurve","valueType":"msg","topic":"","topicType":"none","name":"","x":230,"y":360,"wires":[["8113c146.3bd31"]]},{"id":"8113c146.3bd31","type":"switch","z":"4c828c67.58a5a4","name":"","property":"drawCurve","propertyType":"msg","rules":[{"t":"eq","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":360,"wires":[["d3286baf.178598"]]},{"id":"d3286baf.178598","type":"pac-read","z":"4c828c67.58a5a4","device":"5902c719.eca318","dataType":"float-table","tagName":"x","tableStartIndex":"","tableLength":"","value":"x","valueType":"msg","topic":"","topicType":"none","name":"","x":370,"y":400,"wires":[["e66f2c84.2caaa"]]},{"id":"e66f2c84.2caaa","type":"pac-read","z":"4c828c67.58a5a4","device":"5902c719.eca318","dataType":"float-table","tagName":"y","tableStartIndex":"","tableLength":"","value":"y","valueType":"msg","topic":"","topicType":"none","name":"","x":370,"y":440,"wires":[["f1452e79.49b21"]]},{"id":"5b206b7a.ee71c4","type":"function","z":"4c828c67.58a5a4","name":"Merge X, Y Data","func":"var length = msg.fitCurve;\nvar xData = msg.x;\nvar yData = msg.y;\nvar xyData = [];\nfor (let i = 0; i <= length; i++) {\n    if (xData[i] !== 0) {\n        xyData.push([xData[i], yData[i]]);}\n}\n\nmsg.payload.x = xyData;\nreturn msg;","outputs":1,"noerr":0,"x":594,"y":360,"wires":[["4094cc06.612324"]]},{"id":"f1452e79.49b21","type":"pac-read","z":"4c828c67.58a5a4","device":"5902c719.eca318","dataType":"int32-variable","tagName":"FitCurve","tableStartIndex":"","tableLength":"","value":"fitCurve","valueType":"msg","topic":"","topicType":"none","name":"","x":380,"y":480,"wires":[["3e683446.160b4c"]]},{"id":"3e683446.160b4c","type":"pac-write","z":"4c828c67.58a5a4","device":"5902c719.eca318","dataType":"int32-table","tagName":"EventFlag","tableStartIndex":"6","value":"2","valueType":"value","name":"","x":390,"y":520,"wires":[["5b206b7a.ee71c4"]]},{"id":"ae789e38.08edc","type":"pac-write","z":"4c828c67.58a5a4","device":"5902c719.eca318","dataType":"float-table","tagName":"x","tableStartIndex":"","value":"payload.xx","valueType":"msg","name":"","x":1430,"y":380,"wires":[["e004cc54.b2aaa"]]},{"id":"e004cc54.b2aaa","type":"pac-write","z":"4c828c67.58a5a4","device":"5902c719.eca318","dataType":"float-table","tagName":"y","tableStartIndex":"","value":"payload.yy","valueType":"msg","name":"","x":1430,"y":420,"wires":[["2e2a47b5.9ff218"]]},{"id":"2e2a47b5.9ff218","type":"pac-write","z":"4c828c67.58a5a4","device":"5902c719.eca318","dataType":"float-variable","tagName":"der1","tableStartIndex":"","value":"payload.pumpmaxknockposition","valueType":"msg","name":"","x":1430,"y":460,"wires":[["cf7bc1c8.4581"]]},{"id":"cf7bc1c8.4581","type":"pac-write","z":"4c828c67.58a5a4","device":"5902c719.eca318","dataType":"float-variable","tagName":"critical1","tableStartIndex":"","value":"payload.ymax","valueType":"msg","name":"","x":1440,"y":500,"wires":[["80fbc585.2b3828"]]},{"id":"80fbc585.2b3828","type":"pac-write","z":"4c828c67.58a5a4","device":"5902c719.eca318","dataType":"float-variable","tagName":"ErrorSumOfSquares","tableStartIndex":"","value":"function.r2","valueType":"msg","name":"","x":1480,"y":540,"wires":[["bf9c6f7f.60be6"]]},{"id":"bf9c6f7f.60be6","type":"debug","z":"4c828c67.58a5a4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1690,"y":540,"wires":[]},{"id":"60f251c1.de6ae","type":"pac-read","z":"4c828c67.58a5a4","device":"5902c719.eca318","dataType":"float-table","tagName":"x","tableStartIndex":"","tableLength":"","value":"x","valueType":"msg","topic":"","topicType":"none","name":"","x":350,"y":620,"wires":[["cf5c5e20.243c4"]]},{"id":"25160051.06479","type":"inject","z":"4c828c67.58a5a4","name":"","topic":"","payload":"{}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":620,"wires":[["60f251c1.de6ae"]]},{"id":"1d601158.72679f","type":"debug","z":"4c828c67.58a5a4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":530,"y":620,"wires":[]},{"id":"cf5c5e20.243c4","type":"pac-read","z":"4c828c67.58a5a4","device":"5902c719.eca318","dataType":"float-table","tagName":"y","tableStartIndex":"","tableLength":"","value":"y","valueType":"msg","topic":"","topicType":"none","name":"","x":350,"y":660,"wires":[["1d601158.72679f"]]},{"id":"5902c719.eca318","type":"pac-device","z":"","address":"172.20.1.1","protocol":"https"}]

@josh51 Your post was mangled by the forums and Terry could not import it without errors .
You have to use the preformatted text option.

[{"id":"d760b18f.5cd48","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"82be32b4.43367","type":"regression","z":"d760b18f.5cd48","name":"","dataSetSize":0,"regressionType":"polynomial","polynomialOrder":"2","precision":"10","xInputField":"payload.x","xInputFieldType":"msg","yInputField":"payload.y","yInputFieldType":"msg","yOutputField":"payload.y","yOutputFieldType":"msg","functionOutputField":"function","functionOutputFieldType":"msg","resultOnly":false,"x":768,"y":360,"wires":[["761b3b4e.b0e4e4"]]},{"id":"2cf6c345.bc4ddc","type":"inject","z":"d760b18f.5cd48","name":"","topic":"","payload":"{      x      :[[700,45],[740,46.5],[780,47.5],[820,47.7],[860,46.5],[900,45]]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":75,"y":140,"wires":[[]],"l":false},{"id":"fdfe10a7.6f6ee","type":"debug","z":"d760b18f.5cd48","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1150,"y":380,"wires":[]},{"id":"761b3b4e.b0e4e4","type":"switch","z":"d760b18f.5cd48","name":"","property":"function.r2","propertyType":"msg","rules":[{"t":"gte","v":".98","vt":"num"},{"t":"lt","v":".98","vt":"num"}],"checkall":"false","repair":false,"outputs":2,"x":950,"y":360,"wires":[["7418daf7.2a7194"],["c799fe99.31873"]]},{"id":"c799fe99.31873","type":"regression","z":"d760b18f.5cd48","name":"","dataSetSize":0,"regressionType":"polynomial","polynomialOrder":"3","precision":"10","xInputField":"payload.x","xInputFieldType":"msg","yInputField":"payload.y","yInputFieldType":"msg","yOutputField":"payload.y","yOutputFieldType":"msg","functionOutputField":"function","functionOutputFieldType":"msg","resultOnly":false,"x":950,"y":420,"wires":[["4eb9a392.4d91dc"]]},{"id":"41ee3be1.975f44","type":"debug","z":"d760b18f.5cd48","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1150,"y":460,"wires":[]},{"id":"4eb9a392.4d91dc","type":"function","z":"d760b18f.5cd48","name":"Curve Drawing","func":"var xyData = msg.payload.x;\nvar lastYValue = xyData[xyData.length - 1][0];\nvar firstYValue = xyData[0][0];\nvar regression = msg.function.equation;\nvar ax = regression[0];\nvar bx = regression[1];\nvar cx = regression[2];\nvar d = regression[3];\nvar yCurve = [];\nvar xCurve = [];\nvar y = 0;\nvar xData = msg.x;\nvar yData = msg.y;\n\nfor (var i = firstYValue; i <= (lastYValue); i++) {\n xCurve.push(i);\n y = (ax*(iii)+bx*(ii)+cx(i)+d);\n yCurve.push(y);\n //Do something\n}\nfor (i = (xyData.length + 1); i <= (xCurve.length + xyData.length); i++) {\n xData[i] = xCurve[i - (xyData.length + 1)];\n yData[i] = yCurve[i - (xyData.length + 1)];\n}\nmsg.payload.xcurve = xCurve;\nmsg.payload.ycurve = yCurve;\nmsg.payload.ymax = Math.max(…(yCurve));\nvar pumpMaxKnockPosition = xCurve[yCurve.indexOf(msg.payload.ymax)];\nmsg.payload.pumpmaxknockposition = pumpMaxKnockPosition\nmsg.x = xData;\nmsg.y = yData;\nreturn msg;","outputs":1,"noerr":0,"x":1180,"y":420,"wires":[["41ee3be1.975f44"]]},{"id":"7418daf7.2a7194","type":"function","z":"d760b18f.5cd48","name":"Curve Drawing","func":"var xyData = msg.payload.x;\nvar lastYValue = xyData[xyData.length - 1][0];\nvar firstYValue = xyData[0][0];\nvar regression = msg.function.equation;\nvar ax = regression[0];\nvar bx = regression[1];\nvar c = regression[2];\nvar yCurve = [];\nvar xCurve = [];\nvar y = 0;\nvar xData = msg.x;\nvar yData = msg.y;\n\nfor (var i = firstYValue; i <= (lastYValue); i++) {\n xCurve.push(i);\n y = (ax*(ii)+bx(i)+c);\n yCurve.push(y);\n //Do something\n}\n\nfor (i = (xyData.length + 1); i <= (xCurve.length + xyData.length); i++) {\n xData[i] = xCurve[i - (xyData.length + 1)];\n yData[i] = yCurve[i - (xyData.length + 1)];\n}\nmsg.payload.xcurve = xCurve;\nmsg.payload.ycurve = yCurve;\nmsg.payload.ymax = Math.max(…(yCurve));\nvar pumpMaxKnockPosition = xCurve[yCurve.indexOf(msg.payload.ymax)];\nmsg.payload.pumpmaxknockposition = pumpMaxKnockPosition\nmsg.payload.xx = xData;\nmsg.payload.yy = yData;\nreturn msg;","outputs":1,"noerr":0,"x":1180,"y":341,"wires":[["fdfe10a7.6f6ee","c91f9289.8285b"]]},{"id":"a890d524.bad138","type":"inject","z":"d760b18f.5cd48","name":"","topic":"","payload":"{}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":70,"y":360,"wires":[["d52d6013.74d5f"]]},{"id":"d52d6013.74d5f","type":"pac-read","z":"d760b18f.5cd48","device":"c3c14c3.63f89b","dataType":"int32-table","tagName":"EventFlag","tableStartIndex":"6","tableLength":"1","value":"drawCurve","valueType":"msg","topic":"","topicType":"none","name":"","x":230,"y":360,"wires":[["569b6056.f73bb"]]},{"id":"569b6056.f73bb","type":"switch","z":"d760b18f.5cd48","name":"","property":"drawCurve","propertyType":"msg","rules":[{"t":"eq","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":360,"wires":[["218fe545.51b9aa"]]},{"id":"218fe545.51b9aa","type":"pac-read","z":"d760b18f.5cd48","device":"c3c14c3.63f89b","dataType":"float-table","tagName":"x","tableStartIndex":"","tableLength":"","value":"x","valueType":"msg","topic":"","topicType":"none","name":"","x":370,"y":400,"wires":[["c99b297d.5594a8"]]},{"id":"c99b297d.5594a8","type":"pac-read","z":"d760b18f.5cd48","device":"c3c14c3.63f89b","dataType":"float-table","tagName":"y","tableStartIndex":"","tableLength":"","value":"y","valueType":"msg","topic":"","topicType":"none","name":"","x":370,"y":440,"wires":[["2a872250.7640be"]]},{"id":"c4cc6e59.ece04","type":"function","z":"d760b18f.5cd48","name":"Merge X, Y Data","func":"var length = msg.fitCurve;\nvar xData = msg.x;\nvar yData = msg.y;\nvar xyData = [];\nfor (let i = 0; i <= length; i++) {\n if (xData[i] !== 0) {\n xyData.push([xData[i], yData[i]]);}\n}\n\nmsg.payload.x = xyData;\nreturn msg;","outputs":1,"noerr":0,"x":594,"y":360,"wires":[["82be32b4.43367"]]},{"id":"2a872250.7640be","type":"pac-read","z":"d760b18f.5cd48","device":"c3c14c3.63f89b","dataType":"int32-variable","tagName":"FitCurve","tableStartIndex":"","tableLength":"","value":"fitCurve","valueType":"msg","topic":"","topicType":"none","name":"","x":380,"y":480,"wires":[["a73d2493.450228"]]},{"id":"a73d2493.450228","type":"pac-write","z":"d760b18f.5cd48","device":"c3c14c3.63f89b","dataType":"int32-table","tagName":"EventFlag","tableStartIndex":"6","value":"2","valueType":"value","name":"","x":390,"y":520,"wires":[["c4cc6e59.ece04"]]},{"id":"c91f9289.8285b","type":"pac-write","z":"d760b18f.5cd48","device":"c3c14c3.63f89b","dataType":"float-table","tagName":"x","tableStartIndex":"","value":"payload.xx","valueType":"msg","name":"","x":1430,"y":380,"wires":[["4b6eb04b.4cf43"]]},{"id":"4b6eb04b.4cf43","type":"pac-write","z":"d760b18f.5cd48","device":"c3c14c3.63f89b","dataType":"float-table","tagName":"y","tableStartIndex":"","value":"payload.yy","valueType":"msg","name":"","x":1430,"y":420,"wires":[["ac5fac5c.b13fb"]]},{"id":"ac5fac5c.b13fb","type":"pac-write","z":"d760b18f.5cd48","device":"c3c14c3.63f89b","dataType":"float-variable","tagName":"der1","tableStartIndex":"","value":"payload.pumpmaxknockposition","valueType":"msg","name":"","x":1430,"y":460,"wires":[["3f108db1.04b392"]]},{"id":"3f108db1.04b392","type":"pac-write","z":"d760b18f.5cd48","device":"c3c14c3.63f89b","dataType":"float-variable","tagName":"critical1","tableStartIndex":"","value":"payload.ymax","valueType":"msg","name":"","x":1440,"y":500,"wires":[["37d60549.fb040a"]]},{"id":"37d60549.fb040a","type":"pac-write","z":"d760b18f.5cd48","device":"c3c14c3.63f89b","dataType":"float-variable","tagName":"ErrorSumOfSquares","tableStartIndex":"","value":"function.r2","valueType":"msg","name":"","x":1480,"y":540,"wires":[["63d326d6.c78158"]]},{"id":"63d326d6.c78158","type":"debug","z":"d760b18f.5cd48","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1690,"y":540,"wires":[]},{"id":"f0b94b49.87cc48","type":"pac-read","z":"d760b18f.5cd48","device":"c3c14c3.63f89b","dataType":"float-table","tagName":"x","tableStartIndex":"","tableLength":"","value":"x","valueType":"msg","topic":"","topicType":"none","name":"","x":350,"y":620,"wires":[["b1ada336.61059"]]},{"id":"a7c72069.b241d","type":"inject","z":"d760b18f.5cd48","name":"","topic":"","payload":"{}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":620,"wires":[["f0b94b49.87cc48"]]},{"id":"8d63cfb4.adba3","type":"debug","z":"d760b18f.5cd48","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":530,"y":620,"wires":[]},{"id":"b1ada336.61059","type":"pac-read","z":"d760b18f.5cd48","device":"c3c14c3.63f89b","dataType":"float-table","tagName":"y","tableStartIndex":"","tableLength":"","value":"y","valueType":"msg","topic":"","topicType":"none","name":"","x":350,"y":660,"wires":[["8d63cfb4.adba3"]]},{"id":"c3c14c3.63f89b","type":"pac-device","z":"","address":"172.20.1.1","protocol":"https"}]
1 Like

@Beno

How were you able to do this?

From within Node-RED;

Highlight your nodes you want to include in the flow.
Select ‘compact’ and then copy that text to the clipboard.

Then in the forums;

Click on the preformatted text icon and paste the clipboard contents in.

1 Like

@Beno
Thank you sir for taking the time to do this it is greatly appreciated

Ok @josh51 Terry and I have spent the afternoon looking at your flow and each of us have been trying to run it on our PR1s. As you know, its a bit tricky, so Terry built a flow to just test writing to a float table 500 elements of random data.

We would really like you to import this flow and give it a test.
Here is how we need it to look;

The flow I am going to paste here does NOT have the red PAC node. I need you to copy / paste your x[] node so your IP address and API key is the same.
So import the flow, copy the one pac node and connect the two wires, then deploy.
Go in to pac control debug mode and click the clear inject node, everything should stay or go to zero.
Click the 500 inject node and you should have 500 elements of random numbers.
(Least that’s how it works for me).

[{"id":"cae575d2.8c02f","type":"function","z":"4a18b8f.05d4348","name":"randomize","func":"myValues = [];\nfor(i = 0; i < msg.payload; i++) {\n    myValues.push(Math.round(Math.random()*1000));\n}\nreturn { \"payload\" : { \"xx\" : myValues }};","outputs":1,"noerr":0,"x":1130,"y":820,"wires":[["125a7976.78c8e7"]]},{"id":"125a7976.78c8e7","type":"debug","z":"4a18b8f.05d4348","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.xx","targetType":"msg","x":1360,"y":820,"wires":[]},{"id":"b29c56ad.cdf048","type":"inject","z":"4a18b8f.05d4348","name":"clear","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":950,"y":900,"wires":[["55064172.df755"]]},{"id":"55064172.df755","type":"function","z":"4a18b8f.05d4348","name":"zero-out","func":"myValues = [];\nfor(i = 0; i < 500; i++) {\n    myValues.push(0);\n}\nreturn { \"payload\" : { \"xx\" : myValues }};","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1140,"y":900,"wires":[[]]},{"id":"28c9aeff.9d0faa","type":"inject","z":"4a18b8f.05d4348","name":"500","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"500","payloadType":"num","x":950,"y":820,"wires":[["cae575d2.8c02f"]]}]

Lets know how it works for you.

@Beno @torchard
Thank you for looking it over and getting back to me I will test this out when I get back in to work tomorrow.

On a second note I was curious if there is a more efficient way to check to see if I need to run my regression besides using the inject node at a specific interval to read my variable and check to see if there is a specific integer?

@josh51 regarding your second point, I do use the same inject method you do for checking for variable changes, that’s really the best way to go about it.
One way to make it more efficient would be to increase the interval, but that comes at the cost of responsiveness, so there’s a bit of give-and-take.

1 Like

@torchard
Thanks for the input I appreciate it I’m thinking about a three second interval as I think it will be responsive enough for my needs.

@torchard @Beno

It is doing some very weird things. it will send some of the data from the random data from your flow starting at index 420 to the end index 499. Now get this the last 4 data points are from index 416 through 419. It does this ever time I use your node. I will include screen shots and the data from node red of what is going on. My Node-RED version is 1.0.3, node-red-contrib-pac version is 1.1.1 and my firmware on the PR1 is 2.0.1-b.84. Finally I will include screenshots of my Palettes that are installed

[291,325,187,93,901,139,140,366,862,306,357,665,923,206,402,41,187,826,374,959,193,448,635,409,656,135,765,441,564,877,680,573,628,662,975,321,105,794,775,422,139,942,290,846,680,582,922,238,914,171,620,729,809,27,352,12,400,230,557,179,257,389,491,89,257,115,599,900,338,900,555,792,2,784,306,225,451,59,986,541,137,539,781,567,470,878,112,763,196,666,237,725,32,228,497,529,902,720,985,269,712,101,108,220,840,154,887,694,57,978,19,402,370,143,604,417,927,458,465,313,220,704,315,498,513,571,870,747,60,330,40,113,532,602,41,884,65,783,99,755,909,400,705,555,868,684,497,984,838,251,27,415,206,548,974,592,787,200,423,848,442,166,336,31,629,971,231,834,346,888,855,874,479,270,330,679,52,396,955,741,777,525,642,130,240,708,456,946,165,180,998,967,303,218,958,690,727,499,332,820,949,591,848,436,73,689,644,166,239,121,277,167,221,85,96,923,681,174,649,138,985,553,491,336,251,436,773,423,480,463,246,703,423,729,117,916,654,91,651,250,839,53,379,626,240,148,209,852,575,503,97,440,183,833,999,582,226,194,420,232,748,697,505,994,191,262,228,684,111,501,330,836,74,691,822,761,351,715,154,894,216,994,100,240,124,937,479,917,39,478,893,603,124,920,759,642,395,610,182,673,53,702,395,94,193,724,931,238,947,963,199,802,708,552,111,821,576,603,604,764,211,778,685,189,544,697,886,391,70,974,865,702,333,477,271,131,532,925,578,856,726,962,378,923,906,460,399,373,421,623,692,308,901,964,761,689,524,371,255,287,95,609,668,271,946,752,208,934,201,421,732,968,345,224,268,66,942,693,977,853,446,833,610,492,221,175,367,541,543,665,446,433,824,752,120,750,430,266,280,472,447,906,251,185,648,209,112,920,346,743,151,863,753,0,342,544,421,998,902,93,133,256,117,47,987,981,362,929,644,29,610,520,463,698,418,642,509,778,843,244,884,389,541,874,353,171,601,89,283,435,12,343,449,573,986,339,292,920,949,617,89,333,265,899,94,876,828,390,819,926,415,723,961,209,850,439,492,964,18,639,350,961,576,653,225,713,785,649,924,129,413,955,957,7,368,170,74,262,89,19]

[120,276,135,536,333,778,136,947,421,929,400,243,376,370,834,825,355,987,895,824,543,712,376,543,56,932,38,147,162,179,48,277,300,101,159,106,489,17,962,182,547,435,295,473,899,5,945,780,893,387,233,796,395,7,972,49,561,107,686,451,896,961,299,34,84,357,645,572,71,988,698,521,346,502,443,408,988,856,640,112,694,341,706,21,813,681,266,784,623,932,494,890,955,775,565,847,737,925,624,338,691,907,648,947,443,608,419,930,428,865,973,880,3,654,41,690,526,870,66,792,951,663,783,939,788,67,88,250,114,552,360,885,403,540,792,647,782,716,179,785,766,442,340,871,485,558,193,884,510,869,326,392,389,512,39,616,424,667,162,671,803,846,513,834,161,726,645,490,394,191,84,821,139,938,618,269,787,952,173,848,721,740,412,603,527,810,481,156,664,790,344,790,241,424,269,663,972,367,332,838,934,593,204,36,339,131,78,240,790,175,694,0,776,990,730,163,960,63,81,41,101,447,943,23,82,768,353,346,56,373,570,815,769,474,415,96,474,753,87,134,916,631,344,541,960,999,593,949,294,167,259,501,176,286,918,874,76,856,567,405,438,187,667,198,640,106,634,787,121,909,806,638,355,346,83,589,381,799,781,581,732,816,216,755,168,849,591,84,806,718,814,687,492,864,282,843,931,402,847,748,237,50,607,77,442,395,685,48,630,859,668,676,724,545,155,994,115,442,493,808,681,753,258,852,809,58,251,176,782,852,822,529,427,697,259,97,653,519,904,304,547,541,302,193,915,588,124,251,402,205,216,839,826,541,792,73,486,863,387,857,491,898,321,539,704,769,791,632,519,480,624,262,845,89,811,265,412,921,701,964,809,635,399,623,674,865,162,741,812,662,515,157,539,676,808,153,106,269,164,917,771,764,86,403,365,633,82,353,820,454,878,627,326,565,93,474,382,22,478,160,994,210,152,454,167,521,570,786,799,595,45,127,51,342,806,441,144,140,901,122,744,882,762,589,388,823,344,471,720,540,776,505,805,247,340,51,492,235,846,636,487,26,997,491,502,722,320,547,523,672,504,213,681,5,844,424,146,455,501,921,400,392,787,631,282,464,488,650,532,358,474,211,23,512,517,470,534,711,359,357]

I’m trying to troubleshoot this further by using curl to post data to the table. my question is how do i post data with curl? i am able to get data with curl but not sure where i am going wrong with the body data. I get an error message: HTTP 405 Method Not Allowed.

curl -k -X POST "https://172.20.1.1/pac/device/strategy/tables/floats/x" -d [1.4,3.2,6.5] -H "accept: application/json" -H "apiKey: "

Not quite following you here… It fills all 499 indexes, but only the last 4?

@Beno
Index 0 in pac manager is the data point from index 420 in the node-red array.

Update: when i say the last 4 data points i am talking about the last 4 data points that are not 0 so index 80 through 83 on the table from pac.

I am finding the random data to be annoying.

I changed the JavaScript in the ‘randomize’ node to be the following;

myValues = [];
for(i = 0; i < msg.payload; i++) {
//    myValues.push(Math.round(Math.random()*1000));
    myValues.push(i);
    
}
return { "payload" : { "xx" : myValues }};

This results in a much cleaner output.

And the top and bottom of the table in PAC Control.


The rest of the table is all zeros

Do you have a strategy running in PAC Control?
Looks like something is over writing Node-RED.

Also, whats the debug of Node-RED show?
Here you can see mine with just the top and bottom arrays expanded.

yes there is a strategy running i just created a brand new table that is not referenced anywhere in the code

@Beno @torchard
Here is what i have been able to figure out so far. when i send 84 datapoints to the table it sends all the data no issues meaning index 0 is 0, index 1 is 1 index 2 is 2 … When i send 85 datapoints it starts over at index 0 and overwrites the data in this index. Any ideas on why it is doing this? I am having this issue weather i use node-red or curl code below. (I removed the apiKey from the string below).

curl -k -X POST "https://172.20.1.1/pac/device/strategy/tables/floats/x" -H "accept: application/json" -H "apiKey: *********************************" -H "Content-Type: application/json" -d "[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84]" 

1 Like

@josh51 thank you for doing such thorough testing and sharing the results. I am not entirely sure what the cause is and will be doing some deeper digging, but until we have a solution I have found a work-around: split the large array into smaller batches of < 85 values at a time.

image

This extra function node before the PAC write node will split any incoming array into at most 50 values per-batch, and put them into a write object for the PAC control node. Just configure the PAC node Value to msg.payload.values and put this node before it. Using this method I can easily fill a PAC array with 750 values.

[{"id":"4e6cf98.7efd608","type":"pac-write","z":"eedf3627.4e1558","device":"","dataType":"float-table","tagName":"myFloats","tableStartIndex":"","value":"payload.values","valueType":"msg","name":"","x":890,"y":580,"wires":[[]]},{"id":"35ed922f.79dd5e","type":"inject","z":"eedf3627.4e1558","name":"","topic":"","payload":"{}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":390,"y":580,"wires":[["9d20830.f596e8"]]},{"id":"9d20830.f596e8","type":"function","z":"eedf3627.4e1558","name":"0-749","func":"myVals = [];\n\nfor (i = 0; i < 749; i++) {\n    myVals.push(i);\n}\n\nreturn { \"payload\" : myVals }","outputs":1,"noerr":0,"x":510,"y":580,"wires":[["dd45d5ca.f20458"]]},{"id":"51bb2e54.94b76","type":"debug","z":"eedf3627.4e1558","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":890,"y":620,"wires":[]},{"id":"dd45d5ca.f20458","type":"function","z":"eedf3627.4e1558","name":"split into batches","func":"batchSize = 50;         // the size of each batch\ndata = msg.payload;     // data to be split into batches\nbatch = [];             // initialize the batch array\n\nstartIndex = 0;         // keep track of where to insert the data\nfor(i = 0; i < data.length; i++) {\n    batch.push(data[i]);                    // add the data to this batch\n    if((i+1) % batchSize === 0) {           // if at the end of a batch,\n        node.send( { payload : {            // send this batch\n            tableStartIndex : startIndex,\n            values : batch\n        }});\n        startIndex += batchSize;            // move the insert index by the size\n        batch = [];                         // reinitialize for the next batch\n    }\n}\n// send the last batch, if that data exists:\nif(batch.length > 0) {\n    return( { payload : {\n        tableStartIndex : startIndex,\n        values : batch\n    }});\n}","outputs":1,"noerr":0,"x":690,"y":580,"wires":[["51bb2e54.94b76","4e6cf98.7efd608"]]}]

Could you give that a test and let me know what you think?

@torchard
I did a quick test and it seems to be working i do have one question for you do you have any good documentation to explain how the return { “payload” : myVals } works? It seems to be a lot cleaner then how i write out my msg values. My biggest question would be how to use that return statement on multiple messages?