Example for sending temperature and humidity to the cloud using the DHT22 and ESP8266 Code # 2

Hello!

I’ve been trying to connect the DHT22 and ESP8266 to the Losant Platform. I’ve been using outdated code and I ran into problems with the update libraries. I was able to connect using the latest code: https://github.com/Losant/losant-mqtt-arduino/blob/master/examples/esp8266/esp8266.ino

I can’t seem to find the latest code to send the temperatures and humidity to the cloud and display them on the dashboard.

Hi @Nick_C,

The example included in the Github repository contains code to connect and send data to Losant. You will have to update the code from the example to also read from your DHT sensor, and include these values in the data sent to Losant. For further assistance with this sensor, I would recommend checking out the Arduino Forums and/or Stack Overflow.

I am also curious, could you further elaborate on the issue you are facing with “and display them on the dashboard”? Is this an issue that will this likely be solved once you are sending values from the sensor?

There are also some posts around the Forums about DHT that may provide some assistance. You can check them out here:


Please let me know if I can answer any additional questions :smile:

Thanks!
Julia

Hello! @JuliaKempf Thanks for the response!

I’m following this example: https://www.losant.com/blog/getting-started-with-the-esp8266-and-dht22-sensor. For the first part of the code, which is called “code” I was having compile issues because of the outdated libraries. I reached out to Losant forums and I got an updated code (https://github.com/Losant/losant-mqtt-arduino/blob/master/examples/esp8266/esp8266.ino). Now for the second part of the code, which is under “code PT.2” is also outdate, and once again I’m having issues compiling the code. Similar to the code for part 1, is there an update code for part 2? This will solve all of the errors and will let me upload the temperature and humidity value to the cloud.

Thanks! Nick

Hi @Nick_C,

The first section of code within the blog exclusively reads the sensor and logs to the serial monitor. The “updated code” you have linked is not actually updated code as it is performing completely different functionality.

The “updated” code you have linked above includes code exclusively for connecting to Losant, while the first link you have included reads from the DHT and does not connect to Losant. The code you have linked from Github does not read from the sensor, nor should it.

I’d like to break this down because it can get a little confusing, so let’s dive in!

The example in the blog has two sections of code. The first section reads from the DHT sensor and logs to the serial monitor, while the second section of code connects to WiFi, Losant, and reads the sensor values. Within the blog, the second portion of the code is building upon the first.

The updated Github code you have linked connects to WiFi and Losant and does not include code to report the sensor values, as it is a base for users to build upon for their specific use cases. You will need to use the Github code as a base and build the DHT sensor functionality into this code. The blog was written as an example in 2016, so it is very likely you’ll need to rewrite some of the code from the first section of code to read from the sensor, then build it into the updated Github code.

The issue you are facing is the fact that there is no DHT code in the Github repository. Since the DHT22 sensor is specific to your use case and you have successfully connected to Losant, I’d recommend you check out the resources I referenced above. Since our expertise lies in the Losant Platform, you can find excellent resources from Arduino and possibly an updated example of how to read from a DHT22 sensor within Stack Overflow.

Please let me know if I can answer any further questions!

Thanks,
Julia