flow.set("payload","msg.payload.payload");
flow.set("humidity","msg.payload.humidity");
var date = new Date().getTime();
msg.topic= "insert into sensor(temp, humidity, date) values('"+msg.payload.payload+"', '"+msg.payload.humidity+"', '"+date+"')";
return msg;
this is my function code
i receive data to {"_msgid":"81665f152edd9336","payload":"25.20","topic":"rpi-dht22","humidity":"39.30","isValid":true,"errors":2,"sensorid":"dht22"}
but saw in database undefined, undefined, 1636534958644
what is problem?
You have 2 problems with the function node.
Firstly you are inserting strings into the flow
context rather than the values from the incoming message, you should not be wrapping the value argument in quotes.
Secondly you have an extra payload
in the msg
object keys.
It should probably look like this:
flow.set("payload",msg.payload);
flow.set("humidity",msg.humidity);
var date = new Date().getTime();
msg.topic= "insert into sensor(temp, humidity, date) values('"
+ msg.payload + "', '"
+ msg.humidity + "', '"
+ date + "')";
return msg;