BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

How to insert data into the correct field of mysql database

#1

Hello, I am trying to insert sensor data from a blynk server to a mysql database, but i am unable to insert multiple data in the correct field. i am using node red to do so here is what I have done.

from what you see i am trying to do it with 2 sensor data but i am unsuccessful.
Here is what i have in my function node

msg.topic="INSERT Into fire_contents (Temperature1) values(?)";
msg.payload=[msg.payload];
return msg;

it only works for a single data but when it comes down to multiple data i have a problem

0 Likes

#2

There aren’t many Node-Red users here, and this is a bit of a specialist question anyway.
It’s a very long time since I’ve done anything with MySQL, and that was before I discovered Node-Red.
I think you’re more likely to work-out a solution by googling for answers about Node-Red and MySQL.

Actually, from your flow it’s not possible to tell where your data is coming from and what format it’s in.
The input into the Insert_Func node appears to have two connectors going into it, but it’s a bit hard to tell. Node-Red works as a sequential processing engine, so feeding two values into a node will result in them being treated as separate events. This means they won’t get written into the same record of your database. Unless of course you can store a pointer to the record and update the second field of the database record with the second value as a separate operation.

If you want to feed a single payload into a node with multiple values then it needs to be an array, or separate values on different elements of the payload.
Some of the Node-Red help files have examples of this, and there are some good tutorials out there.
If your values are arriving at different times then you may need to store one as a variable, then retrieve and process it when your other value arrives.
Sorry I can’t be more specific, but without knowing more about your data sources and what you’re trying to achieve it’s difficult to advise.

Pete.

0 Likes

#3


so this is where my data is coming from

0 Likes

#4

i want to create a graph that will stream data and show previous data (the data stored in the database).

0 Likes

#5

There are quite a few different scenarios that you could be using with your database…

Different tables for Temp and Humidity.
One table with different fields for Temp and Humidity.

If it’s the latter then you could be trying to write Temp and Humidity into the same record at the same time, or at different times by using the record pointer.

Which are you doing?

Pete.

0 Likes

#6

It is the latter. Pete, i think the issue has been resolved thanks for your input. I used a join node to send all the data then into the function node then i used a function to separate the data (variable_name.split()) then i wrote the insert query with the field columns and the values i want to insert and finally the data was inserted into the database after it left the function node into the mysql node.

1 Like