# Temp and Hum store in MySQL

**URL:** <https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431>\
**Category:** General\
**Created:** [31 January 2019 12:35 UTC](https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431 "2019-01-31T12:35:34Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![tamasszabo60](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@tamasszabo60](https://discourse.nodered.org/u/tamasszabo60)\
**Post date:** [31 January 2019 12:35 UTC](https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431/1 "2019-01-31T12:35:34Z")

</div>

Hello!

I'm new in Node-RED, I made flow to storing 2 pcs MQTT msg to MySQL, it is working fine. But in sql rows sometimes 0, sometimes not 0. I think my function can't sending 2 pcs data in one time. I want to know how can I storing 2 pcs msg in one time.

 ![nodered1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/ea7aa88091f39d7e95c9f8e06f33eb56cb6f824a.jpeg)

Thanks a lot!

---

<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:** [31 January 2019 12:44 UTC](https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431/2 "2019-01-31T12:44:12Z")

</div>

So you are either sending a line with office temperature  
`[MQTT - Office Temperature]` - `[Data To SQL]` - `[Mysql DB]`  
or a line with humidity  
`[MQTT- Office Humidity]` - `[Data To SQL]` - `[Mysql DB]`

If you want to end up with one line you will have to look at combining the data. One way you can do this is by using the `join` node, before your function node(s)

---

<div class="post-metadata">

**Author:** ![Robbo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/robbo/32/4491_2.png) [@Robbo](https://discourse.nodered.org/u/Robbo)\
**Post date:** [31 January 2019 13:41 UTC](https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431/3 "2019-01-31T13:41:35Z")

</div>

If the final outcome is too Graph the results you may want to look at InfluxDB instead with Grafana as the graphing tool. InfluxDB is a time based DB, so is a little more efficient on this type of data.

---

<div class="post-metadata">

**Author:** ![tamasszabo60](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@tamasszabo60](https://discourse.nodered.org/u/tamasszabo60)\
**Post date:** [31 January 2019 15:53 UTC](https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431/4 "2019-01-31T15:53:49Z")

</div>

If I using join node, I think the best is combine each msg.payload with a key/value. But I don't know how to modify my sql function.

Now my function is:

var newMsg = { payload: msg.payload };  
newMsg.topic="insert into iot\_data (temp, location) values ("+newMsg.payload+","Office")";  
return newMsg;

From the join node I have this object:  
{ /Office/DHT22/Temperature: "18.50", /Office/DHT22/Humidity: "33.50" }

---

<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:** [31 January 2019 16:34 UTC](https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431/5 "2019-01-31T16:34:40Z")

</div>

> [@tamasszabo60](#):
>
> { /Office/DHT22/Temperature: "18.50", /Office/DHT22/Humidity: "33.50" }

This page shows you how you can use the debug to identify and copy the path to any part of the message [Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [31 January 2019 19:35 UTC](https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431/6 "2019-01-31T19:35:54Z")

</div>

What software are you using on the device that is sending the MQTT msg's? Since the sensor is a DHT22, it reads both the temperature and humidity at the same time. Why not change that software to send both in one MQTT msg?

---

<div class="post-metadata">

**Author:** ![tamasszabo60](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@tamasszabo60](https://discourse.nodered.org/u/tamasszabo60)\
**Post date:** [31 January 2019 19:53 UTC](https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431/7 "2019-01-31T19:53:50Z")

</div>

I'm using NodeMCU with ESPEasy firmware.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [31 January 2019 22:27 UTC](https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431/8 "2019-01-31T22:27:08Z")

</div>

Ok, this goes outside the bounds of Node-red but here is what to do. In ESPeasy:

1. go to the `Tools` tab, click the `Advanced` button and check the box `Rules` then hit `Submit` at the bottom. This will give you an new tab called `Rules`
2. go to the `Devices` tab and edit your DHT22 device (Let's assume it is `DHT22`)
3. note the name and the `Values` names (Lets assume they are `Temp` and `Humi`
4. uncheck `Send to Controller`
5. go to the `Rules` tab and enter the following:

```auto
on dht22#Temp do
   Publish %sysname%/what_ever_else_makes_up_your_topic,"T":[dht22#Temp],"H":[dht22#Humi]
endon

```

1. Press the `Submit` at the bottom of the screen and you are done. You will now get one MQTT msg with both readings.

---

<div class="post-metadata">

**Author:** ![tamasszabo60](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@tamasszabo60](https://discourse.nodered.org/u/tamasszabo60)\
**Post date:** [1 February 2019 12:47 UTC](https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431/9 "2019-02-01T12:47:41Z")

</div>

In this rules what intervals sending the msg? How can change?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [1 February 2019 12:55 UTC](https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431/10 "2019-02-01T12:55:06Z")

</div>

The inteval is detemined by what you set for the device. Since you already have the device set up to send data at an interval, that is what it will use. The one thing is to uncheck the `Send to Controller' so you won't get three mqtt msgs when the interval happens

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [1 February 2019 13:33 UTC](https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431/11 "2019-02-01T13:33:25Z")

</div>

Just be careful not to read from a DHT22 too rapidly as it takes some appreciable time to read. Doing it too often will result in errors. Personally, I wouldn't read it less than 5-10 sec apart but I can't remember the actual limitation as I stopped using these sensors a long time ago. My own sensor platforms produce readings about every 30-60 seconds, anything less is rarely really useful, especially with old sensors like the DHT's.

---

<div class="post-metadata">

**Author:** ![tamasszabo60](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@tamasszabo60](https://discourse.nodered.org/u/tamasszabo60)\
**Post date:** [1 February 2019 13:45 UTC](https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431/12 "2019-02-01T13:45:46Z")

</div>

Ok, working nice! 🙂 Thank for everybody!!!!!

 ![iotdatatables](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e293d7ab63a425bf0b40e916de5883c9ca3aa10e.jpeg)

---

<div class="post-metadata">

**Author:** ![Meriam](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@Meriam](https://discourse.nodered.org/u/Meriam)\
**Post date:** [14 February 2021 12:54 UTC](https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431/13 "2021-02-14T12:54:46Z")

</div>

hello, can you please send to me your flow

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [14 February 2021 13:33 UTC](https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431/14 "2021-02-14T13:33:01Z")

</div>

@Meriam Welcome to the forum. You might have to wait a while since the original poster hasn't been active since the last post on this thread two years ago.

It would be best if you open a new thread showing what you have already tried and explaining what your issue is.

I will close this thread now.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [14 February 2021 13:33 UTC](https://discourse.nodered.org/t/temp-and-hum-store-in-mysql/7431/15 "2021-02-14T13:33:08Z")

</div>


