msg.topic = "insert into metertable values ('','','"+msg.payload+"','"+msg.payload+"');"
return msg;
While the data is different and its insert the same values on both column in database.
I also tried to create variable and save coming data but its showed undefined.
1 Like
There is a recipe in the cookbook that describes how to combine different streams of messages into a single message - Create a single message from separate streams of messages : Node-RED
But afer joining how can i insert these values separatly with their repective column into mysql database ??
I suggest you take it one step at a time.
Get the messages joined into one. Pass that to a debug node and confirm you have all the data from both messages you need.
You can then construct a query that does the insert taking the values from the message.
1 step was done and its working.
Then how i can insert into database ??
What exactly does the combined message now look like?
How have you configured the SQL node?
And what does your database table look like? What columns has it got and which value do you want to be inserted in which column?
i want to insert into two column
Flowrate
Totalizer
These two values are in join node.
Here is a function to insert into database
var flow = msg.payload[0];
var totaliz = msg.payload[1];
msg.topic = "insert into metertable values ('','','"+flow+"','"+totaliz+"');"
return msg;
but its now working.
Change that for:
var flow = msg.payload["esp32/Flow"];
var totaliz = msg.payload["esp32/Totalizer"];
This is because your msg.payload
in an object not an array, and uses the original messages' topic
property as the key to the corresponding value.
Thanks alot it working now bye repalce this "["esp32/Flow"];".
I have an another problem is that i use my sql data database auto function of current_timestamp() for time reading but its show "0000000000" as you see in screenshot.
Looks like your database default is not working or you are passing in a null time by including all four parameters in sql. "insert into metertable values ('','','"+flow+"','"+totaliz+"');"
Test db by inserting a record manually. Does it get a timestamp?
Fix that or
Create a timestamp and include in your insert statement.
jbudd
17 July 2021 18:12
13
Does INSERT INTO metertable (Flowrate, Totalizer) VALUES ( blah, blah ) create a record with the default timestamp value?
system
Closed
15 September 2021 18:13
14
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.