feat: added mdns resolution - #210
Open
IM-TechieScientist wants to merge 3 commits into
Open
Conversation
Reviewer's GuideAdds mDNS-based discovery for the PSLab Pico ESP SPI Wi-Fi bridge and introduces a first-boot Wi-Fi provisioning flow with an HTTP setup portal, refactoring Wi-Fi startup to support AP+STA and persistent credentials stored in NVS. Sequence diagram for Wi-Fi startup, provisioning, and mDNS discoverysequenceDiagram
participant udp_task
participant start_wifi
participant wifi_provisioning
participant start_station
participant mdns_service
udp_task->>start_wifi: start_wifi()
start_wifi->>wifi_provisioning: wifi_provisioning_load_credentials(credentials)
alt credentials loaded
start_wifi->>start_station: start_station(credentials)
alt station connects
start_station->>mdns_service: mdns_service_start(CONFIG_ESP_BRIDGE_LOCAL_PORT)
mdns_service-->>start_station: success
start_station-->>start_wifi: true
else station fails
start_station-->>start_wifi: false
start_wifi->>wifi_provisioning: wifi_provisioning_run(credentials)
wifi_provisioning-->>start_wifi: credentials
start_wifi->>start_station: start_station(credentials)
start_station->>mdns_service: mdns_service_start(CONFIG_ESP_BRIDGE_LOCAL_PORT)
mdns_service-->>start_station: success
start_station-->>start_wifi: true
end
else no saved credentials
start_wifi->>wifi_provisioning: wifi_provisioning_run(credentials)
wifi_provisioning-->>start_wifi: credentials
start_wifi->>start_station: start_station(credentials)
start_station->>mdns_service: mdns_service_start(CONFIG_ESP_BRIDGE_LOCAL_PORT)
mdns_service-->>start_station: success
start_station-->>start_wifi: true
end
start_wifi-->>udp_task: success / failure
alt failure
udp_task->>udp_task: vTaskDelete(NULL)
end
Sequence diagram for the new Wi-Fi HTTP provisioning flowsequenceDiagram
actor User
participant WiFi_AP as wifi_provisioning_run
participant HTTP_Server as esp_http_server
participant configure_handler
participant NVS
User->>WiFi_AP: connect to AP (WIFI_MODE_AP)
WiFi_AP->>HTTP_Server: start_server()
HTTP_Server-->>WiFi_AP: ready
User->>HTTP_Server: HTTP GET /
HTTP_Server->>configure_handler: setup_page_handler()
configure_handler-->>User: setup_page HTML
User->>HTTP_Server: HTTP POST /configure (ssid, password)
HTTP_Server->>configure_handler: configure_handler(request)
configure_handler->>configure_handler: httpd_req_recv(form)
configure_handler->>configure_handler: get_form_value(form, "ssid")
configure_handler->>configure_handler: get_form_value(form, "password")
configure_handler->>configure_handler: credentials_are_valid(credentials)
alt valid credentials
configure_handler->>NVS: save_credentials(credentials)
NVS-->>configure_handler: success
configure_handler-->>User: httpd_resp_sendstr("Saved")
configure_handler->>WiFi_AP: xEventGroupSetBits(PROVISIONING_COMPLETE_BIT)
WiFi_AP->>WiFi_AP: stop_server()
WiFi_AP->>WiFi_AP: esp_wifi_stop()
WiFi_AP-->>WiFi_AP: return credentials
else invalid / save error
configure_handler-->>User: httpd_resp_send_err(...)
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="esp_firmware/main/main.c" line_range="201-210" />
<code_context>
+static bool start_station(wifi_provisioning_credentials_t const *credentials)
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider more consistent cleanup when station start fails
In `start_station`, failures from `esp_wifi_set_mode`, `esp_wifi_set_config`, or `esp_wifi_start` return `false` without calling `esp_wifi_stop()`. This can leave the Wi-Fi driver partially configured if earlier calls succeeded. Since you already stop Wi-Fi when `esp_wifi_set_ps` fails, consider also calling `esp_wifi_stop()` on these earlier failures to keep error handling consistent and avoid issues on retries.
Suggested implementation:
```c
static bool start_station(wifi_provisioning_credentials_t const *credentials)
{
wifi_config_t wifi_config = { 0 };
strncpy((char *)wifi_config.sta.ssid, credentials->ssid, sizeof(wifi_config.sta.ssid));
strncpy((char *)wifi_config.sta.password, credentials->password, sizeof(wifi_config.sta.password));
if (esp_wifi_set_mode(WIFI_MODE_STA) != ESP_OK) {
ESP_LOGE(TAG, "Failed to set WiFi mode to STA");
// Stop Wi-Fi to clean up any partial configuration before returning.
esp_wifi_stop();
return false;
}
if (esp_wifi_set_config(WIFI_IF_STA, &wifi_config) != ESP_OK) {
ESP_LOGE(TAG, "Failed to set WiFi station configuration");
// Stop Wi-Fi to clean up any partial configuration before returning.
esp_wifi_stop();
return false;
}
if (esp_wifi_start() != ESP_OK) {
ESP_LOGE(TAG, "Failed to start WiFi station");
// Stop Wi-Fi to clean up any partial configuration before returning.
esp_wifi_stop();
return false;
}
if (esp_wifi_set_ps(WIFI_PS_MAX_MODEM) != ESP_OK) {
ESP_LOGE(TAG, "Failed to set WiFi power save mode");
esp_wifi_stop();
return false;
}
return true;
}
```
- If your actual `start_station` implementation differs (e.g., different logging messages, no `wifi_config_t` initialization, or different power-save settings), adjust the `SEARCH` block to match the exact existing code so the replacement applies cleanly.
- Ensure `esp_wifi_stop()` is safe to call in your initialization sequence; if you have additional state tracking around Wi-Fi initialization, you may want to guard these `esp_wifi_stop()` calls with that state (e.g., only stopping if Wi-Fi has been initialized).
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
IM-TechieScientist
force-pushed
the
wifi-mdns-discovery
branch
from
August 14, 2026 16:06
3a8a23c to
2f1928c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Working on #208.
Adds mDNS discovery to the ESP SPI Wifi bridge.
pslab-pico.localafter station mode connects._pslab._tcp.espressif/mdnsESP-IDF managed component.Users can now directly connect to their PSLab Pico through the domain name without requiring an IP address.
This PR follows up on #209 and is stacked on it as it is a direct dependency.
Summary by Sourcery
Add Wi-Fi provisioning and mDNS discovery to make the ESP SPI bridge self-configuring and discoverable on the local network.
New Features:
Enhancements:
Build:
Documentation: