Skip to main content

Crate wifi_caddy_proc

Crate wifi_caddy_proc 

Source
Expand description

§wifi-caddy-proc

Proc macro for WiFi caddy config structs. Derive WifiCaddyConfig on your config struct to generate storage, form HTML/JS, and the group API. All generated code references only wifi_caddy::* — no platform-specific dependencies.

Config storage traits and types live in wifi-caddy (module config_storage). This crate only runs at compile time; the macro expands to full paths (wifi_caddy::config_storage::..., wifi_caddy::ConfigStorageParams, etc.) so you do not need to import that module.

Platform-specific initialization (e.g. esp_wifi_caddy::wifi_init!) is handled by the platform crate, which uses the CONFIG_STORAGE_PARAMS and CONFIG_UI_OPTIONS statics generated by this macro.

For architecture overview, boot flow, and prerequisites, see the wifi-caddy README.

§Usage

One derive plus struct-level attributes:

use wifi_caddy_proc::WifiCaddyConfig;

#[derive(Clone, Debug, Serialize, Deserialize, WifiCaddyConfig)]
#[config_server]
#[config_notify]
#[config_ui(
    page_heading = "My App",
    title = "My App - Configuration",
)]
pub struct AppConfig {
    #[config_store(env_default = "WIFI_SSID", notify = "Wifi")]
    #[config_form(fieldset = "WiFi", help = "Network name")]
    wifi_ssid: String,
    #[config_store(env_default = "WIFI_PASS", notify = "Wifi")]
    #[config_form(fieldset = "WiFi", input_type = "password", help = "Password")]
    wifi_pass: String,
}

With esp-wifi-caddy, use esp_wifi_caddy::wifi_init!(AppConfig, ...) to start the HTTP config server. Use page = "Name" on #[config_form] to split fields across multiple tabs; omit it for single-page (group "main").

§Dependencies required by generated code

The derive macro expands into code that references these crates — they must be in your Cargo.toml for the generated code to compile.

Always required:

CrateUsed for
wifi-caddyConfig traits (ConfigStorage, ConfigApi, ConfigValue, …) and statics
serdeSerialize / Deserialize on per-group DTOs
serde-json-coreto_slice / from_str in ConfigApi impl
enumsetEnumSet<ConfigChange> changed-set type

With #[config_notify]:

CrateUsed for
embassy-syncChannel, CriticalSectionRawMutex
static_cellStatic storage for the notify channel

With #[config_server]:

CrateUsed for
wifi-caddyConfigStorageParams, ConfigUiOptions types for statics

See wifi-example/Cargo.toml for a complete working [dependencies] section.

§Field types

Supported config field types: String, u8, u16, u32, u64, i8, i16, i32, i64, f32, f64.

§Field and struct attributes

Use these on your config struct and its fields when deriving WifiCaddyConfig.

§#[config_store(...)] (per field)

  • default = "value" – literal default when the key is missing.
  • env_default = "VAR_NAME" – default from env at compile time (option_env!).
  • skip – omit from storage.
  • notify = "VariantName" – PascalCase variant for ConfigChange when this field changes.
  • bump = "field_name" – when this field is set, also increment the given numeric field.

§#[config_form(...)] (per field)

  • page = "Name" – assign this field to a tab. All fields with the same page appear on that tab. Omit for single-page (default "main"). Groups (fieldsets) cannot span pages.
  • fieldset = "Legend Text" – wrap in a <fieldset> with that legend.
  • help = "..." – help text.
  • input_type = "password" – for string fields; default "text".
  • min / max – for numeric fields (integer, float, or string literal e.g. min = "-100", max = "3.14").
  • label = "..." – override default label.
  • hidden – include in form but render as hidden input.
  • skip – omit from form. (Fields with no config_form are already excluded.)

§#[config_server(...)] (struct-level only)

  • storage_magic, storage_version – override flash config storage params.
  • Omit the attribute to disable the statics block entirely.

§#[config_notify] (struct-level only)

  • Generate channel for config change notifications. Optional: #[config_notify(cap = N)] to tune channel capacity (default: number of config pages).

§#[config_ui(...)] (struct-level only)

  • page_heading, title, subtitle, nav_left, nav_right – strings for the config page; all optional. Defaults: page_heading and title "Configuration", subtitle "", nav as in generated code.
  • extra_css = "..." – custom CSS appended after the built-in stylesheet; use to override colors, sizing, or layout.
  • default_group = "Name" – which tab to show first when using multiple pages. Default "main".

§License

MIT OR Apache-2.0

Derive Macros§

WifiCaddyConfig
Derive macro for WiFi caddy config structs.