Skip to content

feat: add Wi-Fi SoftAP provisioning - #209

Open
IM-TechieScientist wants to merge 2 commits into
fossasia:dev26from
IM-TechieScientist:wifi-softap-provisioning
Open

feat: add Wi-Fi SoftAP provisioning#209
IM-TechieScientist wants to merge 2 commits into
fossasia:dev26from
IM-TechieScientist:wifi-softap-provisioning

Conversation

@IM-TechieScientist

@IM-TechieScientist IM-TechieScientist commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Working on #208.

Adds first-run Wi-Fi provisioning to the ESP32 SPI bridge.

Instead of compiling station credentials into the firmware, a board without
saved credentials now starts a temporary WPA2 setup access point named:

PSLab-Pico-XXXX

The user connects to that access point and opens http://192.168.4.1 to enter
the target Wi-Fi SSID and password. Credentials are stored in ESP NVS and the
bridge then switches to normal station mode.

Changes:

  • Add a dedicated wifi_provisioning module.
  • Store and load station credentials from ESP NVS.
  • Start a temporary SoftAP only when credentials are missing.
  • Serve a minimal browser based setup form at 192.168.4.1.
  • Reenter provisioning after saved credentials repeatedly fail to connect.
  • Remove compile time SSID/password configuration.

Summary by Sourcery

Add first-run Wi-Fi SoftAP provisioning to the ESP32 SPI bridge so boards can be configured via a local web setup page and then connect as Wi-Fi stations using stored credentials.

New Features:

  • Introduce a Wi-Fi provisioning module that starts a temporary WPA2 setup access point and serves a browser-based configuration page.
  • Persist user-entered station SSID and password in ESP NVS for reuse across boots.
  • Automatically fall back to the provisioning access point when no credentials are stored or saved credentials fail to connect.

Enhancements:

  • Refactor Wi-Fi startup to separate station connection logic from overall Wi-Fi initialization and provisioning flow.

Build:

  • Register the new Wi-Fi provisioning component in CMake and declare required ESP-IDF dependencies for Wi-Fi, HTTP server, networking, timers, and NVS.

Documentation:

  • Update firmware README with instructions for using the temporary provisioning access point and web setup page, including default password configuration.

Copilot AI lite review requested due to automatic review settings August 11, 2026 15:46

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @IM-TechieScientist, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sourcery-ai

sourcery-ai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implements first-run Wi-Fi SoftAP provisioning on the ESP32 bridge by introducing a dedicated provisioning module that serves a minimal HTTP form, persists credentials in NVS, and integrates with the existing Wi-Fi startup flow to switch between AP provisioning and normal station mode based on saved credentials and connection success.

Sequence diagram for Wi-Fi startup and SoftAP provisioning flow

sequenceDiagram
    participant ESPMain as main.c
    participant WifiProv as wifi_provisioning
    participant NVS as nvs
    participant WiFi as esp_wifi

    ESPMain->>WifiProv: wifi_provisioning_load_credentials(credentials)
    WifiProv->>NVS: nvs_open / nvs_get_str
    NVS-->>WifiProv: ssid/password or error
    WifiProv-->>ESPMain: loaded? (bool)

    alt no saved credentials
        ESPMain->>WifiProv: wifi_provisioning_run(credentials)
        WifiProv->>WiFi: esp_wifi_set_mode(WIFI_MODE_AP)
        WifiProv->>WiFi: esp_wifi_set_config(WIFI_IF_AP, ap_config)
        WifiProv->>WiFi: esp_wifi_start()
        WifiProv->>WifiProv: start_server()
        WifiProv-->>ESPMain: credentials
    end

    ESPMain->>WiFi: start_station(credentials)
    WiFi-->>ESPMain: connected? (bool)

    alt saved station connection failed
        ESPMain->>WifiProv: wifi_provisioning_run(credentials)
        WifiProv-->>ESPMain: new credentials
        ESPMain->>WiFi: start_station(credentials)
    end
Loading

Sequence diagram for HTTP-based credential provisioning

sequenceDiagram
    actor User
    participant AP as SoftAP_192_168_4_1
    participant Httpd as esp_http_server
    participant WifiProv as wifi_provisioning
    participant NVS as nvs

    User->>AP: Connect to PSLab-Pico-XXXX
    User->>Httpd: GET /
    Httpd->>WifiProv: setup_page_handler()
    WifiProv-->>Httpd: setup_page (HTML)
    Httpd-->>User: Wi-Fi setup form

    User->>Httpd: POST /configure (ssid, password)
    Httpd->>WifiProv: configure_handler(request)
    WifiProv->>WifiProv: get_form_value("ssid") / get_form_value("password")
    WifiProv->>WifiProv: credentials_are_valid()
    WifiProv->>NVS: nvs_set_str / nvs_commit
    NVS-->>WifiProv: ESP_OK
    WifiProv->>WifiProv: xEventGroupSetBits(PROVISIONING_COMPLETE_BIT)
    WifiProv-->>Httpd: httpd_resp_sendstr("Saved")
    Httpd-->>User: Confirmation page
Loading

File-Level Changes

Change Details Files
Refactor Wi-Fi startup logic to support credential-based station startup and provisioning fallback.
  • Replace compile-time SSID/password use with a credentials struct passed into station startup.
  • Add start_station() that configures and starts the STA interface, waits for connection bits, and cleanly stops Wi-Fi on failure.
  • Extend start_wifi() to initialize netif/event loop, create both AP and STA interfaces, register Wi-Fi/IP event handlers, and orchestrate loading credentials and running provisioning when needed.
  • Handle initial missing credentials by starting provisioning, then joining STA with returned credentials; on failed STA connection, re-enter provisioning and retry.
esp_firmware/main/main.c
Add a Wi-Fi provisioning module that exposes NVS-backed credential loading and an interactive SoftAP-based configuration flow via HTTP.
  • Define wifi_provisioning_credentials_t and public APIs wifi_provisioning_load_credentials() and wifi_provisioning_run().
  • Implement NVS storage helpers to save and load SSID/password with basic validation on retrieved credentials.
  • Start a temporary WPA2 SoftAP with a MAC-derived SSID and configurable password, using the pre-created AP netif and esp_wifi APIs.
  • Run an embedded HTTP server that serves a minimal HTML setup page and a POST endpoint that parses application/x-www-form-urlencoded SSID/password, validates input length, saves to NVS, and signals completion via an event group.
  • Ensure Wi-Fi AP and HTTP server are stopped on completion or error, returning the selected credentials to the caller.
esp_firmware/main/wifi_provisioning.c
esp_firmware/main/wifi_provisioning.h
Update build configuration and documentation for runtime Wi-Fi provisioning and new module dependencies.
  • Add wifi_provisioning.c to the main component sources and declare required ESP-IDF components such as esp_http_server, esp_wifi, esp_netif, lwip, and nvs_flash.
  • Document first-boot SoftAP behavior, setup URL, default provisioning password, and automatic fallback to provisioning when saved credentials fail.
  • Remove references to compile-time station SSID/password configuration from the README and associated Kconfig/sdkconfig defaults entries.
esp_firmware/main/CMakeLists.txt
esp_firmware/README.md
esp_firmware/main/Kconfig.projbuild
esp_firmware/sdkconfig.defaults

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants