I'm sorry I didn't mean to say that i don't want your help. I intended to say that those nodes are working right like I need them. I plan to upgrade it and make it better as I go, but I was hoping to get the switch working properly first. Since everything else is working, I wanted to leave it like it is as not to mess it up. Thanks for your help.
Hi Colin,
Thanks for your pointers. The reason cycle is not set at all is because this is unfinished. Steve wanted to see what I had in the function node.
@lesmar96 I updated that previous post.
Please read it.
Please show me the output of this debug node (a screen shot and the copied data please)
5/23/2020, 11:06:32 AMnode: 13e14267.55c63e
msg.payload : Object
object
cycleID: "undefined"
Project: "LoadNGo"
TimeStamp: "5/23/2020, 3:06:31 PM"
M1: 0
M2: 0
M3: 0
M4: 0
M5: 0
M6: 0
Flow: -133.97463989257812
Pressure: 0.007999999448657036
Temp: 65.84
I do not understand yet what is wrong with the set & compile nodes. But that is okay.
I am reading and researching your suggestions.
You are making an object out of strings instead of making an object.
This is how I would do this...
- No delay (causes inconsistent data as 5s later the machine might have stopped!)
- 1 function that does EXACTLY the same but using objects instead of concatenating strings to make JSON then converting to an object
Here are the 2 functions....
[{"id":"3000cec0.1c2dc2","type":"function","z":"80a62cbb.ffa6a","name":"Compile_message","func":"\n//use the consistent values sent in when the sample was taken\nmsg.payload = {\n cycleID: msg.cycleID,\n Project: msg.ProjectName,\n TimeStamp: msg.datetime,\n M1: msg.manifold1,\n M2: msg.manifold2,\n M3: msg.manifold3,\n M4: msg.manifold4,\n M5: msg.manifold5,\n M6: msg.manifold6,\n Flow: msg.flow,\n Pressure: msg.pressure,\n Temp: msg.tempF\n}\n\nreturn msg;\n\n","outputs":1,"noerr":0,"x":550,"y":460,"wires":[["ead8fc11.ac877"]]},{"id":"e1860782.2d3118","type":"function","z":"80a62cbb.ffa6a","name":"Machine_Running?","func":"//get all data in one place & pass it on to next node\n//this ensures data is consistent & unchanged before sending to database\n//i.e. any change in the GLOBALS will not affect these samples\n\nmsg.ProjectName = \"LoadNGo\";\nmsg.cycleID = global.get(\"cycleID\");\nmsg.datetime = global.get('datetime') || 0;\nmsg.flow = global.get('flow') || 0;\nmsg.pressure = global.get('pressure') || 0;\nmsg.tempF = global.get('TempF') || 0;\nmsg.manifold1 = global.get('manifold1') || 0;\nmsg.manifold2 = global.get('manifold2') || 0;\nmsg.manifold3 = global.get('manifold3') || 0;\nmsg.manifold4 = global.get('manifold4') || 0;\nmsg.manifold5 = global.get('manifold5') || 0;\nmsg.manifold6 = global.get('manifold6') || 0;\n\nvar manifoldON;\n\nif (msg.manifold1 || msg.manifold2 || msg.manifold3 || msg.manifold4 || msg.manifold5 || msg.manifold6) {\n manifoldON = true;\n}\n\nif (msg.manifoldON || (msg.pressure > 0)) {\n return msg;\n}\n\nreturn null; //halt flow","outputs":1,"noerr":0,"x":330,"y":460,"wires":[["3000cec0.1c2dc2"]]}]
This is the final output (ignore the faked values - the structure is the same as what you had - thats whats important)
EDIT:
The logic in "Machine_running" is this...
"If any manifold == true OR pressure is > 0 THEN proceed"
if (msg.manifoldON || (msg.pressure > 0)) {
return msg;
}
to
If you need "If any manifold == true AND pressure is > 0 THEN proceed" change the below...
if (msg.manifoldON && (msg.pressure > 0)) {
return msg;
}
EDIT2:
While testing, in the function Machine_running, I was returning msg at the end - I've updated the flow export above to return null
Thanks Steve,
That makes sense. Am I correct that this functions basically the same as I had it, but this is definitely neater?
But my main question still remains unanswered. This has been puzzling me for several days. Let me keep thinking though.
EDIT: I see your updated post. We are getting closer. Thanks!!
Yes with the benefit of "sampling" the data at one place to ENSURE consistency in your data
Neater? urm yes, but also, that is actually how you SHOULD make JS objects
What is that? Are you refering to the required go/no-go logic?
does this help...
OK. so I understand your AND & OR functions. that all makes sense to me, but apparently I am not being clear. This is where I am puzzled.
We must return msg the entire length of the cycle that this machine runs. if (msg.manifoldON && (msg.pressure > 0)) {
will signal that the cycle has started. The cycle must continue to run until pressure = 0 no matter the status of the manifold (the manifolds will turn on and off during the cycle but the pump will continue to run). That is why neither OR or AND is satisfactory.
Like this?
in the function "Machine_running"
//get all data in one place & pass it on to next node
//this ensures data is consistent & unchanged before sending to database
//i.e. any change in the GLOBALS will not affect these samples
msg.ProjectName = "LoadNGo";
msg.cycleID = global.get("cycleID");
msg.datetime = global.get('datetime') || 0;
msg.flow = global.get('flow') || 0;
msg.pressure = global.get('pressure') || 0;
msg.tempF = global.get('TempF') || 0;
msg.manifold1 = global.get('manifold1') || 0;
msg.manifold2 = global.get('manifold2') || 0;
msg.manifold3 = global.get('manifold3') || 0;
msg.manifold4 = global.get('manifold4') || 0;
msg.manifold5 = global.get('manifold5') || 0;
msg.manifold6 = global.get('manifold6') || 0;
var manifoldON;
var running = !!global.get("running");
if (msg.manifold1 || msg.manifold2 || msg.manifold3 ||
msg.manifold4 || msg.manifold5 || msg.manifold6) {
manifoldON = true;
}
//if both are true, start running
if (manifoldON && msg.pressure){
running = true;
}
//if both are false, stop running
if (!manifoldON && !msg.pressure) {
running = false;
}
global.set("running", running);
if (running) {
return msg;
}
return null; //halt flow
play with that logic to suit
Great. Thanks! I knew there was some way and I just couldn't think of it. I will be able to take care of it from there. Thanks!