ESP8266. Outdoor weather station

espressifText herein is the continuation of my previous work with ESP8266-07 WiFi module. That work was related to connecting the ESP with humidity/temperature sensor (DHT22) and pressure sensor (BMP180). The weather station prototype described here consist of set of ready-to-use modules: ESP8266-07, DHT22, BMP180 and DC-DC converter module (built on LM2596HV chip). All components mentioned above was purchased in arduino-ua.com shop. As enclosure was used standard box with flanges from Gainta (model G203MF).

weather_station2

Outdoor weather station

The described device includes the next sensors – DHT22 and BMP180 which allows to measure such parameters of an weather condition as temperature, humidity and pressure,

  • Pressure 300…1100 hPa (30…110 kPa)
  • Temperature -40…+80 °C
  • Humidity 0…100%

Power supplies to this device with AC-DC adapter 220V-9v(5V), voltage from such adapter is additional converted with DC-DC converter to the level 3,3V.

weather-station

ESP8266. Outdoor weather station (internal view)

All components (control and sensor except the DHT22) are installed in the enclosure, DHT22 is placed on the outer surface of the enclosure under the plastic shield (on the photo in upper right side).  Sensor are connected in the next way.

  • DHT22 dataPin -> pin7 (Node-MCU) GPIO13 (ESP8266-07)
  • BMP180 sda -> pin1 (Node-MCU) GPIO5/sdl -> pin2 (Node-MCU) GPIO4

Schematic

The device is controlled with set of lua scripts all could be found on my github. Scripts are not so original and created with using sources available into the internet (links on original sources could be found in the description). Device initialization and its connection to WiFi (with static IP 192.168.0.100) is duty of init.lua script. This scrip also starts up http-server and server.lua and main program cycle do.lua.

wifi.setmode(wifi.STATION)
print("Connecting to the %SSID%")
wifi.sta.config("%SSID%","%password%")
wifi.sta.connect()
wifi.sta.setip({ip="192.168.0.100",netmask="255.255.255.0",gateway="192.168.0.1"})

print("ESP8266 mode: " ..wifi.getmode())
print("ESP8266 MAC: " ..wifi.ap.getmac())
print("ESP8266 IP "..wifi.sta.getip())

dofile("server.lua")
collectgarbage()
dofile("do.lua")

Script do.lua include the main program cycle which is repeats with help of internal timer each 30 seconds.

tmr.alarm(1, 30000, 1, function()
    print("-----------------------------------")
    print("Read the sensors")
    dofile("dht22.lua")
    collectgarbage()
    dofile("bmp085.lua")
    collectgarbage()
    dofile("string_p.lua")
    print(string.format("t = %s;h = %s;p = %s",t,h,p))
    collectgarbage()
    dofile("thingspeak.lua")
    collectgarbage()
    end
)

This module continuously reads the data from DHT22 and BMP180 sensors (with help dht22.lua and bmp085.lua scripts). Also this module prepares data obtained from bmp180 sensor – converts value in kPa into the mm.Hg and then sends data to the thingspeak.com service. Data obtained from one of this devices you can find on this page – “Meteo”. More detailed description of work with sensors you can find in next article “ESP8266. Hello world”.

Files and sources:
1. Datasheet BMP180
2. Datasheet DHT22
3. Проект на github.com