readme.md
Markdown · 63 lines
# ESP Captive Portal: AHT20 + BMP280 (I2C) — ESP8266 / ESP32

This project creates an **open Wi-Fi Access Point (AP)** and serves a **captive portal**. After connecting with a phone/laptop, the OS should automatically pop up a portal window showing live sensor readings:
- **AHT20**: temperature + humidity
- **BMP280**: pressure + temperature + altitude (estimated)
The page auto-updates every 2 seconds by fetching data from `/api`.
## Requirements
- ESP8266 (NodeMCU / Wemos D1 mini) or ESP32 DevKit
- AHT20 I2C module (pins: VDD, GND, SDA, SCL)
- BMP280 I2C module (pins: VCC/VDD, GND, SDA, SCL)
- Jumper wires
## Wiring (I2C)
Universal:
- ESP 3V3 -> VDD/VCC (AHT20 + BMP280)
- ESP GND -> GND
- ESP SDA -> SDA (both sensors in parallel)
- ESP SCL -> SCL (both sensors in parallel)
Common default I2C pins:
### ESP8266 (NodeMCU / Wemos D1 mini)
- SDA = D2 (GPIO4)
- SCL = D1 (GPIO5)
### ESP32 (DevKit)
- SDA = GPIO21
- SCL = GPIO22
## Libraries (Arduino Library Manager)
Install:
- Adafruit AHTX0
- Adafruit BMP280 Library
- Adafruit Unified Sensor
(DNSServer/WebServer are included in the ESP8266/ESP32 Arduino cores.)
## Usage
1. Flash the sketch to your board.
2. On your phone/laptop, connect to the Wi-Fi network: `ESP-Sensors` (open network).
3. The captive portal should appear automatically.
If it does not, open a browser and go to:
- `http://192.168.4.1/`
4. You should see live sensor readings. The page refreshes automatically.
## API
- `GET /api` returns JSON:
- `aht20_temp_c`
- `aht20_hum_pct`
- `bmp280_temp_c`
- `bmp280_press_hpa`
- `bmp280_alt_m`
## Notes
- BMP280 I2C address is usually `0x76` or `0x77` — the sketch tries both automatically.
- Altitude depends on sea-level pressure. Adjust `SEA_LEVEL_HPA` (default 1013.25 hPa) for better accuracy.
- Captive portal behavior varies by OS. If it doesn't pop up, opening any HTTP page or directly visiting `192.168.4.1` usually works.
## License
MIT