# Dht11 cannot read temp and humidity on Lora shield gps

**URL:** <https://www.thethingsnetwork.org/forum/t/dht11-cannot-read-temp-and-humidity-on-lora-shield-gps/32383>\
**Category:** Uncategorized\
**Created:** [December 4, 2019, 6:25pm UTC](https://www.thethingsnetwork.org/forum/t/dht11-cannot-read-temp-and-humidity-on-lora-shield-gps/32383 "2019-12-04T18:25:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ichsanpr](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/ichsanpr/32/25844_2.png) [@ichsanpr](https://www.thethingsnetwork.org/forum/u/ichsanpr)\
**Post date:** [December 4, 2019, 6:25pm UTC](https://www.thethingsnetwork.org/forum/t/dht11-cannot-read-temp-and-humidity-on-lora-shield-gps/32383/1 "2019-12-04T18:25:43Z")

</div>

Hi,  
Im new in this Lora Technology. Im sorry If my question was basic. so Im from Indonesia which is have a bit Lora Technology expertise.

**MY PROBLEM**  
I build a single channel gateway with rpi + Lora GPS/HAT as a gateway and arduino+Lora GPS Shield as a node. trying to transmitting the temperature & humidity using dht11. my code on this [github Lora dht11](https://github.com/ichsanpras/mylearn/blob/master/TTN_gps%26temp%20Lora). and I take the example on this web [wiki dragino](https://wiki.dragino.com/index.php?title=MyDevices)  
and will show the data humidity and temperature to cayenne mydevice.  
**my problem is** , the sensor dht11 cannot appear on the serial monitor(try on first monitoring), and in the ttn. it always nan or 0,00%.

**My Question**

- is it related with the code hex in **static uint8\_t mydata[22]**?  
`

> static uint8\_t mydata[22] = {0x06,0x67,0x00,0x00,0x02,0x68,0x00,0x03,0x88,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x65,0x00,0x00};

`  
because I take that hex from this [ttn\_mydevice](https://github.com/goodcheney/TTN_Mydevice/blob/master/GPS_Mydevice).

- is it any wrong code with the dht11 library on it ?
- if I add sensor **GY-906 Infrared Temperatur Sensor MLX90614 ESF** for contacless temperature sensor. what should I add for the code? **static uint8\_t mydata[]** is probably add again with the differen code hex ?

**Background**  
I build a monitoring and detection forest fires using Lora Technology. so Im using temperature sensor. with 2 nodes. for now I still trying to read sensor dht11 with 1 node first. if it can read and monitoring, I will trying to dual channel gateway. 🙂

please help on my project…

---

<div class="post-metadata">

**Author:** ![LoRaTracker](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/loratracker/32/48502_2.png) [@LoRaTracker](https://www.thethingsnetwork.org/forum/u/LoRaTracker)\
**Post date:** [December 4, 2019, 9:59pm UTC](https://www.thethingsnetwork.org/forum/t/dht11-cannot-read-temp-and-humidity-on-lora-shield-gps/32383/2 "2019-12-04T21:59:32Z")

</div>

Back to basics, ignore the LoRa stuff for now.

Can you confirm that, with a simple program, and no LoRa device code involved, you can read the DHT11 sensor and print the results to the serial monitor ?

---

<div class="post-metadata">

**Author:** ![ichsanpr](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/ichsanpr/32/25844_2.png) [@ichsanpr](https://www.thethingsnetwork.org/forum/u/ichsanpr)\
**Post date:** [December 4, 2019, 10:27pm UTC](https://www.thethingsnetwork.org/forum/t/dht11-cannot-read-temp-and-humidity-on-lora-shield-gps/32383/3 "2019-12-04T22:27:46Z")

</div>

Hi @LoRaTracker.  
Yes I already tried to do that. Everything normal. I think its wrong with the pin dht11 which it has a digital pin but the example to analog pin. When I tried with a simple program to run the sensor using analog pin, it can read to the serial monitor. And when I back to the code using Lora, it can’t.

---

<div class="post-metadata">

**Author:** ![cslorabox](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/cslorabox/32/35697_2.png) [@cslorabox](https://www.thethingsnetwork.org/forum/u/cslorabox)\
**Post date:** [December 4, 2019, 11:43pm UTC](https://www.thethingsnetwork.org/forum/t/dht11-cannot-read-temp-and-humidity-on-lora-shield-gps/32383/4 "2019-12-04T23:43:11Z")

</div>

Your code will only even _attempt_ to read from the DHT11 if do\_send() is called when OP\_TXRXPEND is unset. In practice, that flag can often get stuck on in LMiC for various reasons.

What sort of output are you seeing from the sketch?

Likely you should add additional logging to see when do\_send() is called at all, see which path it takes, see if your dhtTem() function is called at all, and if it exists with a success

Attempting to read from a GPS with software serial could also be causing problems, though it looks like maybe you aren’t actually calling that in the current version.

---

<div class="post-metadata">

**Author:** ![ichsanpr](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/ichsanpr/32/25844_2.png) [@ichsanpr](https://www.thethingsnetwork.org/forum/u/ichsanpr)\
**Post date:** [December 5, 2019, 3:02am UTC](https://www.thethingsnetwork.org/forum/t/dht11-cannot-read-temp-and-humidity-on-lora-shield-gps/32383/5 "2019-12-05T03:02:58Z")

</div>

Hi @cslorabox,

here is the output.

![test%20arduino](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/d/1/d127f4b4410ae444b295e24b38efb6b2aecb99f8.png) .

---

<div class="post-metadata">

**Author:** ![cslorabox](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/cslorabox/32/35697_2.png) [@cslorabox](https://www.thethingsnetwork.org/forum/u/cslorabox)\
**Post date:** [December 5, 2019, 4:11am UTC](https://www.thethingsnetwork.org/forum/t/dht11-cannot-read-temp-and-humidity-on-lora-shield-gps/32383/6 "2019-12-05T04:11:23Z")

</div>

you seem to have commented out all calls to dht.begin()

---

<div class="post-metadata">

**Author:** ![ichsanpr](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/ichsanpr/32/25844_2.png) [@ichsanpr](https://www.thethingsnetwork.org/forum/u/ichsanpr)\
**Post date:** [December 5, 2019, 4:49am UTC](https://www.thethingsnetwork.org/forum/t/dht11-cannot-read-temp-and-humidity-on-lora-shield-gps/32383/7 "2019-12-05T04:49:34Z")

</div>

in where I add that code?  
after

> #define

or in the

> void setup() {

?

---

<div class="post-metadata">

**Author:** ![cslorabox](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/cslorabox/32/35697_2.png) [@cslorabox](https://www.thethingsnetwork.org/forum/u/cslorabox)\
**Post date:** [December 5, 2019, 4:48pm UTC](https://www.thethingsnetwork.org/forum/t/dht11-cannot-read-temp-and-humidity-on-lora-shield-gps/32383/8 "2019-12-05T16:48:04Z")

</div>

Wherever you would usually put it if you were not using LoRaWAN, setup() isn’t a bad guess

---

<div class="post-metadata">

**Author:** ![swebstergeo](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/swebstergeo/32/35697_2.png) [@swebstergeo](https://www.thethingsnetwork.org/forum/u/swebstergeo)\
**Post date:** [August 15, 2020, 7:06am UTC](https://www.thethingsnetwork.org/forum/t/dht11-cannot-read-temp-and-humidity-on-lora-shield-gps/32383/9 "2020-08-15T07:06:36Z")

</div>

I’ve run in to this issue. Did you ever get it solved?

I believe the issue is caused by something relating to the following code, though I can’t be sure as I’m very new to the Arduino. dhtTem is getting called, presumably if both of LMIC.opmode and OP\_TXRXPEND are set. I’m not quite sure how to unset OP\_TXRXPEND, what further issues that might cause, or how to move the function around to avoid cases where OP\_TXRXPEND is set.

```cpp
void do_send(osjob_t* j){
    // Check if there is not a current TX/RX job running
    if (LMIC.opmode & OP_TXRXPEND) {
        Serial.println(F("OP_TXRXPEND, not sending"));
    } else {
        // Prepare upstream data transmission at the next possible time.
        dhtTem();
        //LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0);
        Serial.println(F("Packet queued"));
        Serial.print(F("Sending packet on frequency: "));
        Serial.println(LMIC.freq);
    }
    // Next TX is scheduled after TX_COMPLETE event.
}

```

---

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [August 16, 2020, 8:43am UTC](https://www.thethingsnetwork.org/forum/t/dht11-cannot-read-temp-and-humidity-on-lora-shield-gps/32383/10 "2020-08-16T08:43:52Z")

</div>

> [@swebstergeo](#):
>
> I’m not quite sure how to unset OP\_TXRXPEND

You shouldn’t. Unless you’re referring to:

> [@cslorabox](#):
>
> that flag can often get stuck on in LMiC for various reasons

Just to be clear: bugs aside, it’s set when another transmission is already scheduled, so you should not run into that condition unless you’re transmitting too much. So: just adhere to the regulations and [other limitations](https://www.thethingsnetwork.org/forum/t/limitations-data-rate-packet-size-30-seconds-uplink-and-10-messages-downlink-per-day-fair-access-policy-guidelines/1300) and you should not run into that branch of the code at all.

(Aside: note that the `LMIC_setTxData2` is commented out in your sample code. So, that code is not sending anything. Also, [it’s very unlikely](https://www.thethingsnetwork.org/forum/t/dragino-with-ultrasonic-sensor-and-ttn/38423/3) you want the `-1` in `sizeof(mydata)-1`.)
