My Chinese ESP32 + SX1276 board + DHT11 connected to The Things Network – #2

Time for part 2 of the post about getting the “cheap” Chinese ESP32 + SX1276 board connected to The Things Network.

The picture in this and the other post shows the board with a DHT11 temperature and humidity sensor already connected. I stopped using the small case that was on sale, because with the pinheaders soldered to the board and dupont cables connected to it, it no longer fitted.

Also, I am no longer using the small antenna that was provided with the board. I seem to have accidentally twisted the cable that you use to connect the SMA socket to the U.FL IPX connector on the board. The only suitable antenna I had available, was one that was provided as part of the LoPy kickstarter kits (which apparently is different from the antenna sets they sell now). The antenna I got in the kit is a RP-SMA antenna meaning the cable is also RP-SMA. Long story short: I can connect the LoPy cable + LoPy antenna to the board, but the the provided small antenna won’t fit on the LoPy cable. With the LoPy antenna combi I’ve been able to get about 500 meters range outdoors, combined with the single channel LoPy nanogateway. Which is absolutely not bad at all, also given that I’m fixed not to just one channel there but also to SPF7. I’ll do further comparisons once the replacement cable has arrived.

So, the DHT11 sensor. It helped that I managed to figure out that the provided pinout chart was incorrect. Once I know to which actual ports the DHT11 was connected, it was a matter of integrating the library and code into the existing code.  To keep the number of things that could go wrong manageable, I first tested jut the DHT11 code. I provided an example here. If that doesn’t work, don’t bother with the connection to TTN.

Just as a reminder, don’t use the image provided by the merchant to find the correct pins, look at the backside of the board!

Once you get the DHT11 sensor working on its own, we can do the integration with TTN. I uploaded the code here. Like before, you need to add in your own TTN codes.

You might notice that the code looks different that the examples on the forum. That is because I used the code generator provided by TTN ‘s-Hertogenbosch. I think the structure of the code they provide is more easy to understand. I added the needed code for the OLED display and added the code for the DHT11.

Another thing I needed to change was the code to transmit the data collected from the DHT11 to TTN. Now at first, I have to admit, I was making stuff way to complicated, accounting for negative values and decimal values, converting to Kelvin, bit shifting values into multiple bytes. But after looking at the specifications for the DHT11, it became clear that the sensor has some limitations which make transferring the data very simple. And simple is always better.

It turns out that the DHT11 measures temperatures between 0 and 50℃ with an accuracy of  ±2℃. So, no need to account for negative numbers. And also not for decimal values. Because the humidity part of the sensor has an accuracy of ±5% relative humidity. The example code provided for the DHT library does use “float” for both values, but that is there for the DHT22. Because that one has an accuracy of ±0.2℃ making float practical.

So, the values I need to be able to transport are between 0 – 50 (temperature) and 20 – 90 (humidity). Each value easily fits into a single byte and can be decoded just as easily on the TTN server. See the image above for the code (which is also on github).

In the next post, I’ll attach a BME280 temperature, humidity, air-pressure sensor which has an operating range of -40 -> +85 °C, 0 -> 100 % relative humidity  and 300 -> 1100 hPa. For those readings we’ll use 3 x 2 bytes per transmission. The sensor will use I2C for its communication with the board.

0 0 stemmen
Bericht waardering
6 Reacties
Inline Feedback
Bekijk alle reacties
trackback

My Chinese ESP32 + SX1276 board + DHT11 connected to The Things Network – #2 https://t.co/WtaIBClqIS

LoRaWAN Berlin
6 jaren geleden

500 meter only? We need about 2.5 – 5 km!

Rodrigo Carbajales
6 jaren geleden

Hi Pierre, great work! Thanks
I am taking a look to BME code, could you explain how do you convert data with 3 x 2 bytes per transmission and also how do you decode on TTN?
Best

Chenhao Ren
6 jaren geleden

Hi, Pierre

I have used your code TTN_test_ESP32_ABP_DHT11.ino, but in Serial monitor, it just shows “temp Celcius:18 temp Fahrenheit:66 moisture:61” without sending anything to ttn and finally, it shows “61711 Sending.. FAILURE”
and “C:\Users\mylaptop\Documents\Arduino\libraries\arduino-lmic-master\src\lmic\radio.c:523”.

I used esp32 sx1276.

do you know how to solve this?