i got 2 nodes fetching some mqtt data, some temperature and humidity readings. Im trying to pass that info to a sqlite node. On that node i have the following code:
var newMsg = {
"topic": "INSERT INTO ambiente VALUES (null, #thisshouldbetemperature, #thisshouldbehumidity, date('now'), time('now') )"
}
return newMsg;
I try to use a join node but didnt make the work. So, what is the correct way to pass both msg.payload to that function? Thanks!
The join
node is the correct way to combine the 2 incoming messages. You should use the manual mode and configure it to create a key value object something like this.
The problem is that your function node is ignoring the incoming data and creating a new message with just a topic set.
The fix for the function node is:
msg.topic = "INSERT INTO ambiente VALUES (null, " + msg.payload.temperature + ", " + msg.payload.humidity + " , date('now'), time('now') )";
return msg;
This will just update the msg.topic
and leave the incoming msg.payload
intact. This assumes that the MQTT messages arrive on topics temperature
and humidity
.