# 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:** 17
**Page:** 2

<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 10:32 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/21 "2019-02-12T10:32:21Z")

</div>

I set the all columns to VARCHAR (255)

---

<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:46 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/22 "2019-02-12T10:46:03Z")

</div>

In that case put a Function node after the Join node that checks the values and adds in any missing ones with whatever value you want.

---

<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 14:32 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/23 "2019-02-12T14:32:33Z")

</div>

I make this, but the sensor is always ON, how make when the sensor not count meters pass to OFF state?

```auto
[{"id":"9c5ae5dc.8b7f08","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"1f6e701c.af967","type":"function","z":"9c5ae5dc.8b7f08","name":"","func":"if (msg.payload[\"n=2;s=SensorIndutivo\"] === msg.payload[\"n=2;s=SensorIndutivo\"]-1){\n msg.color = \"OFF\";\n\n}\nelse{\n msg.color = \"ON\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":308,"y":91.00000190734863,"wires":[["d037f44c.7ee6c8"]]},{"id":"d037f44c.7ee6c8","type":"ui_text","z":"9c5ae5dc.8b7f08","group":"3f8269da.fa4936","order":2,"width":0,"height":0,"name":"","label":"Sensor State","format":"{{msg.color}} ","layout":"row-spread","x":644.0000076293945,"y":92.00000095367432,"wires":[]},{"id":"9d8e7de6.bb29d","type":"link in","z":"9c5ae5dc.8b7f08","name":"Sensor Status In Indutive Sensor","links":["9b2b6965.f7a918"],"x":124.30000400543213,"y":89.00000190734863,"wires":[["1f6e701c.af967"]]},{"id":"3f8269da.fa4936","type":"ui_group","z":"","name":"Station1","tab":"d59368e5.9adfe8","disp":true,"width":"6","collapse":false},{"id":"d59368e5.9adfe8","type":"ui_tab","z":"","name":"Monitoring Sensors Dasboard","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<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 15:37 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/24 "2019-02-12T15:37:16Z")

</div>

Can you explain in words what the function is supposed to do? I thought you were wanting to write to the database.

---

<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 15:50 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/25 "2019-02-12T15:50:07Z")

</div>

> [@Colin](#):
>
> Can you explain in words what the function is supposed to do? I thought you were wanting to write to the database.

What I want to do is to have an ON and OFF message on the dashboard that indicates that the sensor is active or inactive I want the function to do, but I think I'm not programming the function well

---

<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 15:59 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/26 "2019-02-12T15:59:43Z")

</div>

> [@smalhao](#):
>
> What I want to do is to have an ON and OFF message on the dashboard

OK, I thought you wanted to get that information into the database. In that case put a debug node showing what is coming in through the link node in the flow.

---

<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 16:11 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/27 "2019-02-12T16:11:17Z")

</div>

> [@Colin](#):
>
> OK, I thought you wanted to get that information into the database. In that case put a debug node showing what is coming in through the link node in the flow.

in the inject or the subscribe?

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

---

<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 16:22 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/28 "2019-02-12T16:22:32Z")

</div>

I put a debug in each one and the result is this:

```
12/02/2019, 16:20:28[node: Metros](http://10.6.4.101:1880/#)ns=2;s=SensorIndutivo : msg : Object
   { topic: "ns=2;s=SensorIndutivo", payload: 246.61502330679875, _msgid: "a370e17d.7df2b", serverTimestamp: "2019-02-12T16:08:22.474Z", serverPicoseconds: 481300000 … }
 
12/02/2019, 16:20:28[node: 51c28584.261b8c](http://10.6.4.101:1880/#)ns=2;s=SensorIndutivo : msg.payload : number
 0
```

---

<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 16:28 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/29 "2019-02-12T16:28:06Z")

</div>

Has this question got anything to do with the title of this thread? It might be better to start a new thread. You can use a Trigger node configured to send ON each time a value comes in, but if no input occurs for a certain time then it sends OFF.

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

---

<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 16:50 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/30 "2019-02-12T16:50:19Z")

</div>

> [@Colin](#):
>
> Has this question got anything to do with the title of this thread? It might be better to start a new thread. You can use a Trigger node configured to send ON each time a value comes in, but if no input occurs for a certain time then it sends OFF.

I tried to use the trigger but it is not using well, maybe it is better to start another topic

---

<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 17:10 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/31 "2019-02-12T17:10:12Z")

</div>

The trigger needs to go before the join node, one on each signal you want to check is still coming in.

---

<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: [13 February 2019 15:05 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/32 "2019-02-13T15:05:02Z")

</div>

Can you make a schematic with the connection, now i´m confuse, because yesterday you tells me that:  
The trigger needs to go before the join node, one on each signal you want to check is still coming in.

---

<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: [13 February 2019 15:56 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/33 "2019-02-13T15:56:33Z")

</div>

The trigger is in the right place. The join and the trigger must both come from the sensor.

---

<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: [13 February 2019 16:21 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/34 "2019-02-13T16:21:58Z")

</div>

Also can you decide which thread you are using please.

---

<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: [14 February 2019 09:56 UTC](https://discourse.nodered.org/t/database-not-receive-the-data-when-one-sensor-stops/7824/35 "2019-02-14T09:56:54Z")

</div>

I use this thread. I testing another way for my problem but i still in the same, the way i´m used is this:

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

My function is programmed like this:

```auto
if (typeof msg.payload === 'number') {
    msg.payload = true;
} else {
    msg.payload= false;
}
return msg;

```

When I run the program this gives me the following values ​​of msg.payload:

```auto
14/02/2019, 09:45:01[node: test function](http://10.6.4.101:1880/#)ns=2;s=SensorIndutivo : msg.payload : boolean
true

14/02/2019, 09:45:01[node: value received](http://10.6.4.101:1880/#)ns=2;s=SensorIndutivo : msg.payload : number
32.82964323001333

```

in the dasboard the led when it is true is green but when the sensor stops sending data it does not turn red (value false). The msg.payload of value received when sensor stops not send any value and not turn to red.

---

<div class="post-metadata">

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

</div>

Moved to [Show if sensor is ative or inactive](https://discourse.nodered.org/t/show-if-sensor-is-ative-or-inactive/7957/2)

---

<div class="post-metadata">

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

</div>



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