# ESP32 T-Display-S3 AMOLED UP-AirQuality

ESP-IDF firmware that displays live UniFi UP-AirQuality readings on the original LILYGO T-Display-S3 AMOLED 1.91-inch board.

It uses ESP-IDF only. It does not use Arduino, PlatformIO, LVGL, LovyanGFX, or managed components.

> This targets the original 536 x 240 RM67162 board. It does not support the later SPI/Plus model.

| T-Display | UP-AirQuality sensor | UniFi Protect readings |
| :---: | :---: | :---: |
| <img src="docs/images/t-display-air-quality.jpg" alt="T-Display showing live air quality readings"> | <img src="docs/images/up-air-quality-sensor.jpg" alt="UniFi UP-AirQuality sensor"> | <img src="docs/images/unifi-protect-readings.jpg" alt="Air quality readings in UniFi Protect"> |

## Setup

Requirements: ESP-IDF v6, OpenSSL, UniFi Protect, and an adopted UP-AirQuality sensor.

```bash
git clone git@github.com:angristan/esp32-t-display-s3-amoled-up-air-quality.git
cd esp32-t-display-s3-amoled-up-air-quality
```

Capture the UniFi console certificate:

```bash
UNIFI_HOST=192.168.0.1
openssl s_client \
  -connect "${UNIFI_HOST}:443" \
  -servername unifi.local \
  </dev/null 2>/dev/null \
  | openssl x509 -out main/unifi_local.pem

openssl x509 \
  -in main/unifi_local.pem \
  -noout -subject -dates -fingerprint -sha256
```

Verify the fingerprint before you continue. The certificate is embedded in the firmware and excluded from Git. TLS also requires the `unifi.local` certificate identity.

Build and flash:

```bash
. "$HOME/esp/esp-idf/export.sh"
idf.py set-target esp32s3
idf.py build
idf.py -p /dev/ttyACM0 flash monitor
```

On first boot, enter the Wi-Fi and local Protect account details over serial. Hold the touch screen during startup to replace the saved configuration. Exit the monitor with `Ctrl+]`.

## Notes

- Readings refresh every 15 seconds.
- The firmware uses the first UP-AirQuality sensor returned by Protect.
- It uses the private local Protect API because the official API does not expose these readings. Protect updates can break it.
- Credentials are stored in NVS. NVS is not encrypted by default. Use a dedicated local Protect account.

## Tests

```bash
./tests/run-host.sh
```

## License

MIT. Hardware driver values were derived from LILYGO's MIT-licensed [`LilyGo-AMOLED-Series`](https://github.com/Xinyuan-LilyGO/LilyGo-AMOLED-Series). See [`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md).
