Basic 2 ... how to check if two sensed values are greater than ...

by 01:32 0 commenti


// if the variable current_input1 exists it get the current values 
// otherwise it sets it to 0
var current_input1 = context.get("store_of_current_input1") || 0;
// if the variable current_input2 exists it get the current values 
// otherwise it sets it to 0
var current_input2 = context.get("store_of_current_input2") || 0;

// if the current message is of topic input1
if (msg.topic === "input1"){
    // set the variable current_input1 to the value in the 
    //msg.payload
    current_input1 = parseInt(msg.payload);
    // update the value of  the variable store_of_current_input1 
    //to the value of  current_input1
    context.set(("store_of_current_input1"),current_input1);

}

// if the current message is of topic input2
if (msg.topic === "input2"){
    // set the variable current_input2 to the value in the 
    //msg.payload
    current_input2 = parseInt(msg.payload);
    // update the value of  the variable store_of_current_input2  
    // to the value of  current_input2
    context.set(("store_of_current_input2"),current_input2);

}
  
// check if the condition holds

if (current_input1>10 && current_input2>10 ){
    msg.payload="alto";
}
else{
    msg.payload="basso";
}
return msg;




[{"id":"1b3c741.5f3e88c","type":"function","z":"967e1482.589018","name":"","func":"var current_input1 = context.get(\"store_of_current_input1\") || 0;\nvar current_input2 = context.get(\"store_of_current_input2\") || 0;\n\nif (msg.topic === \"input1\"){\n    current_input1 = parseInt(msg.payload);\n    context.set((\"store_of_current_input1\"),current_input1);\n\n}\n\nif (msg.topic === \"input2\"){\n    current_input2 = parseInt(msg.payload);\n    context.set((\"store_of_current_input2\"),current_input2);\n}\n    \n\n\nif (current_input1>10 && current_input2>10 ){\n    msg.payload=\"alto\";\n}\nelse{\n    msg.payload=\"basso\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":369,"y":364,"wires":[["ea4b7c90.e24d7"]]}]

andrea

Developer

Cras justo odio, dapibus ac facilisis in, egestas eget quam. Curabitur blandit tempus porttitor. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

0 commenti:

Posta un commento

Nota. Solo i membri di questo blog possono postare un commento.