ESP8266 Weather Station: Measuring Inside and Outside Temperature – Part 2

In Part 1 of this series you learned how to connect a DHT temperature/humidity sensor directly to your WeatherStation and to display the readings as an additional frame in the carousel rotation. In this second part I will show you how to setup a sensor node and post the readings to a free cloud service before fetching them on a WeatherStation (in another room) and displaying them there.

Requirements

For the sensor node you’ll need:
You can either order these items from Banggood, from my own online shop or if you life in the US from Amazon. I assume that you have already a working WeatherStation.

Wiring

The climate node is relatively easy to wire. The DHT breakout board has only three connectors: GND (Ground), VCC (connect to 3.3V) and DAT which is the data line that we connect to pin D6 on the NodeMCU

Thingspeak

Thingspeak is a free cloud service which allows you to easily post (sensor) data, to visualize it and to retrieve it again using simple HTTP methods. I’d like to point out that you could also use Wunderground to store your climate data and it probably would be very easy to do as well. But I believe that for education purposes Thingspeak allows you more degrees of freedom. After all you could also send them read outs from a motion sensor or similar things. Thingspeak has some nice additional features which lets you program webhooks to trigger a push notification on your cell phone, etc.
So first of all you have to sign up for a (free) account on Thingspeak. Go to https://thingspeak.com/users/sign_up and create the account. After you completed that process, log in to your new account and go to “My Channels”:
There you click on the “New Channel” button. Then fill out the form:
Explanation: The name just helps you to recognize your channel among many others that you might create over time. The important part are the field names. This name will later show up in the chart and with this I’m telling Thingspeak that the value I’m sending later with the field1 attribute should be displayed as Temperature.
Now navigate to the API Keys tab and note the two generated keys:
The first one will allow you to write to this channel in Thingspeak and the second one will allow you to read from it later. Treat them as secrets and with care. Others might be able to spam your channel or to “steal” your data. (BTW: I regenerated the keys after taking a screenshot;-)). We will use these keys soon enough… Also note the channel ID on top of the screen…

Programming the Climate Node

Now we have all ingredients to post the climate data to Thingspeak. We just have to program the ESP8266 accordingly. Go to https://github.com/squix78/esp8266-dht-thingspeak-logger and download the code as Zip file (or do a git check out, if you know what that means).
Now adapt the settings to your needs:

Especially the Wifi settings and the Thingspeak API key have to be updated. Take the Write API key from the previous step here. For testing you might also play with the update interval which is a number in seconds. Please be aware that the minimum update interval in Thingspeak is about 15 seconds. Below your updates will just be ignored.Now flash your program to the Node MCU and your Climate node should start logging. To check the results you can go back to Thingspeak and look at the charts:

Displaying the data on the WeatherStation

Now to the real easy part. Like a cook in the TV kitchen I have prepared this step a long time ago (possibly to your confusion;-)). The WeatherStationDemo that comes as an example with the WeatherStation library already contains everything needed to display your own Climate Node data:

Look for these lines in the demo and replace the read api key and the channel ID with the ones you got in the Thingspeak step. If you didn’t remove the climate node section in your weather station code you just need to flash your WeatherStation with the updated API key and channel ID and voilà: you just successfully sent the temperature and humidity data from the next room once around the world just to display it on a tiny OLED display. I know some people (including my wife) who wouldn’t be impressed by that at all;-).Explanation: This last step might have been a bit confusing, since the tv cook had prepared everything hours before the TV show actually started, so here the summary in slow motion: the Weather Station library now comes with a class called Thingspeak client which does all the leg work. You pass in the channel id and API key and it downloads a JSON object and picks out just the last data set, since we are currently interested only in that. Have a look at https://github.com/ThingPulse/esp8266-weather-station/blob/master/src/ThingspeakClient.cpp to understand what happens and maybe adapt/ extend it to your needs. Why not display the chart of the last 24 hours on the OLED display?

<Measuring Inside and Outside Part 1

Posted by Daniel Eichhorn

Daniel Eichhorn is a software engineer and an enthusiastic maker. He loves working on projects related to the Internet of Things, electronics, and embedded software. He owns two 3D printers: a Creality Ender 3 V2 and an Elegoo Mars 3. In 2018, he co-founded ThingPulse along with Marcel Stör. Together, they develop IoT hardware and distribute it to various locations around the world.

20 comments

  1. Nice article and addition to the first part you wrote some days ago. I wonder if anyone has some ideas how to protect the DTH22 outside. If I want to measure the temperatures outside snow and rain or even a strong wind may destroy the sensor. But I can't just put it in a case because the readings may not be correct then.

    Any ideas?

    • You should consider DS18B20 sensor for temperature and get a waterproof probe you can stick outside. It is better than DHT11 and humidity is 100% when it is raining anyway 🙂

    • You should consider DS18B20 sensor for temperature and get a waterproof probe you can stick outside. It is better than DHT11 and humidity is 100% when it is raining anyway 🙂

  2. Hi Taki K

    I have a thingspeak weatherstation myself for a year now. I used a waterproof case (IP68) BUT: punched a tiny hole in it and pointed this downward so if it rains the rain will not get in. I use a BMP180 for airpressure so NO HOLE was no option, then I cannot measure the pressure accurately. DHT22 needs a hole also because otherwise humidity will not be accurate

    • Hi DVE,

      Thanks for your advice. But isn't the temperature in the case other then outside the case? Or does the hole equals the inner and outside temperatures?

  3. Hi Taki K

    The whole case assumes/takes the outside temperature after 10-20minutes so this gives no error. Besides the BMP180 I use is not so calibrated. I found that the temperature readings are quite close to those I see on semi-prof stations in the neighbourhood. Personally I dont mind 1 degree error 🙂

    You could place the station under a small roof or something. Or experiment a little with the case open and compare with closed? I dont think you will see shocking differences.

  4. Nice Article and technical solution.
    How big is the power consumption of the ESP8266 Nodes?
    Is it possible to power them from a battery pack?

  5. Got my WeatherStation fully operational today. Thanks so much! (Beer teleported!)

    Enjoy!

    Tim

  6. Have you considered both displaying the data locally using the weather station code and uploading to Thingspeak? That way I can see my home temperature from the office or office temperature from home without too many additional esp8266 boards. I’d be interested in some information on how your scheduling works and how much time is available in the main loop. I presume its the display driver that takes the most time

    • Hi Tim. Basically yes, that should be no problem at all. I was just more interested on the outside temperature while watching the data indoors. The current scheduling is quite simple. Just make sure that the time intensive things don’t happen while you are animating the display or the carousel won’t so smooth anymore. You can check in which state the carousel currently is and only execute when the frames are not moving. If you want to do “background” tasks don’t execute them without such a check. I also wouldn’t execute it during the clock frame, since the seconds might “jump” a lot… If you need more speed, you can also switch to the BRZO version of the I2C driver. This driver is written in assembler and is a lot faster than the built-in I2C driver…

  7. hey i have one doubt ..if i am using weather station demo example by using nodemcu and oled only then will i get graphs on thingspeak channels or its neccessary that i should connect one dht sensor with it…if it is possible then plzz let me know coz i have tried alot but i am not getting it..
    thanks in advance

  8. Got the Thingspeak uploads working. I’m now considering swapping the DHT sensor for an SHT11. Is it acceptable to share the I2C for the display and if so can I get away with a Wire.beginTransmission(eSHT2xAddress); in the main code assuming that the display code has already initialised the pins?

  9. Now consider adding particle counter (PM2.5/PM10) for inside and outside, as well as NO2(outside) and CO2(inside), as well as noise meter (dB meter). Additionally new BMP680 will be a good choice for inside application into air quality measurements. BME280 and BME680 has two I2C addresses, or can be separate controlled by SPI – so there you go – one for inside, one for outside.

  10. I can not seem to get the “Climate Mode” sketch to compile. The last error is as follows:

    Arduino: 1.8.3 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, 4M (1M SPIFFS), v2 Prebuilt (MSS=536), Disabled, None, 115200”

    Archiving built core (caching) in: C:\Users\steve\AppData\Local\Temp\arduino_cache_96152\core\core_esp8266_esp8266_nodemcuv2_CpuFrequency_80,FlashSize_4M1M,LwIPVariant_v2mss536,Debug_Disabled,DebugLevel_None____,UploadSpeed_115200_f8c65c991b2173c0d637a69a82742b0e.a
    libraries\DHT_sensor_library\DHT.cpp.o: In function `DHT::DHT(unsigned char, unsigned char, unsigned char)’:

    C:\Users\steve\Documents\Arduino\libraries\DHT_sensor_library/DHT.cpp:12: multiple definition of `DHT::DHT(unsigned char, unsigned char, unsigned char)’

    sketch\DHT.cpp.o:sketch/DHT.cpp:12: first defined here

    libraries\DHT_sensor_library\DHT.cpp.o: In function `DHT::DHT(unsigned char, unsigned char, unsigned char)’:

    C:\Users\steve\Documents\Arduino\libraries\DHT_sensor_library/DHT.cpp:12: multiple definition of `DHT::DHT(unsigned char, unsigned char, unsigned char)’

    sketch\DHT.cpp.o:sketch/DHT.cpp:12: first defined here

    libraries\DHT_sensor_library\DHT.cpp.o: In function `DHT::begin()’:

    C:\Users\steve\Documents\Arduino\libraries\DHT_sensor_library/DHT.cpp:24: multiple definition of `DHT::begin()’

    sketch\DHT.cpp.o:sketch/DHT.cpp:24: first defined here

    libraries\DHT_sensor_library\DHT.cpp.o: In function `DHT::readHumidity(bool)’:

    C:\Users\steve\Documents\Arduino\libraries\DHT_sensor_library/DHT.cpp:64: multiple definition of `DHT::convertCtoF(float)’

    sketch\DHT.cpp.o:sketch/DHT.cpp:64: first defined here

    libraries\DHT_sensor_library\DHT.cpp.o: In function `DHT::convertCtoF(float)’:

    C:\Users\steve\Documents\Arduino\libraries\DHT_sensor_library/DHT.cpp:69: multiple definition of `DHT::convertFtoC(float)’

    sketch\DHT.cpp.o:sketch/DHT.cpp:69: first defined here

    libraries\DHT_sensor_library\DHT.cpp.o: In function `DHT::computeHeatIndex(float, float, bool)’:

    C:\Users\steve\Documents\Arduino\libraries\DHT_sensor_library/DHT.cpp:92: multiple definition of `DHT::computeHeatIndex(float, float, bool)’

    sketch\DHT.cpp.o:sketch/DHT.cpp:92: first defined here

    libraries\DHT_sensor_library\DHT.cpp.o: In function `DHT::expectPulse(bool)’:

    C:\Users\steve\Documents\Arduino\libraries\DHT_sensor_library/DHT.cpp:237: multiple definition of `DHT::expectPulse(bool)’

    sketch\DHT.cpp.o:sketch/DHT.cpp:237: first defined here

    libraries\DHT_sensor_library\DHT.cpp.o: In function `DHT::read(bool)’:

    C:\Users\steve\Documents\Arduino\libraries\DHT_sensor_library/DHT.cpp:123: multiple definition of `DHT::read(bool)’

    sketch\DHT.cpp.o:sketch/DHT.cpp:123: first defined here

    libraries\DHT_sensor_library\DHT.cpp.o: In function `DHT::readTemperature(bool, bool)’:

    C:\Users\steve\Documents\Arduino\libraries\DHT_sensor_library/DHT.cpp:35: multiple definition of `DHT::readTemperature(bool, bool)’

    sketch\DHT.cpp.o:sketch/DHT.cpp:35: first defined here

    libraries\DHT_sensor_library\DHT.cpp.o: In function `DHT::readHumidity(bool)’:

    C:\Users\steve\Documents\Arduino\libraries\DHT_sensor_library/DHT.cpp:72: multiple definition of `DHT::readHumidity(bool)’

    sketch\DHT.cpp.o:sketch/DHT.cpp:72: first defined here

    collect2.exe: error: ld returned 1 exit status

    exit status 1
    Error compiling for board NodeMCU 1.0 (ESP-12E Module).

    This report would have more information with

    “Show verbose output during compilation”
    option enabled in File -> Preferences.

    I suspect I do not have files in the correct directories. Any help is most appreciated!! Thanks.

  11. Is it difficult to allow others (sailing club) to see the readings on a web page (or thingspeak)

    weather station -> repeater -> accesspoint -> thingspeak -> all club members have access to readings?

    Also have you seen the new boards that have cameras on,?, maybe take it to the next level

    Good tutorial and easy to follow

  12. i have two questions. 1. Can be use the ESP8266-01 for indoor and outdoor modules? and 2. it is possible to connect this ESP modules without an internet services like Thingspeak , blynk or other?

Leave a Reply to stamy1Cancel reply