User error, coding error between Function and SQlite nodes no

#1

Hi,

I'm sure this is something I am doing wrong.

I run a query from a function node against a SQLite node passing data in the msg.topic. The result is returned in the msg.payload.

I now want to use that information to run a second query, and also to also power up a Gpio pin. The gpio pin wants a 1 sent to it using the msg.payload. so the first command I run is msg.topic = msg.payload so I have backed up all the data from the sqlread into the topic, then I can later set msg.payload to 1 and the gpio activates the pin, so far it works.

A case statement splits the two msg parts onto two different outputs, first one for the gpio pin and the second for the next sql insertion. The gpio one work ok, it shows ok in the debug, ie payload of 1.

msg : Object
object
_msgid: "b5b249d8.ff6e48"
payload: 1

the sql command however does not seem to run, it also does not show anything in the debug statement, tried swapping the two ports on the case statement and changing the wires to match, and the same issue occurs, the gpio work and the sql does not run.

the case statement reads..

switch (gatestatus) { // open or close the gate as appropriate
case false:
msg.payload = 0 ; // close the gate
return [null, msg.topic]; // return msg;
break;
case true:
msg.payload = 1 ; // open the gate
return [msg, msg.topic]; // return msg;
break;
default: // if we are here we have reached an unforeseen problem set to 0 to close gate
msg.payload = 0;
return [null, msg.topic]; // return msg;
break;
}
return msg.topic, msg.payload 
0 Likes

#2

Couple things,

  1. when adding code in a topic, surround it with three tic's (```) or select the lines and press the </> icon. That will keep it's formatting.
  2. You should go read https://nodered.org/docs/writing-functions and look at your function again. The second line of the write up will be of importance to you.
0 Likes

#3

Thanks, will have a look at that page.

Also put the three ticks around the code as suggested.

0 Likes