CYD Weather Station for ESP32
An ESP32 display project for Sunton ESP32-2432S028R involving SD card.
Parts and sourceBefore you start
Check the exact SD card configuration against the upstream wiring or parts list.
Upstream README
:partly_sunny: CYD Weather Station :pager:
A beautiful, configurable real-time weather station and desk clock built for the ESP32 Cheap Yellow Device (CYD) family (such as the 2.8" Resistive ESP32-2432S028R, 2.8" Capacitive ESP32-2432W328C, and 3.5" Capacitive ESP32-3248S035C) utilizing the LVGL v8 graphics library, Open-Meteo / OpenWeatherMap APIs, and the Catppuccin Color Theme.
[!WARNING] This project is currently in a
v0.X.Xdevelopment stage. Features and configurations are subject to change, and breaking changes may be introduced at any time.
:star: Features
- Dual API Integration:
- Open-Meteo API: Out-of-the-box fallback — no API key required. Automatically fetches 24-hour rolling hourly forecasts and 3-day daily forecasts in the user's local timezone.
- OpenWeatherMap API: Automatically used if an API key is configured.
- Location Resolution & City Name Footer:
- Displays
Last Update: <time> | <city name>centered at the bottom of the screen. - Zip Code Geocoding: Enter a US Zip Code (e.g.
90210); coordinates are resolved on boot. - IP Geolocation Fallback: Automatically falls back to resolving location via IP geolocation (using
ip-api.com) on boot if Zip Code and coordinates are left blank. - Reverse Geocoding: When using coordinates + Open-Meteo, the city is resolved using Nominatim OSM. OWM resolves and returns the city name natively.
- Displays
- 3-Day Forecast View: Swipe to a dedicated Forecast tab showing daily high/low temperature and weather condition icons.
- 24-Hour Hourly Forecast Chart: Dedicated Hourly tab plotting dynamic temperature and precipitation probability curves across a 24-hour rolling window with 4-hour interval tick labels (
Now,+4h,+8h,+12h,+16h,+20h,+24h). - Swipe Navigation: Swipe left/right anywhere on the screen to switch between the Current Weather, 3-Day Forecast, 24-Hour Hourly Forecast, and System Settings tabs.
- Dynamic Weather Icons: A large (48px) custom weather glyph maps weather codes to condition icons, dynamically colored using the active Catppuccin palette.
- Interactive Settings Tab: Touch-configurable settings persisted to flash across reboots:
- Independent Weather Metric Units: Choose units independently for Temperature (°C / °F), Wind Speed (km/h, mph, m/s, kn), Precipitation (mm / in), and Pressure (hPa, inHg, mbar, mmHg).
- Catppuccin Theme Flavor: Choose between Mocha, Macchiato, Frappé, or Latte — the full UI redraws instantly in the selected palette.
- Auto Brightness: Toggle automatic backlight dimming/brightening driven by the onboard LDR light sensor (GPIO 34) with smooth non-linear perceptual scaling.
- Manual Brightness: Slider to set a fixed screen brightness level with natural $\gamma = 2.2$ gamma correction.
- Timezone:
–/+buttons to cycle through common IANA timezone presets with automatic DST handling powered by AceTime. - SD Log: Enable/disable weather logging to a microSD card.
- SD Cache: Enable/disable weather caching to a microSD card (restores UI offline).
- Screenshot Server: Enable/disable the remote screenshot HTTP server.
- MQTT: Toggle publishing weather variables to MQTT topics with a configurable base topic (default
cyd/). - MQTT Integration & Remote Control:
- Configurable Base Topic: Customize the base topic (e.g.
home/living_room/weather/) via the web settings portal. - Home Assistant Auto-Discovery: Automatically exposes entities for weather sensors (temp, humidity, wind speed/direction, condition, city), device diagnostics (uptime, heap, RSSI, IP, version, MAC), configuration controls (screen & LED brightness, auto brightness, theme flavor, units, orientation, update interval, screensaver timeout, status LED, SD log/cache), and device restart button.
- Bidirectional Remote Control: Change any setting or command via MQTT topics with immediate on-screen and Home Assistant state synchronization.
- LWT & Robust Reconnection: Reports online/offline availability via Last Will and Testament (LWT) on
<base_topic>statuswith MAC-based unique client IDs, paced discovery message queueing, and exponential reconnection backoff (5s to 2min).
- Configurable Base Topic: Customize the base topic (e.g.
- Screensaver: Enable/disable screensaver mode (smoothly fades backlight using gamma interpolation and displays a resolution-scaled bedside clock—48px on 2.8" and 72px on 3.5"—with periodic burn-in prevention drift).
- Sleep Schedule: Enable/disable automatic screen sleep during a configured time frame (e.g. 22:00 to 07:00).
- Screen Orientation: Choose between Landscape, Portrait, Landscape Rev, or Portrait Rev—the entire UI dynamically scales/stacks, header height dynamically increases to 60px in portrait to fit a wrapped two-line title without overlaps, and touch coordinates update instantly.
- Auto-Brightness & Gamma Scaling: Uses the LDR photoresistor (GPIO 34) with an EMA filter and a perceptual $\gamma = 2.2$ gamma curve feeding LEDC PWM (GPIO 21) to smoothly adapt screen brightness to ambient light.
- NTP Time Synchronization: Connects to NTP on boot and keeps a live clock in the header bar, respecting the configured IANA timezone with full DST support.
- RGB LED Status Indicator: Onboard RGB LED (GPIO 4/16/17) with gamma-corrected brightness provides Wi-Fi status feedback (blinking blue for connecting, solid green for connected, fast red for disconnected, slow purple blink for AP Mode) and a brief weather-condition color pulse on updates.
- Custom Hostname & mDNS: Configurable network hostname (default
cyd-weather-station) registered with DHCP (WiFi.setHostname) and mDNS responder (MDNS.begin) for access viahttp://<hostname>.local/without needing to find the device IP address. - Web Dashboard & Settings Portal:
- Access
http://<DEVICE_IP>/orhttp://<hostname>.local/(e.g.http://cyd-weather-station.local/) in any browser for a central Catppuccin-themed dashboard. - Includes direct navigation links to Device Settings (
/settings), Firmware Updates (/update), Live Screenshots (/screenshot), Clear SD Logs (/clear_logs), Clear SD Cache (/clear_cache), Reboot to AP Setup Mode (/reboot_ap), and Factory Reset (/reset). - Configure Wi-Fi SSID and Password directly within
/settingswithout requiring Access Point mode. - Settings portal automatically redirects back to the main dashboard after saving settings once the device comes back online.
- Access
- Wi-Fi AP Captive Portal Fallback:
- Automatically hosts an open Soft AP (
cyd-weather-station-<mac_short>) if connection fails or times out after 30 seconds on boot. - Runs a captive portal configuration web server and DNS redirector on
192.168.4.1for selecting networks, setting Wi-Fi credentials, and configuring your location (Zip Code or Coordinates). - Runs background async Wi-Fi scans after AP initialization to prevent client disconnections (common on ESP32 during active/blocking scans).
- Web interface
/scantriggers background scanning with a friendly redirect loader screen, displaying updated networks on completion. - Dynamically displays step-by-step connection instructions (SSID name and IP address) directly on the screen while AP Mode is active.
- Colors the header Wi-Fi icon Mauve when in setup configuration mode.
- Automatically hosts an open Soft AP (
- SD Card Weather Logging:
- Automatically mounts a microSD card on boot and appends weather records (timestamp, temperature, humidity, wind speed, wind direction, weather code) to
/weather_history.csvon the root of the card. - Automatic formatting fallback to FAT32 on mount failure.
- Automatically mounts a microSD card on boot and appends weather records (timestamp, temperature, humidity, wind speed, wind direction, weather code) to
- Screenshot Capture:
- Remote via HTTP:
GET /screenshotstreams a pixel-perfect 24-bit BMP of the current screen directly over Wi-Fi. - Physical button: Press and hold the BOOT button (GPIO 0) for 2 seconds to save a timestamped BMP to the SD card as
/screenshot_YYYYMMDD_HHMMSS.bmp. A single quick press of the BOOT button triggers an immediate weather refresh. - Zero large-allocation design — screen tiles are intercepted from the LVGL flush callback and written directly to file.
- Toggle the screenshot server on/off from the Settings tab (
API Srv).
- Remote via HTTP:
- SD Offline Cache Recovery:
- Automatically caches the latest retrieved weather data to
/weather_cache.jsonon the microSD card. - If the device boots without Wi-Fi, it restores the weather screen from the cache instead of displaying blank widgets, displaying a
⚠️ Offlinestatus badge in the header.
- Automatically caches the latest retrieved weather data to
- Wireless OTA Firmware Updates:
- Easily update firmware wirelessly by navigating to
/updatein a browser when connected to the configuration AP (http://192.168.4.1/update) or the local network IP (http://<DEVICE_IP>/updatewhen the Screenshot Server is enabled). - Portal features a responsive Catppuccin-themed HTML interface, drag-and-drop binary selector, dynamic progress bar, error handling, and auto-reboot upon completion.
- Easily update firmware wirelessly by navigating to
:hammer_and_wrench: Hardware Requirements
- ESP32 Cheap Yellow Device (CYD):
- CYD 2.8" (Resistive): ESP32-2432S028R — 2.8″ 320×240 ILI9341 LCD with XPT2046 resistive touch.
- CYD 2.8" (Capacitive): ESP32-JC2432W328C — 2.8″ 320×240 ST7789 LCD with CST816 capacitive touch.
- CYD 2.8" NodeMiner / Rockbase (Resistive): ESP32-2432S028 ("NM") — 2.8″ 320×240 ST7789 LCD with XPT2046 resistive touch.
- CYD 3.5" (Capacitive): ESP32-3248S035C — 3.5″ 480×320 ST7796 LCD with GT911/CST820 capacitive touch.
- Onboard Sensors: LDR photoresistor (GPIO 34), Backlight PWM (GPIO 21), RGB LED (GPIO 4/16/17), BOOT button (GPIO 0).
- Storage: MicroSD card slot (compatible with standard FAT32 formatted cards).
- Micro-USB cable for power and programming.
:electric_plug: Hardware Setup / Sensor Wiring
To read local temperature and humidity, you can wire a sensor directly to the CYD board.
[!NOTE] Currently, the DHT22 (AM2302), DHT11, and SHT40 (I2C) temperature and humidity sensors are supported.
DHT11 / DHT22 Wiring
Connect the DHT sensor to the CN1 breakout port:
-
VCC: 3V3
-
GND: GND
-
Data/Signal: IO22
+------------------------------+ | | | +------+ | | P3 | | +------+ | | | +---------+ | | CN1 | +--------------+ | | GND[X] |------| [X]GND | | | IO22[X] |------| [X]SIG / OUT | | | IO27[ ] | | | | | 3.3V[X] |------| [X]VCC | | +---------+ +--------------+ | | DHT11 / DHT22 | +------+ | | SD | | | CARD | | +------+ | | | +--+ +-------+ +-----------+ | +-| |-| USB C |-| MICRO USB |-+ +--+ +-------+ +-----------+ ESP32-2432S028R+------------------------------+ | | | +------+ | | P3 | | +------+ | | | +---------+ | | CN1 | +--------------+ | | GND[X] |------| [X]GND | | | IO22[X] |------| [X]Sig / OUT | | | IO21[ ] | | | | | 3.3V[X] |------| [X]VCC | | +---------+ +--------------+ | | DHT11 / DHT22 | +------+ | | SD | | | CARD | | +------+ | | | +--+ +-----------+ | +-| |-----------| MICRO USB |-+ +--+ +-----------+ ESP32-3248S035C
SHT40 (I2C) Wiring
Connect the SHT40 sensor to the CN1 breakout port (do not use connector P3 as it lacks a 3.3V power supply):
- VCC: 3V3
- GND: GND
- SDA: IO27 (on
cyd_28r/cyd_28_nm) or IO21 (oncyd_35c/cyd_28c)
[!NOTE] On the
cyd_28randcyd_28_nmboards, the CN1 connector breaks out IO27. IO27 must be used for SDA to prevent conflicts with the display backlight on IO21. On thecyd_35candcyd_28cboards, the CN1 connector breaks out IO21. IO21 must be used for SDA to prevent conflicts with the display backlight on IO27.
-
SCL: IO22
+------------------------------+ | | | +------+ | | P3 | | +------+ | | | +---------+ | | CN1 | +--------+ | | GND[X] |------| [X]GND | | | IO22[X] |------| [X]SCL | | | IO27[X] |------| [X]SDA | | | 3.3V[X] |------| [X]VCC | | +---------+ | [ ]3Vo | | | +--------+ | +------+ SHT40 | | SD | | | CARD | | +------+ | | | +--+ +-------+ +-----------+ | +-| |-| USB C |-| MICRO USB |-+ +--+ +-------+ +-----------+ ESP32-2432S028R+------------------------------+ | | | +------+ | | P3 | | +------+ | | | +---------+ | | CN1 | +--------+ | | GND[X] |------| [X]GND | | | IO22[X] |------| [X]SCL | | | IO21[X] |------| [X]SDA | | | 3.3V[X] |------| [X]VCC | | +---------+ | [ ]3Vo | | | +--------+ | +------+ SHT40 | | SD | | | CARD | | +------+ | | | +--+ +-----------+ | +-| |-----------| MICRO USB |-+ +--+ +-----------+ ESP32-3248S035C
Local Sensor Calibration
Sensors mounted near the CYD board often pick up residual heat radiated by the ESP32 chip and LCD backlight (self-heating), resulting in temperature readings that are slightly high and relative humidity readings that are slightly low. You can calibrate both values using single-point linear offsets via the on-device Settings screen, the Web Settings UI, or MQTT/Home Assistant.
1. Temperature Calibration (Known Accurate Secondary Device)
- Place a trusted, known-accurate digital thermometer right beside the CYD's local sensor.
- Allow both devices to stabilize in the room for at least 30–60 minutes away from direct drafts, sunlight, or airflow.
- Compare the readings:
$$\text{Temperature Offset} = T_{\text{reference}} - T_{\text{CYD}}$$
Example: If your reference thermometer reads $72.0^\circ\text{F}$ and the CYD reads $74.5^\circ\text{F}$, set the Temperature Offset to
-2.5. - Enter this offset in the Settings screen (or Web UI / MQTT).
2. Humidity Calibration (Saturated Salt Test Method)
For accurate relative humidity calibration, the standard and recommended method is the Saturated Salt (NaCl) Slurry Test (see wikiHow: How to Test a Hygrometer for a detailed visual guide), which creates an exact 75% Relative Humidity sealed environment at room temperature:
- In a small, shallow container (like a bottle cap or small cup), mix ordinary table salt with a few drops of water until it forms a thick, wet slush or slurry (all salt should be wet, but with no free-standing liquid water on top).
- Place the salt container along with the sensor (or entire board if wired directly) inside an airtight container or zip-top freezer bag. Ensure no salt water directly touches the sensor.
- Seal the bag completely and let it sit at room temperature for at least 6–8 hours to reach equilibrium.
- Check the humidity reading without unsealing the bag:
$$\text{Humidity Offset} = 75% - H_{\text{CYD}}$$
Example: If the CYD reads $79%$ inside the sealed 75% RH salt container, set the Humidity Offset to
-4.0%. - Enter this offset in the Settings screen (or Web UI / MQTT).
:floppy_disk: MicroSD Card Logging & Auto-Formatting
The weather station periodically logs weather reports to a microSD card in CSV format.
[!WARNING] Auto-Formatting Warning: If the inserted microSD card fails to mount (e.g., if it is formatted as exFAT or uses a GPT partition scheme), the firmware will automatically format the card to FAT32 on boot. This will permanently delete all existing data on the card.
To prevent data loss, ensure that any card you insert is either empty, or pre-formatted as FAT32 with a Master Boot Record (MBR) partition scheme (GUID/GPT partition tables are not supported).
:camera: Screenshots
Device UI Showcase
| Screen | Landscape (320x240) | Portrait (240x320) |
|---|---|---|
| Current Weather | ![]() |
![]() |
| 3-Day Forecast | ![]() |
![]() |
| 24-Hour Forecast | ![]() |
![]() |
| System Settings | ![]() |
![]() |
The device supports capturing the current screen as a standard 24-bit BMP image via two methods:
Remote Settings, Web Dashboard & API
[!NOTE] The Settings Web UI, Dashboard, and Configuration API are available while the device is connected to Wi-Fi. Access the device via IP address (printed to serial:
[WiFi] Connected! IP address: <IP>) or mDNS hostname:http://<hostname>.local/(default:http://cyd-weather-station.local/).
Web Dashboard:
Navigate to http://<DEVICE_IP>/ or http://cyd-weather-station.local/ in any browser to access the central Catppuccin-themed dashboard landing page. From here, you can access:
- ⚙️ Device Settings (
/settings): Configure all device parameters at runtime (Wi-Fi SSID & Password, Units, Theme, Screen & LED Brightness, Timezone, Hostname, Weather Update Interval, Screensaver Timeout, Static IP, AP Password, API Server, SD Settings, MQTT, etc.) and save them without reflashing. - 🔄 Firmware Update (
/update): Flash new firmware binaries wirelessly. - 📸 View Screenshot (
/screenshot): Stream a pixel-perfect image of the current screen (if enabled). Includes inline status indicators and help prompts. - 🗑️ Clear SD Logs (
/clear_logs): Delete the weather history CSV file (/weather_history.csv) stored on the microSD card. - 🗑️ Clear SD Cache (
/clear_cache): Delete the weather cache JSON file (/weather_cache.json) stored on the microSD card. - 📶 Reboot to AP Setup Mode (
/reboot_ap): Reboot the device directly into Access Point captive portal setup mode (192.168.4.1) without erasing stored device settings, coordinates, or calibration values. - ⚠️ Factory Reset (
/reset): Completely erase NVS settings and saved Wi-Fi credentials to reboot the device into AP Setup mode.
Capture Screenshot:
# Save to file
curl http://<DEVICE_IP>/screenshot -o screenshot.bmp
# View inline (if ImageMagick is installed)
curl -s http://<DEVICE_IP>/screenshot | display -
Get Configuration Settings: Retrieve the current settings in JSON format:
curl http://<DEVICE_IP>/api/config
Example JSON response:
{
"unit_system": 2,
"temp_unit": 2,
"wind_unit": 2,
"precip_unit": 2,
"pressure_unit": 2,
"brightness": 75,
"auto_brightness": false,
"show_title_version": true,
"timezone": "America/New_York",
"theme_flavor": 1,
"sd_logging_enabled": true,
"screenshot_server_enabled": false,
"hostname": "cyd-weather-station",
"api_server_enabled": true,
"screen_orientation": 1,
"display_inverted": false,
"led_enabled": true,
"led_brightness": 60,
"mqtt_enabled": true,
"mqtt_server": "192.168.1.88",
"mqtt_port": 1883,
"mqtt_user": "user",
"mqtt_password": "password",
"mqtt_base_topic": "cyd/",
"wifi_ssid": "Your_SSID",
"wifi_password": "Your_Password",
"sd_cache_enabled": true,
"screensaver_enabled": false,
"screensaver_timeout": 300000,
"screensaver_color": 0,
"sleep_schedule_enabled": false,
"sleep_start_time": "22:00",
"sleep_end_time": "07:00",
"weather_update_interval": 15,
"static_ip_enabled": false,
"static_ip": "192.168.1.8",
"static_gateway": "192.168.1.1",
"static_subnet": "255.255.255.0",
"static_dns": "1.1.1.1",
"ap_password": "",
"zip_code": "90210",
"city_code": "",
"latitude": "",
"longitude": "",
"owm_api_key": "",
"ntp_server": "pool.ntp.org",
"use_24_hour_format": false,
"local_sensor_enabled": true,
"local_sensor_type": 1,
"local_sensor_update_interval": 60,
"local_sensor_temp_offset": 0.0,
"local_sensor_hum_offset": 0.0
}
Update Configuration Settings: Update any subset of device settings dynamically by posting a JSON payload:
curl -X POST -H "Content-Type: application/json" \
-d '{"brightness": 80, "theme_flavor": 2}' \
http://<DEVICE_IP>/api/config
Response:
{"status":"ok"}
Physical BOOT button capture
Press and hold the BOOT button (GPIO 0) on the CYD board for 2 seconds. The screenshot is saved to the SD card root as /screenshot_YYYYMMDD_HHMMSS.bmp (NTP-synced timestamp). A single quick press of the BOOT button triggers an immediate weather refresh.
Serial output confirms the save:
[System] BOOT button pressed. Taking screenshot...
[Screenshot] Capture started: /screenshot_20260711_135852.bmp
[Screenshot] Capture complete.
:rocket: Getting Started
1. Quick Install (Pre-compiled Binaries)
Option A: Web Flasher (Easiest) You can easily flash the pre-compiled firmware directly from your browser using the ESP32 Web Flasher. This requires a Web Serial compatible browser (like Chrome or Edge).
Option B: Terminal Flash Script
Alternatively, you can flash the device directly from your terminal using the provided flash script. Replace /dev/ttyUSB0 with your actual serial port. By default, it flashes the cyd_28r version, but you can specify the device as the first argument.
# Flash the default cyd_28r (2.8" resistive 320x240 screen)
bash -c "$(curl -fsSL https://raw.githubusercontent.com/nicholaswilde/cyd-weather-station/main/scripts/flash.sh)" _ cyd_28r /dev/ttyUSB0
# Or flash the cyd_28c version (2.8" capacitive 320x240 screen)
bash -c "$(curl -fsSL https://raw.githubusercontent.com/nicholaswilde/cyd-weather-station/main/scripts/flash.sh)" _ cyd_28c /dev/ttyUSB0
# Or flash the cyd_28_nm version (2.8" NodeMiner ST7789 320x240 screen)
bash -c "$(curl -fsSL https://raw.githubusercontent.com/nicholaswilde/cyd-weather-station/main/scripts/flash.sh)" _ cyd_28_nm /dev/ttyUSB0
# Or flash the cyd_35c version (3.5" capacitive 480x320 screen)
bash -c "$(curl -fsSL https://raw.githubusercontent.com/nicholaswilde/cyd-weather-station/main/scripts/flash.sh)" _ cyd_35c /dev/ttyUSB0
[!WARNING] Running a script directly from the internet with
bash -c "$(curl...)"is a potential security risk. Always review the script's source code before executing it to ensure it is safe. You can view the script here.
2. Build from Source
Secrets Setup
Wi-Fi credentials and API keys live in a Git-ignored secrets file to prevent committing them.
-
Copy the template:
task init(Or manually:
cp config/secrets.h.example config/secrets.h) -
Edit
config/secrets.h:#define WIFI_SSID "Your_WiFi_Network" #define WIFI_PASSWORD "Your_WiFi_Password" // (Optional) Secure the configuration AP with a password (at least 8 chars). // Leave blank ("") or comment out to run an open Access Point. // This can also be changed at runtime via the Web Settings UI. #define AP_PASSWORD "" // (Optional) Set your API key here to use OpenWeatherMap instead of Open-Meteo. // If left empty (""), Open-Meteo API will be used as a fallback. #define OPENWEATHERMAP_API_KEY "YOUR_OPENWEATHERMAP_API_KEY"
Configuration
Static settings (location, update interval, default units) live in config/config.h. Runtime user preferences (units, brightness, theme, timezone) are changed via the on-device Settings tab, Web UI, REST API, or MQTT and saved to flash.
Weather Units:
You can set compile-time defaults for each weather metric independently in config/config.h (or fall back to the legacy UNIT_SYSTEM macro):
// Choose Unit System fallback (UNIT_METRIC or UNIT_IMPERIAL)
#define UNIT_SYSTEM UNIT_IMPERIAL
// Optional independent overrides:
// #define DEFAULT_TEMP_UNIT TEMP_UNIT_FAHRENHEIT // TEMP_UNIT_CELSIUS (1) or TEMP_UNIT_FAHRENHEIT (2)
// #define DEFAULT_WIND_UNIT WIND_UNIT_MPH // WIND_UNIT_KMH (1), MPH (2), MS (3), KNOTS (4)
// #define DEFAULT_PRECIP_UNIT PRECIP_UNIT_INCH // PRECIP_UNIT_MM (1) or PRECIP_UNIT_INCH (2)
// #define DEFAULT_PRESSURE_UNIT PRESSURE_UNIT_INHG // PRESSURE_UNIT_HPA (1), INHG (2), MBAR (3), MMHG (4)
Location:
Location (Zip Code, City Code, or Coordinates) is configured dynamically via the Captive Portal Wi-Fi Manager when the device boots in AP mode. You can pre-configure the fallback defaults in config/config.h:
// Default values (if not configured via Wi-Fi Setup)
#define WEATHER_ZIP_CODE "90210"
#define WEATHER_API_LATITUDE ""
#define WEATHER_API_LONGITUDE ""
// City Code (For OpenWeatherMap only)
#define WEATHER_CITY_CODE ""
(Note: If you leave these fields empty in both the code and the Wi-Fi Setup page, the device will automatically detect your location via IP Geolocation).
Weather update interval: You can change the update interval dynamically via the Web Settings UI, or set the default fallback here:
#define WEATHER_UPDATE_INTERVAL_MINS 15
Screensaver: The screensaver timeout can be adjusted dynamically via the Web Settings UI. Defaults are configured here:
#define SCREENSAVER_ENABLED true
#define SCREENSAVER_TIMEOUT_MS 300000 // 5 minutes (in milliseconds)
Sleep Schedule:
The sleep schedule can be configured dynamically via the Web Settings UI or MQTT. Defaults are configured in config/config.h:
#define DEFAULT_SLEEP_SCHEDULE_ENABLED false
#define DEFAULT_SLEEP_START_TIME "22:00"
#define DEFAULT_SLEEP_END_TIME "07:00"
Static IP:
Static IP can be configured directly in the Web Settings UI at runtime. Alternatively, you can uncomment the static IP settings block in config/config.h to set the default fallback values. If kept blank or commented out, the device will default to DHCP:
// #define STATIC_IP "192.168.1.100"
// #define STATIC_GATEWAY "192.168.1.1"
// #define STATIC_SUBNET "255.255.255.0"
// #define STATIC_DNS "1.1.1.1"
Display performance — tune animation smoothness vs. touch responsiveness:
// Height of the LVGL draw buffer (pixel rows).
// Larger = smoother animation; too large = unresponsive touch.
// Sweet spot on CYD hardware: 25–35.
#define DISPLAY_DRAW_BUF_ROWS 30
// How often LVGL redraws changed areas (ms). Range: 10–30.
#define DISPLAY_REFR_PERIOD_MS 20
// How often LVGL polls the touchscreen (ms). Keep <= DISPLAY_REFR_PERIOD_MS.
#define DISPLAY_INDEV_READ_PERIOD_MS 10
// Duration of the tab-switch swipe animation (ms). LVGL default: 300.
#define DISPLAY_SWIPE_ANIM_MS 150
Build & Upload
task build # Compile firmware
task upload # Flash to the connected CYD board
task monitor # Open serial monitor (115200 baud)
:gear: Settings Tab Reference
All settings below are configured by touch on the device and saved to flash:
| Setting | Description |
|---|---|
| Temp Unit | Select temperature unit: Celsius (°C) or Fahrenheit (°F). |
| Wind Unit | Select wind speed unit: km/h, mph, m/s, or kn (knots). |
| Precip Unit | Select precipitation unit: Millimeters (mm) or Inches (in). |
| Pressure Unit | Select atmospheric pressure unit: hPa, inHg, mbar, or mmHg. |
| Auto Light | Enable/disable LDR-driven automatic backlight control. |
| Brightness | Manual backlight level slider (disabled when Auto Light is on). |
| Theme | Catppuccin flavor selector — Mocha / Macchiato / Frappé / Latte. Full UI redraws on change. |
| Timezone | IANA timezone selector (– / + buttons) with automatic DST transitions via AceTime. |
| SD Log | Toggle SD card weather logging. Disabled automatically if no card is inserted. |
| SD Cache | Toggle SD card weather caching. |
| API Srv | Toggle the remote screenshot & configuration HTTP API server on/off. |
| Local Sensor | Toggle reading local temperature/humidity sensor on/off. |
| Sensor Interval | Slider adjusting local sensor read interval (seconds) with live preview. |
| Temp Offset | Numerical input with themed on-screen numeric keypad to set temperature offset (supports decimals). |
| Hum Offset | Numerical input with themed on-screen numeric keypad to set humidity offset (supports decimals). |
| Status LED | Toggle RGB status LED feedback on/off. |
| LED Brightness | Manual RGB status LED brightness level slider. |
| Scr Saver | Toggle the screensaver on/off. |
| Sleep Sched | Toggle the sleep schedule on/off. |
| MQTT | Toggle publishing weather variables to MQTT topics. |
Timezone Configuration (AceTime & IANA)
The CYD Weather Station integrates bxparks/AceTime to provide full IANA timezone database support (e.g. America/Los_Angeles, Europe/London) and automatically manages Daylight Saving Time (DST) transitions year-round without manual intervention.
You can configure the timezone via:
- On-Device Settings Tab: Cycle through presets using
–/+buttons. - Web Settings Portal (
/settings): Select from an interactive dropdown containing over 400 IANA timezone options. - REST API (
/api/config): Send a JSON payload updating the"timezone"field. - MQTT: Publish to
<base_topic>command/timezoneor control via Home Assistant's Select entity. - Config File: Set the compile-time default in
config/config.h.
The device UI Settings tab allows cycling through the following common presets:
| Region | Preset Display | IANA String |
|---|---|---|
| UTC | UTC | UTC |
| New York | New York | America/New_York |
| Chicago | Chicago | America/Chicago |
| Denver | Denver | America/Denver |
| Los Angeles | Los Angeles | America/Los_Angeles |
| London | London | Europe/London |
| Berlin | Berlin | Europe/Berlin |
| Sydney | Sydney | Australia/Sydney |
| Tokyo | Tokyo | Asia/Tokyo |
:satellite: MQTT Topics & Home Assistant Integration
When MQTT is enabled in settings, the CYD Weather Station connects to your configured MQTT broker and provides state telemetry, Home Assistant auto-discovery, system diagnostics, and bidirectional remote control commands.
[!NOTE] All telemetry, state, and command topics are prefixed with your configurable MQTT Base Topic (default:
cyd/). Home Assistant auto-discovery topics always use the standardhomeassistant/root prefix.
Telemetry & State Topics
| Topic | Description | Example / Values |
|---|---|---|
<base_topic>status |
Connection availability (LWT) | online / offline |
<base_topic>weather/temperature |
Current temperature | 72 |
<base_topic>weather/humidity |
Current relative humidity | 45 |
<base_topic>weather/wind_speed |
Current wind speed | 8 |
<base_topic>weather/wind_direction |
Current wind direction | NW |
<base_topic>weather/status |
Current weather condition | Partly Cloudy |
<base_topic>weather/city |
Resolved city name | Seattle |
<base_topic>system/uptime |
Device uptime (seconds) | 3600 |
<base_topic>system/free_heap |
Free heap memory (bytes) | 184320 |
<base_topic>system/wifi_rssi |
Wi-Fi signal strength (dBm) | -58 |
<base_topic>system/ip |
Device IP address | 192.168.1.150 |
<base_topic>system/version |
Firmware version string | v0.1.22 |
<base_topic>system/mac |
Device MAC address | B0:CB:D8:DA:77:5C |
<base_topic>settings/brightness |
Screen brightness percentage | 0–100 |
<base_topic>settings/led_brightness |
Status LED brightness percentage | 0–100 |
<base_topic>settings/auto_brightness |
Auto brightness switch state | ON / OFF |
<base_topic>settings/screensaver |
Screensaver switch state | ON / OFF |
<base_topic>settings/theme |
Catppuccin theme flavor | Mocha / Macchiato / Frappe / Latte |
<base_topic>settings/units |
Legacy unit system | Imperial / Metric |
<base_topic>settings/units/temperature |
Temperature unit | °C / °F |
<base_topic>settings/units/wind |
Wind speed unit | km/h / mph / m/s / kn |
<base_topic>settings/units/precipitation |
Precipitation unit | mm / in |
<base_topic>settings/units/pressure |
Pressure unit | hPa / inHg / mbar / mmHg |
<base_topic>settings/screen_orientation |
Display orientation | Landscape / Portrait / Landscape Rev / Portrait Rev |
<base_topic>settings/display_inversion |
Display inversion switch state | ON / OFF |
<base_topic>settings/screensaver_color |
Screensaver clock color | White / Red / Amber / Green |
<base_topic>settings/update_interval |
Weather update interval (mins) | 15 |
<base_topic>settings/screensaver_timeout |
Screensaver timeout (mins) | 5 |
<base_topic>settings/sleep_schedule |
Sleep schedule switch state | ON / OFF |
<base_topic>settings/sleep_start |
Sleep schedule start time | 22:00 |
<base_topic>settings/sleep_end |
Sleep schedule end time | 07:00 |
<base_topic>settings/timezone |
Configured IANA timezone string | America/New_York |
<base_topic>settings/hostname |
Configured device hostname | cyd-weather-station |
<base_topic>settings/led |
Status LED enabled switch state | ON / OFF |
<base_topic>settings/sd_log |
SD logging enabled switch state | ON / OFF |
<base_topic>settings/sd_cache |
SD caching enabled switch state | ON / OFF |
Remote Control Topics
| Topic | Payload | Action |
|---|---|---|
<base_topic>command/brightness |
0–100 |
Adjusts the screen backlight brightness percentage and saves setting. |
<base_topic>command/led_brightness |
0–100 |
Adjusts the status LED brightness percentage (0-100% mapped to hardware 0-255). |
<base_topic>command/auto_brightness |
ON / OFF / 1 / 0 |
Enables or disables ambient light-based automatic brightness. |
<base_topic>command/screensaver |
ON / OFF / 1 / 0 |
Enables or disables the screensaver. |
<base_topic>command/sleep_schedule |
ON / OFF / 1 / 0 |
Enables or disables the sleep schedule. |
<base_topic>command/sleep_start |
HH:MM |
Sets the sleep schedule start time (24-hour format). |
<base_topic>command/sleep_end |
HH:MM |
Sets the sleep schedule end time (24-hour format). |
<base_topic>command/timezone |
America/Los_Angeles |
Sets the device IANA timezone string with dynamic DST recalculation. |
<base_topic>command/hostname |
cyd-weather-station |
Sets the device network hostname and mDNS address. |
<base_topic>command/theme |
Mocha / Macchiato / Frappe / Latte |
Changes the active Catppuccin theme flavor. |
<base_topic>command/units |
Imperial / Metric |
Legacy command to change all units to Imperial or Metric. |
<base_topic>command/units/temperature |
°C / °F |
Changes the temperature unit independently. |
<base_topic>command/units/wind |
km/h / mph / m/s / kn |
Changes the wind speed unit independently. |
<base_topic>command/units/precipitation |
mm / in |
Changes the precipitation unit independently. |
<base_topic>command/units/pressure |
hPa / inHg / mbar / mmHg |
Changes the atmospheric pressure unit independently. |
<base_topic>command/screen_orientation |
Landscape / Portrait / Landscape Rev / Portrait Rev |
Changes display orientation dynamically. |
<base_topic>command/display_inversion |
ON / OFF / 1 / 0 |
Toggles display color inversion at runtime. |
<base_topic>command/screensaver_color |
White / Red / Amber / Green |
Changes the screensaver clock color palette. |
<base_topic>command/update_interval |
1–120 |
Sets the weather fetch update interval in minutes. |
<base_topic>command/screensaver_timeout |
1–60 |
Sets screensaver activation inactivity timeout in minutes. |
<base_topic>command/led |
ON / OFF / 1 / 0 |
Enables or disables the onboard status RGB LED. |
<base_topic>command/sd_log |
ON / OFF / 1 / 0 |
Enables or disables SD card weather history logging. |
<base_topic>command/sd_cache |
ON / OFF / 1 / 0 |
Enables or disables SD card weather caching. |
<base_topic>command/reboot |
REBOOT / 1 / true / ON |
Reboots the ESP32 weather station. |
Home Assistant MQTT Discovery
On connection, the device automatically registers itself as CYD Weather Station <short_mac> with full device hierarchy and exposes the following entities to Home Assistant:
- Weather Sensors: Temperature (°F/°C), Humidity (%), Wind Speed (mph/m/s), Wind Direction, Weather Condition, City Name.
- Diagnostics Sensors: Connection Status (binary sensor), Uptime (s), Free Memory (B), Wi-Fi Signal (dBm), IP Address, Firmware Version, MAC Address.
- Controls & Sliders (Numbers): Screen Brightness (0–100%), LED Brightness (0–100%), Weather Update Interval (1–120 min), Screensaver Timeout (1–60 min).
- Configuration Switches: Auto Brightness, Screensaver, Sleep Schedule, Status LED, SD Log, SD Cache, Invert Display.
- Configuration Selects: Theme Flavor, Screen Orientation, Screensaver Color, Unit Preferences.
- Text Controls: Sleep Start Time, Sleep End Time, Hostname.
- Dropdown Selectors: Theme Flavor, Temperature Unit, Wind Speed Unit, Precipitation Unit, Pressure Unit, Screen Orientation, Timezone.
- Buttons: Device Reboot.
Connection Management & Reconnect Backoff
If the MQTT broker goes offline or becomes unreachable, the weather station will automatically attempt to reconnect using an exponential backoff strategy (doubling the reconnect delay from 5s up to a maximum of 2 minutes) to prevent network congestion. Reconnect intervals reset back to 5s upon a successful connection. Auto-discovery payloads are throttled with asynchronous FreeRTOS pacing to ensure reliable network transmission without packet loss.
:computer: Development
This project is built with PlatformIO and supports both ESP32 hardware builds and native desktop mock testing via a CMock/Unity test suite.
Custom Weather Icon Font
Weather icons use Erik Flowers' Weather Icons font converted to LVGL C source via lv_font_conv.
- Install Node.js dependencies:
task setup:node - Regenerate the font:
task font:generate
Command Reference
| Action | Task Command | PlatformIO Equivalent | Description |
|---|---|---|---|
| Initialize | task init |
cp config/secrets.h.example config/secrets.h |
Copies the secrets template. |
| Build | task build |
pio run |
Compiles the ESP32 firmware. |
| Upload | task upload |
pio run --target upload |
Flashes firmware to the CYD board. |
| Monitor | task monitor |
pio device monitor |
Opens the serial monitor at 115200 baud. |
| Native Tests | task test |
pio test -e native |
Runs mock unit tests on the host. |
| Pre-Flight Check | task test:preflight |
— | Builds all environments and runs unit tests. |
| API Tests | task test:api |
— | Runs live JSON API integration tests against the device. |
| Web Health Check | task test:web |
— | Verifies all HTTP endpoints respond and do not crash. |
| MQTT Tests | task test:mqtt |
— | Verifies MQTT broker connectivity and command handling. |
| OTA Update | task update:ota |
— | Compiles and flashes firmware wirelessly over the network. |
| Lint Check | task check |
pio check |
Runs cppcheck static analysis. |
| Setup Node | task setup:node |
npm install |
Installs lv_font_conv for font conversion. |
| Generate Font | task font:generate |
npm run font:generate |
Rebuilds the weather icons C source from TTF. |
| Clean | task clean |
pio run --target clean |
Removes build output and temp files. |
:wrench: Troubleshooting
If you encounter any issues with your screen or the software, please review the solutions below or create an issue on GitHub if you are still stuck.
Inverted Colors
If the colors on your display appear inverted (for example, dark themes like Mocha, Macchiato, or Frappe display with bright white backgrounds while the light Latte theme appears dark), this is due to hardware display controller differences between CYD batches. You can easily resolve it by:
- Toggling Invert Display Colors at runtime in the on-device Settings tab, Web configuration portal (
/settings), REST API (/api/config), or via MQTT (command/display_inversion) without needing to re-flash firmware. - Flashing the alternative inversion release for your board (e.g.,
cyd_28rvscyd_28r_inv,cyd_28cvscyd_28c_inv,cyd_28_nmvscyd_28_nm_inv, orcyd_35cvscyd_35c_inv). - Or, if building from source, switching to the corresponding
_invenvironment in PlatformIO or toggling the-D TFT_INVERSION_ON=1build flag.
Garbled or Scrambled Screen
If the UI renders distorted, noisy, or with stretched fonts across the display, ensure you flashed the firmware matching your exact display size and controller:
- 2.8" Resistive (ILI9341):
cyd_28r/cyd_28r_inv(240x320) - 2.8" Capacitive (ESP32-2432W328C):
cyd_28c/cyd_28c_inv(240x320) - 2.8" Resistive NodeMiner / ST7789 (
ESP32-2432S028):cyd_28_nm/cyd_28_nm_inv(240x320) - 3.5" Capacitive (ST7796):
cyd_35c/cyd_35c_inv(320x480)
Flashing a 3.5" image onto a 2.8" display (or vice versa) will result in garbled screens due to framebuffer and resolution mismatches.
Partial Screen Rendering / 80px Noise Band (1/4 Screen)
If the UI displays across only 240 columns while the right 80 columns show uninitialized static noise, your board likely has an ST7789 controller or an alternative ILI9341 clone controller (common on ESP32-2432S028 boards manufactured under "NM" / NodeMiner or 2-USB variants). Pre-configured environments cyd_28_nm and cyd_28_nm_inv are available for these boards directly in platformio.ini. See the detailed guide in docs/hardware-variants.md for background and build configurations (ILI9341_2_DRIVER or ST7789_DRIVER).
Flashing, Erasing Flash & Boot Reset
- Erasing Flash: Running a full
erase_flashwipes all non-volatile storage (NVS), which erases previously saved Wi-Fi credentials and configuration. The device will reboot into Access Point (192.168.4.1) setup mode. Reflashing without erasing preserves your Wi-Fi credentials and saved runtime settings. - Bootloader Mode: If flashing manually via serial (
esptool.py), the ESP32 might remain in bootloader mode after writing. Press the physical RESET / EN button (or power cycle the unit) to boot into the application.
Local Temperature & Humidity Issues / SHT40 Troubleshooting
Standard CYD boards (including ESP32-2432W328C and CYD-2432S028) do not come with an onboard ambient temperature/humidity sensor. If no external sensor is wired to the expansion header, the local sensor readings will remain empty. You can disable the local sensor tile in Settings (/settings) or connect a supported sensor (DHT11, DHT22, or SHT40).
If you are using an SHT40 sensor and it is failing to initialize or read:
- Use the CN1 Port: Ensure you plug the sensor into the CN1 connector (near the USB port). Connector P3 (near the SD card slot) lacks a 3.3V power rail and cannot power the sensor.
- SDA Pin Selection: On
cyd_28randcyd_28_nm, ensure SDA is wired to IO27. GPIO 21 is used for display backlight PWM (TFT_BL). Oncyd_35candcyd_28c, ensure SDA is wired to IO21. IO27 is used for the display backlight. Connecting I2C to the backlight pin will interfere with I2C communications and cause the screen backlight to dim or turn off. - Swap SDA & SCL Lines: If the SHT40 sensor is not recognized or reports
[Sensor] Failed to read from SHT40 sensor!, try switching/swapping the SDA and SCL wiring pins (ensureSDA = 27(or 21) andSCL = 22).
RGB / BGR Swap
If your screen has red and blue colors swapped, it means the display expects a BGR color order instead of RGB. A dedicated release is not currently provided for this variation, but you can fix it by building from source: simply append -D TFT_RGB_ORDER=TFT_BGR to your environment's build_flags in platformio.ini.
Touch Calibration (Resistive Screens)
The 2.8" resistive version (cyd_28r) uses a resistive touch layer which can sometimes be misaligned or mapped to inverted coordinates depending on the batch. If touches are registering in the wrong place, you may need to run a touch calibration sketch to determine the correct offsets for your specific screen. Capacitive variants (cyd_28c, cyd_35c) do not require calibration.
Backlight Pin and Polarity Differences
If your screen is completely black but the board seems to be running, it might be a backlight pin mapping issue. While most boards use GPIO 21 or 27 for the backlight (TFT_BL), some obscure batches might map it differently. Furthermore, some boards require TFT_BACKLIGHT_ON=LOW instead of HIGH.
Different Driver Chips
Most 2.8" screens use the ILI9341 driver. However, occasionally manufacturers substitute it with an ST7789V driver without changing the board's appearance. This will result in a completely blank or noisy screen until you change the driver flag in your platformio.ini from -D ILI9341_DRIVER=1 to -D ST7789_DRIVER=1.
SD Card Formatting
The CYD board can be picky about SD cards. If you encounter a "Failed to initialize SD card" error:
- Ensure the microSD card is formatted as FAT32 (not exFAT).
- Try to use an SD card that is 32GB or smaller.
- Ensure it is inserted fully before booting the device.
Power Delivery Glitches
Intermittent touch issues, screen flickering, or spontaneous reboots are frequently caused by inadequate power. Ensure you are using a high-quality USB power supply and a good USB cable that can supply the burst current the ESP32 and backlight need simultaneously.
Audio Output / DAC Pins
If you ever intend to use the speaker connector on the back, be aware that the DAC pin mapping changes between board revisions. Sometimes it's mapped to GPIO 25, and sometimes GPIO 26.
:balance_scale: License
:writing_hand: Author
This project was started in 2026 by Nicholas Wilde.







