# ESP32 Temperature Weather Display

ESP32 weather dashboard for a 128x64 OLED display. The firmware connects to Wi-Fi, syncs time with NTP, fetches current weather data from OpenWeatherMap, and also shows local temperature and humidity from a DHT22 sensor.

![ESP32 temperature weather display hardware](assets/temperature-weather-display.jpg)

## Features

- Shows date and time on a 128x64 OLED display
- Fetches current weather conditions from OpenWeatherMap over Wi-Fi
- Displays weather icon, description, temperature, humidity, pressure, wind, sunrise, and sunset
- Reads local temperature and humidity from a DHT22 sensor
- Rotates through multiple information pages automatically
- Prints connection and weather debug information to the serial monitor at `115200`
- Uses PlatformIO with the Arduino framework

## Hardware

- Generic ESP32 development board
- DHT22 temperature and humidity sensor
- 128x64 OLED display
- Jumper wires
- USB cable for power, flashing, and serial monitoring

## Wiring Overview

Confirmed from the source code:

- DHT22 data pin -> `GPIO4`
- OLED display -> hardware I2C via `U8g2`

Typical ESP32 defaults often used for I2C are:

- SDA -> `GPIO21`
- SCL -> `GPIO22`

OLED I2C displays commonly use address `0x3C`, but this should be verified on your hardware.

See [docs/hardware.md](docs/hardware.md) for a fuller hardware summary, wiring notes, and troubleshooting guidance.

## Software Stack

- [PlatformIO](https://platformio.org/) for project management, build, and upload
- Arduino framework for ESP32 firmware structure and peripheral access
- `U8g2` for OLED graphics and text rendering
- `DHT sensor library` for reading the DHT22 sensor
- `ArduinoJson` for parsing the OpenWeatherMap JSON response
- `WiFi`, `WiFiMulti`, `HTTPClient`, and `time` from the ESP32 Arduino core for network connectivity, HTTP requests, and NTP time sync

## PlatformIO Environment

The current project configuration uses:

- Environment: `esp32-s3-devkitc-1`
- Platform: `espressif32`
- Framework: `arduino`
- Serial monitor speed: `115200`

The more common generic PlatformIO board choice for many ESP32 examples is `esp32dev`, but this project is configured for an ESP32-S3 board, so `esp32-s3-devkitc-1` is used here.

## Libraries

Configured in `platformio.ini`:

- `bblanchon/ArduinoJson`: parses the weather API JSON response
- `olikraus/U8g2`: drives the OLED display and renders text/bitmaps
- `adafruit/DHT sensor library`: reads local temperature and humidity from the DHT22

Also used from the ESP32 Arduino core:

- `WiFi` and `WiFiMulti`: connect to one of multiple configured Wi-Fi networks
- `HTTPClient`: fetch weather data from OpenWeatherMap
- `time`: sync and format date/time from NTP

## Project Structure

```text
.
├── assets/
│   └── temperature-weather-display.jpg
├── docs/
│   └── hardware.md
├── include/
│   ├── config.h
│   └── config.example.h
├── src/
│   ├── images.h
│   ├── status_icons.h
│   └── main.cpp
├── .gitignore
├── LICENSE
├── platformio.ini
└── README.md
```

## Build And Upload

Using the PlatformIO CLI:

```bash
pio run
pio run --target upload
pio device monitor --baud 115200
```

Using VS Code with the PlatformIO extension:

1. Open the project folder.
2. Build the project.
3. Upload to the board.
4. Open the serial monitor at `115200`.

## Configuration

This project uses local configuration for Wi-Fi credentials and the OpenWeatherMap API key.

1. Open `include/config.h`
2. Fill in your Wi-Fi SSID/password and OpenWeatherMap API key
3. Update `WEATHER_CITY` and `WEATHER_TIMEZONE`
4. Keep `include/config.h` untracked

`include/config.h` is ignored by Git, while `include/config.example.h` is intended to remain public.

Example:

```cpp
static const char* OPEN_WEATHER_MAP_KEY = "YOUR_OPENWEATHERMAP_API_KEY";
static const char* WEATHER_CITY = "Rome,IT";
```

## Interfaces Used

- Wi-Fi: required for NTP sync and OpenWeatherMap access
- I2C: used by the OLED display through the default `Wire` bus
- GPIO: DHT22 data line on `GPIO4`
- Serial: USB serial monitor output at `115200`


## Weather API Notes

- Service used in the firmware: OpenWeatherMap current weather endpoint
- Polling interval: `10` minutes
- If the API key is not configured, the firmware still starts and the local DHT22 page remains available

## Display Notes

- The source includes support for both `SH1106` and `SSD1306` 128x64 OLED displays
- The active driver is selected in `src/main.cpp` by enabling either `DRIVER_SH1106` or `DRIVER_SSD1306`
- Choose the driver that matches the OLED module you actually have
- The current rotation is `U8G2_R2` because the display is mounted upside down in this build
- If your display is mounted normally, you can change `U8G2_R2` to `U8G2_R0`

## License

This project is released under the [MIT License](LICENSE).
