Database not receive the data when one sensor stops


#1

I have a problem in the code, that is, when the data sensor is sent, the database is not given the data of the other two sensors, the idea was when one sensor stops and the other two continue to send the data but what stopped you should send a null to the database so that we can see that the sensor is in trouble
my command to the database is as follows:

var newmsg=new Date().toString();
msg.topic="INSERT INTO sensores VALUES ('"+ new Date().toString() +"','"+ msg.payload["ns=2;s=SensorIndutivo"].toFixed(1) +"','"+ msg.payload["ns=2;s=LM335"].toFixed(2) +"','"+ msg.payload["ns=2;s=LM35"].toFixed(2) +"')";
return msg;

my question is if there is a command in mysql that places the value of each sensor in a particular column


#2

LMGTFY https://stackoverflow.com/questions/12670979/mysql-insert-two-fields-only


#3

i see that

$query = mysql_query("INSERT INTO table VALUES('','$id')")

in the $id site I put the msg.payload ["n = 2, s = LM335"] for example? like this:

INSERT INTO table (Timestamp, Meters, LM335 Sensor, LM35 Sensor) VALUES (' ','"+$msg.payload ["n = 2, s = LM335"]+"');

#4

Please don't lose data when you are saving it by using toFixed(), it doesn't make any difference to the amount of space it takes in the database and you are losing information that might become useful at some point in the future. If you don't want to see the extra digits when it is displayed then the time to round it is when you display it.
For example, suppose at some time you wanted to do some statistical analysis of the data, the lost precision could well become important then.

To answer your question look up the mysql insert statement and you will quickly find the answer.


#5

i've tried some mysql insert but no one maked what i want, can help me width the command?


#6

What happened when you tried the sql statement in your first post in this thread when they were not all available?


#7

MySQL statement put all values ​​of sensors in database, but if one sensor stops and does not send the data, the database does not receive the data of the other sensors in this case have more 2 sensors


#8

I meant what error did you get


#9

i do not have a error, only the database not receive data if one sensor stops send data, the others sensors don't send the data to database, is necessary the 3 sensors works all the same time, and what i want is if one of them stops working the others 2 sensors should be send the data to database


#10

So where in the flow does the problem arise? Are you sending a query to the database at all? If not why not? Put debug nodes in the flow to find where it stops.


#11

The problem is the Join node that is expecting 3 messages to arrive before sending on the combined single message. If one of your sensors stops sending data, the Join node will sit waiting for it to arrive before sending anything on - so you don't get anything in the database.

Hopefully that clears up the root issue here.

I don't immediately have a suggestion for fixing that, other than changing the whole approach of your flow


#12

Use the timeout option in the join node so that if it gets one or two but no more for a time then it will send what it has anyway.


#13

Thanks for your response, is that my problem because the join expects 3 messages , if one of them stops, the Join waits until get the 3 messages, if i coud separate the array throught a function and them sending each value, but i think is not possible do that.


#14

Did our posts cross? Use the timeout option. That is as well as the three message spec, not instead of.


#15

can send the picture of icon of timeout icon?


#16

Look at the config you have entered for the Join node, there is an option to specify a timeout.


#17

I´m testing the suggestion


#18

I´m testing the suggestion


#19

I used the tip of the timeout and when I turn off the sensor count meters, it in the database is so undefined, which is more or less what I wanted as shown in the figure as well as I took the toFixed following the advice, however I would like ask if there is a way to send eg a way to show that it is stopped, via text eg STOP?

the word Metros is equal a meters


#20

What data type is that column in the database?