Skip to content

Using an ESP32 data collection, an MQTT and Node Red server for server side data processing and Home Assistant for Front End plots

Notifications You must be signed in to change notification settings

lennon101/DIY-Weather-Station

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ESP32 Weather Station

An ESP32-based weather station that connects to Wi-Fi and an MQTT broker, collects environmental data (temperature, humidity, pressure, rainfall), and publishes the results as JSON.

It supports a BME280 sensor for temperature, humidity, and pressure, and a tipping bucket rain gauge for rainfall measurement. Boot information is stored in EEPROM for persistence across reboots.

See the Complete Documentation for more detail on installation and setup.


Features

  • Connects to Wi-Fi with static IP configuration and auto-reconnect.
  • Connects to an MQTT broker with auto-reconnect.
  • Subscribes to an input MQTT topic and publishes sensor readings to an output MQTT topic.
  • Collects data from:
    • BME280 (temperature, humidity, pressure).
    • Davis tipping bucket rain gauge (rainfall).
  • Uses EEPROM to log:
    • Number of boots.
    • Last reboot reason.
  • Includes reboot logic for invalid sensor readings or failed connections.

Hardware Requirements

  • ESP32 development board.
  • BME280 sensor (I²C).
  • Davis tipping bucket rain gauge or compatible (connected to pin GPIO16).

Wiring

ESP32 ↔ BME280 (I²C)

ESP32 Pin BME280 Pin
3.3V VCC
GND GND
GPIO21 SDA
GPIO22 SCL

ESP32 ↔ Rain Gauge

ESP32 Pin Rain Gauge
GPIO16 Signal
3.3V VCC
GND GND

Note: Rain gauge uses an interrupt on GPIO16 to count bucket tips.


Software Requirements


Configuration

Update these variables in the code before flashing:

// Wi-Fi credentials
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";

// MQTT broker
const char* mqtt_server = "BROKER_IP_ADDRESS";

// Optional static IP config
IPAddress local_IP(192, 168, 1, 40);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8);
IPAddress secondaryDNS(8, 8, 4, 4);

MQTT authentication (username/password) can also be updated in the connect_to_mqtt() function.


MQTT Topics

  • Subscribe
    • esp32/in → triggers the device to take a reading and publish data.
  • Publish
    • esp32/out → JSON payload containing temperature, pressure, humidity, and rainfall.
    • esp32/out/debug → Debug messages (boot count and reboot reasons).
    • esp32/out/keepalive → Periodic keep-alive signal.

Example Payload

{
  "temperature": 20.0,
  "pressure": 1000.0,
  "humidity": 50.0,
  "mm_rain": 1.2
}

EEPROM Usage

The EEPROM stores a small struct with:

  • num_boots: number of boots since first flash.
  • reason: the reason for the last reboot (e.g., Wi-Fi failure, MQTT failure, invalid sensor values).

Known Issues / TODO

  • The setup_bme280() and get_bme_values() functions are stubbed; uncomment and configure wiring to enable live sensor data.
  • Improve error handling for MQTT and Wi-Fi reconnection.
  • Add OTA updates for field deployment.

Author

  • Dane Lennon
    Initial version: 2022-11-22

About

Using an ESP32 data collection, an MQTT and Node Red server for server side data processing and Home Assistant for Front End plots

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages