Hi, I am completely new to Node-RED but I love it already.
I have an arduino board connected to my raspberry pi, I need to send a one character output from the pi to the Arduino based on another input that comes from a tape dispenser.
Input ----------------- Raspberry Pi --------[read] --- if [variable}-----payload ------ Arduino.
Now I have different inputs coming from my tape dispenser and they are all in the form of @number. I want to trigger a different payload for each possible input.
The total of inputs are 13
The outputs for the arduino are a 1 character payload [1/2/3/4/5/6/7/8/9/a/b/c/s]
I don't know if a single function can handle it or if I need different functions.
switch (msg.payload){
case msg.payload=="@1T @1XR @1Y198":
msg.output = "1";
break;
switch (msg.payload){
case msg.payload=="@1T @1XR @1Y163":
msg.output = "2";
break;
But it does not work. all the message gets through unfiltered no matter what I do.
I also tried with
var topic=msg.topic;
if (topic=="@1Y198"){
return [null,1]
}
var topic=msg.topic;
if (topic=="@1T"){
return [null]
}
var topic=msg.topic;
if (topic=="@1XR"){
return [null]
}
Even in this case the message goes all the way through unfiltered.
No Idea how to solve this.
Put a debug node before and after the switch node and see what it being output - i would guess it is probably not a fully formed message depending on how you got it into Node Red in the first place i.e. what is the message flow - how do you interface to the Rpi ports to get the data ? Maybe past your whole flow ?
Also you have the syntax of the switch statement completely wrong, go back and look at the example @Steve-Mcl posted and you will see that yours is not the same.
Hi, I tried with that syntax but the editor was complaining about the "@" that was unexpected.
The debug node tells me that the output (after the function) is @1T@1XR@1Y198
Node red tells me:
Unexpected '@'.
Expected an identifier and instead saw ':'
if I quote everything like this:
case: "@1T@1XR@1Y10"
i get
Expected an identifier and instead saw ':'.
Expected ':' and instead saw '@1T@1XR@1Y10'.
Missing ':' on a case clause.
Now you have lost the quotes, that is the one that you did have right the first time case: "@1T @1XR @1Y10"
Strictly there should be a ; on the end but a ; on the end of a line is often optional.