Projects/ESP8266 - Pressure (BMP085) Temperature Humidity (DHT22))

From Playful Exploration
Jump to navigation Jump to search


Version 1 of the quick'n-dirty weather station is online for the first 24 hours, running on a USB power stick, sending air pressure, temperature and humidity data from the balcony up directly to the VPS's influxdb. No mptt, just simple http web requests. Version 2 will need some enclosure to protect the electronic from the elements.

Graphical output using Grafana: https://www.playfulexploration.com/grafana/dashboard/db/pressure-temperatur-humidity-5min-interval

ESP8266 - Pressure Temperature Humidity.JPG

Features

  • AMS1117-3.3 Voltage Regulator
  • Microcontroller ESP8266
  • Firmware Lua NodeMCU
  • Sensor driver build into the firmware
  • DHT22 Temperature and Humidity Sensor, sensor specific single wire protocol
  • BMP280 Barometric Pressure Sensor, I2C
  • CP2102 USB to UART Adapter

Http-Requests based Data Push to Influxdb

file lua code Notes
config.lua
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PASSWORD")
wifi.sta.connect()
setup file, connects the esp to the router
init.lua

(part 1)

print("\n\nHold gpio0 low to stop boot")
tmr.delay(1000000)
if gpio.read(3) == 0 then print("...boot stopped") return end
print("...booting", collectgarbage('count'))
print('ready',collectgarbage('count'))

dofile('config.lc')
Startup code that allows stopping the boot by holding GPIO0 low.
init.lua

(part 2)

-- restart if stall
tmr.softwd(30)

--bmp085.init( dofile("i2c_locate.lc") )
bmp085.init( 6, 5 )
print( bmp085.pressure(), bmp085.temperature()/10, dht.read(7) )

trigger = nil
conn = nil
pub = function(c)
   local d="pa val="..bmp085.pressure()
   local s,t,h=dht.read(7)
   if s==0 then d=d.."\ntemp val="..t.."\nhumi val="..h end
   local m="POST /write?db=rocket HTTP/1.1\r\nContent-Length: "..d:len().."\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n"..d
   print(m)
   c:send(m)
end
trigger = function(c)
  conn = net.createConnection(net.TCP, 0)
  conn:on("connection", pub)
  conn:on("receive", function(conn,m) conn:close() conn=nil print(m) tmr.alarm(0, 3000, 0, trigger) tmr.softwd(30) end)
  conn:connect(8086,"playfulexploration.com")
end
trigger()
Net client connects to influxdb every 3 seconds and send data

The fully charged power stick last about 26 hours.