# Database not receive the data when one sensor stops

**URL:** https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824
**Category:** General
**Created:** [11 February 2019 10:41 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824 "2019-02-11T10:41:05Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)
#### Post date: [11 February 2019 10:41 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/1 "2019-02-11T10:41:05Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [11 February 2019 10:56 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/2 "2019-02-11T10:56:03Z")

</div>

LMGTFY [https://stackoverflow.com/questions/12670979/mysql-insert-two-fields-only](https://stackoverflow.com/questions/12670979/mysql-insert-two-fields-only)

---

<div class="post-metadata">

### Author: ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)
#### Post date: [11 February 2019 11:11 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/3 "2019-02-11T11:11:28Z")

</div>

i see that

```auto
$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:

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

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [11 February 2019 11:25 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/4 "2019-02-11T11:25:47Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)
#### Post date: [11 February 2019 13:43 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/5 "2019-02-11T13:43:44Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [11 February 2019 13:47 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/6 "2019-02-11T13:47:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)
#### Post date: [11 February 2019 13:56 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/7 "2019-02-11T13:56:25Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [11 February 2019 13:57 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/8 "2019-02-11T13:57:07Z")

</div>

I meant what error did you get

---

<div class="post-metadata">

### Author: ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)
#### Post date: [11 February 2019 14:07 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/9 "2019-02-11T14:07:27Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [11 February 2019 14:09 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/10 "2019-02-11T14:09:16Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [11 February 2019 14:11 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/11 "2019-02-11T14:11:02Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [11 February 2019 14:14 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/12 "2019-02-11T14:14:03Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)
#### Post date: [11 February 2019 14:15 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/13 "2019-02-11T14:15:59Z")

</div>

> [@knolleary](#):
>
> 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

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.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [11 February 2019 14:18 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/14 "2019-02-11T14:18:04Z")

</div>

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

---

<div class="post-metadata">

### Author: ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)
#### Post date: [11 February 2019 14:19 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/15 "2019-02-11T14:19:09Z")

</div>

> [@Colin](#):
>
> Did our posts cross? Use the timeout option.

can send the picture of icon of timeout icon?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [11 February 2019 14:20 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/16 "2019-02-11T14:20:21Z")

</div>

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

---

<div class="post-metadata">

### Author: ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)
#### Post date: [11 February 2019 14:21 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/17 "2019-02-11T14:21:34Z")

</div>

I´m testing the suggestion

---

<div class="post-metadata">

### Author: ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)
#### Post date: [11 February 2019 14:21 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/18 "2019-02-11T14:21:53Z")

</div>

I´m testing the suggestion

---

<div class="post-metadata">

### Author: ![smalhao](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@smalhao](https://discourse.nodered.org/u/smalhao)
#### Post date: [12 February 2019 09:34 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/19 "2019-02-12T09:34:48Z")

</div>

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?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4e18f1d6696bfb201871a09ae76bfad990953a49.png)

the word Metros is equal a meters

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [12 February 2019 10:06 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/20 "2019-02-12T10:06:44Z")

</div>

What data type is that column in the database?

[Next page](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824.md?page=2)
