# mfactory-osaka/esptimecast architecture

> Architecture diagram of the GitHub repository mfactory-osaka/esptimecast, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mfactory-osaka/esptimecast
- Repository: https://github.com/mfactory-osaka/esptimecast

## Overview

#### Purpose and Entry Points
ESPTimeCast is Arduino firmware for Wi‑Fi-connected ESP8266/ESP32 LED matrix clocks using MAX7219 hardware. It synchronizes time, retrieves weather, hosts local configuration/control endpoints, and renders rotating display modes. Platform-specific sketch entry points are `ESPTimeCast_ESP32/ESPTimeCast_ESP32.ino` and `ESPTimeCast_ESP8266/ESPTimeCast_ESP8266.ino`.

#### Platform Split
The repository maintains parallel firmware implementations for ESP32-family and ESP8266-family targets rather than a shared core. Each target owns its sketch, embedded UI, lookup data, font, and version metadata:
- `ESPTimeCast_ESP32/ESPTimeCast_ESP32.ino`
- `ESPTimeCast_ESP8266/ESPTimeCast_ESP8266.ino`
- `ESPTimeCast_ESP32/version.h`

The ESP32 path supports the wider ESP32/S2/S3/C3 board family; ESP8266 has its own networking/TLS constraints, notably for Nightscout bridge behavior.

#### Boot, Network, and Persistence
Firmware boots into either configured Wi‑Fi client mode or a recovery/first-time AP mode. AP mode exposes the setup portal when Wi‑Fi cannot connect. Configuration, credentials, API keys, display preferences, and persistent messages are stored in LittleFS; config backup/restore is exposed through HTTP endpoints. OTA capability depends on target flash partitioning and is served by the firmware web interface.

#### Embedded Web and HTTP Control Boundary
The device runs an asynchronous HTTP server, serving an embedded browser UI and machine-oriented endpoints. The UI payload is compiled into firmware rather than uploaded as filesystem assets:
- `ESPTimeCast_ESP32/index_html.h`
- `ESPTimeCast_ESP8266/index_html.h`

`/action` is the central local-network control boundary for UI, Home Assistant, scripts, and the companion browser extension. It accepts display/navigation settings, messages, brightness, timers, stopwatch, Pomodoro, persistence, and restart commands. Temporary API messages are distinct from persistent UI messages, with protected-message conflict behavior.

#### Time, Weather, and External Data
The runtime periodically obtains time from configurable NTP servers, applies IANA timezone/DST rules, and fetches weather from OpenWeatherMap using configured location and API credentials. Weather/time availability drives display fallbacks. Optional bridge behavior repurposes a secondary server/URL setting for RSS headlines, YouTube counts, or Nightscout glucose data; ESP32 can directly use HTTPS where ESP8266 may use an intermediary bridge.

Timezone and localization lookup data are compiled in:
- `ESPTimeCast_ESP32/tz_lookup.h`
- `ESPTimeCast_ESP32/days_lookup.h`
- `ESPTimeCast_ESP32/months_lookup.h`

#### Display State Machine and Hardware Output
The main loop coordinates a mode scheduler and priority overrides. Normal rotation includes clock, weather, optional description/date/countdown/Nightscout, and persistent message modes. Higher-priority timer, stopwatch, Pomodoro, and protected/temporary messages can take control; expiration returns rendering to the appropriate saved or rotating state. Output is rendered through MD_Parola/MD_MAX72xx to an 8×32 MAX7219 matrix over board-specific SPI GPIO mappings.

Custom glyphs, icons, day symbols, and visual status states are firmware assets:
- `ESPTimeCast_ESP32/mfactoryfont.h`
- `ESPTimeCast_ESP8266/mfactoryfont.h`

#### Material Dependencies and Interfaces
Firmware is built in Arduino IDE against ESP8266 or Espressif ESP32 board runtimes, ArduinoJson, MD_Parola/MD_MAX72xx, ESPAsyncWebServer, and platform async TCP libraries. External interfaces are Wi‑Fi, local HTTP/mDNS, NTP, OpenWeatherMap, optional Nightscout/RSS/YouTube bridge sources, OTA update clients, and physical GPIO buttons. The browser installer at esptimecast.com and companion extension are external delivery/control clients, not code contained in this repository.

Main entry points: [`ESPTimeCast_ESP32/ESPTimeCast_ESP32.ino`](https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP32/ESPTimeCast_ESP32.ino) (ESP32 sketch), [`ESPTimeCast_ESP8266/ESPTimeCast_ESP8266.ino`](https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP8266/ESPTimeCast_ESP8266.ino) (ESP8266 sketch), [`ESPTimeCast_ESP32/index_html.h`](https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP32/index_html.h) (Embedded web UI), [`ESPTimeCast_ESP32/version.h`](https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP32/version.h) (Version metadata)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_esp32["ESP32 firmware"]
  node_esp32_sketch["ESP32 sketch<br/>Arduino entry point"]
  node_esp32_ui["Embedded web UI<br/>compiled HTML<br/>[index_html.h]"]
  node_esp32_version["Version metadata<br/>firmware metadata<br/>[version.h]"]
  node_esp32_locale["Timezone and locale data<br/>compiled lookup data<br/>[tz_lookup.h]"]
  node_esp32_font["Display font assets<br/>custom glyphs<br/>[mfactoryfont.h]"]
end

subgraph group_esp8266["ESP8266 firmware"]
  node_esp8266_sketch["ESP8266 sketch<br/>Arduino entry point"]
  node_esp8266_ui["Embedded web UI<br/>compiled HTML<br/>[index_html.h]"]
  node_esp8266_font["Display font assets<br/>custom glyphs<br/>[mfactoryfont.h]"]
end

subgraph group_runtime["Device runtime"]
  node_boot_network{{"Boot and Wi-Fi state<br/>connection state machine"}}
  node_littlefs[("LittleFS settings<br/>persistent storage")]
  node_http_server["Async HTTP server<br/>local control API"]
  node_action_api{{"/action control<br/>HTTP command boundary"}}
  node_time_weather["Time and weather sync<br/>periodic data services"]
  node_optional_bridge["Optional external bridge<br/>secondary data source"]
  node_display_scheduler{{"Display scheduler<br/>priority state machine"}}
  node_matrix_output["MAX7219 matrix<br/>SPI hardware output"]
  node_physical_buttons(("GPIO buttons<br/>physical input"))
end

node_external_clients(("Local clients<br/>UI and automation clients"))
node_internet_services(("Internet services<br/>external APIs"))

node_esp32_sketch -->|"boots"| node_boot_network
node_esp8266_sketch -->|"boots"| node_boot_network
node_esp32_sketch -->|"runs"| node_http_server
node_esp8266_sketch -->|"runs"| node_http_server
node_esp32_ui -->|"served by"| node_http_server
node_esp8266_ui -->|"served by"| node_http_server
node_boot_network -->|"loads settings"| node_littlefs
node_http_server -->|"backup and restore"| node_littlefs
node_external_clients -->|"local HTTP"| node_http_server
node_http_server -->|"routes"| node_action_api
node_action_api -->|"persists settings"| node_littlefs
node_action_api -->|"controls"| node_display_scheduler
node_boot_network -->|"connectivity"| node_time_weather
node_internet_services -->|"NTP and weather"| node_time_weather
node_internet_services -->|"optional feeds"| node_optional_bridge
node_time_weather -->|"time and weather state"| node_display_scheduler
node_optional_bridge -.->|"secondary content"| node_display_scheduler
node_physical_buttons -->|"local controls"| node_display_scheduler
node_esp32_locale -->|"timezone and localization"| node_time_weather
node_display_scheduler -->|"renders current mode"| node_matrix_output
node_esp32_font -->|"glyphs"| node_matrix_output
node_esp8266_font -->|"glyphs"| node_matrix_output
node_esp32_version -->|"build metadata"| node_esp32_sketch

click node_esp32_sketch "https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP32/ESPTimeCast_ESP32.ino"
click node_esp32_ui "https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP32/index_html.h"
click node_esp32_version "https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP32/version.h"
click node_esp32_locale "https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP32/tz_lookup.h"
click node_esp32_font "https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP32/mfactoryfont.h"
click node_esp8266_sketch "https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP8266/ESPTimeCast_ESP8266.ino"
click node_esp8266_ui "https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP8266/index_html.h"
click node_esp8266_font "https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP8266/mfactoryfont.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_esp32_sketch,node_esp32_ui,node_esp32_version,node_esp32_locale,node_esp32_font toneBlue
class node_esp8266_sketch,node_esp8266_ui,node_esp8266_font toneAmber
class node_boot_network,node_littlefs,node_http_server,node_action_api,node_time_weather,node_optional_bridge,node_display_scheduler,node_matrix_output,node_physical_buttons toneMint
class node_external_clients,node_internet_services toneNeutral
```

## Components

### ESP32 firmware

- [ESP32 sketch](https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP32/ESPTimeCast_ESP32.ino): Arduino entry point · Supports ESP32-family boards. · `ESPTimeCast_ESP32/ESPTimeCast_ESP32.ino`
- [Embedded web UI](https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP32/index_html.h): compiled HTML · `ESPTimeCast_ESP32/index_html.h`
- [Version metadata](https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP32/version.h): firmware metadata · `ESPTimeCast_ESP32/version.h`
- [Timezone and locale data](https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP32/tz_lookup.h): compiled lookup data · `ESPTimeCast_ESP32/tz_lookup.h`
- [Display font assets](https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP32/mfactoryfont.h): custom glyphs · `ESPTimeCast_ESP32/mfactoryfont.h`

### ESP8266 firmware

- [ESP8266 sketch](https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP8266/ESPTimeCast_ESP8266.ino): Arduino entry point · Uses target-specific networking and TLS behavior. · `ESPTimeCast_ESP8266/ESPTimeCast_ESP8266.ino`
- [Embedded web UI](https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP8266/index_html.h): compiled HTML · `ESPTimeCast_ESP8266/index_html.h`
- [Display font assets](https://github.com/mfactory-osaka/esptimecast/blob/main/ESPTimeCast_ESP8266/mfactoryfont.h): custom glyphs · `ESPTimeCast_ESP8266/mfactoryfont.h`

### Device runtime

- **Boot and Wi-Fi state**: connection state machine · Uses client Wi-Fi or recovery setup AP mode.
- **LittleFS settings**: persistent storage · Stores credentials, configuration, API keys, and messages.
- **Async HTTP server**: local control API · Serves UI, backup/restore, OTA, and control endpoints.
- **/action control**: HTTP command boundary · Accepts display, message, timer, persistence, and restart commands.
- **Time and weather sync**: periodic data services · Applies NTP, timezone/DST rules, and OpenWeatherMap data.
- **Optional external bridge**: secondary data source · Provides RSS, YouTube, or Nightscout data; ESP8266 may require an intermediary.
- **Display scheduler**: priority state machine · Rotates normal modes and applies timer, message, and Pomodoro overrides.
- **MAX7219 matrix**: SPI hardware output · Renders through MD_Parola and MD_MAX72xx to the 8×32 LED display.
- **GPIO buttons**: physical input

### Other components

- **Local clients**: UI and automation clients · Browser UI, Home Assistant, scripts, and companion extension.
- **Internet services**: external APIs · NTP, OpenWeatherMap, and optional bridge sources.

## Connections

- ESP32 sketch → Boot and Wi-Fi state: boots
- ESP8266 sketch → Boot and Wi-Fi state: boots
- ESP32 sketch → Async HTTP server: runs
- ESP8266 sketch → Async HTTP server: runs
- Embedded web UI → Async HTTP server: served by
- Embedded web UI → Async HTTP server: served by
- Boot and Wi-Fi state → LittleFS settings: loads settings
- Async HTTP server → LittleFS settings: backup and restore
- Local clients → Async HTTP server: local HTTP
- Async HTTP server → /action control: routes
- /action control → LittleFS settings: persists settings
- /action control → Display scheduler: controls
- Boot and Wi-Fi state → Time and weather sync: connectivity
- Internet services → Time and weather sync: NTP and weather
- Internet services → Optional external bridge: optional feeds
- Time and weather sync → Display scheduler: time and weather state
- Optional external bridge → Display scheduler: secondary content
- GPIO buttons → Display scheduler: local controls
- Timezone and locale data → Time and weather sync: timezone and localization
- Display scheduler → MAX7219 matrix: renders current mode
- Display font assets → MAX7219 matrix: glyphs
- Display font assets → MAX7219 matrix: glyphs
- Version metadata → ESP32 sketch: build metadata
