feat: Wi-Fi access point with a setting, password and boot button

The controller runs an AP (SSID = hostname, 192.168.5.1) next to ESP-NOW,
on by default. Network settings gain an on/off switch (ap_enabled) and an
optional WPA2 password (ap_password, 8-63 chars; empty is open). A button
on D7 (GPIO44) held at boot forces the AP on.

Wi-Fi now starts before Ethernet, and a missing W5500 no longer aborts the
boot: the web server and mDNS start anyway so the AP stays usable.

Network tuning found while testing over the AP: HTTP backlog 10 and 12 open
sockets (the default 5 dropped the 6th SYN, a 1 s stall on every page load),
larger TCP and Wi-Fi buffers, and IPv6 link-local addresses so mDNS answers
AAAA queries (browsers waited about a second for them).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Sonnet 5.5 committed 2026-11-10 01:46:05 +13:00
1 parent 9989dd3062
commit f85021d40d
11 files changed
+197 -22

No files matched your search

+40 -2
View File
@@ -210,12 +210,50 @@ void espnow_tx_stats(espnow_stats_t *out)
*out = s_stats;
}
esp_err_t espnow_tx_init(void)
// A link-local IPv6 address on the AP lets the mDNS responder answer the AAAA half of a browser's
// lookup; without it the browser waits about a second for an answer that never comes.
static esp_netif_t *s_ap_netif;
static void ap_event(void *arg, esp_event_base_t base, int32_t id, void *data)
{
if (s_ap_netif) {
esp_netif_create_ip6_linklocal(s_ap_netif);
}
}
esp_err_t espnow_tx_init(const char *ap_ssid, const char *ap_password)
{
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_RETURN_ON_ERROR(esp_wifi_init(&cfg), TAG, "wifi init");
ESP_RETURN_ON_ERROR(esp_wifi_set_storage(WIFI_STORAGE_RAM), TAG, "storage");
ESP_RETURN_ON_ERROR(esp_wifi_set_mode(WIFI_MODE_STA), TAG, "mode");
if (ap_ssid) {
// Not the Ethernet fallback subnet (192.168.4.x)
esp_netif_t *ap = esp_netif_create_default_wifi_ap();
ESP_RETURN_ON_FALSE(ap, ESP_FAIL, TAG, "ap netif");
s_ap_netif = ap;
ESP_RETURN_ON_ERROR(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_AP_START, ap_event, NULL), TAG, "ap event");
esp_netif_ip_info_t ip = { 0 };
ip.ip.addr = ESP_IP4TOADDR(192, 168, 5, 1);
ip.gw.addr = ip.ip.addr;
ip.netmask.addr = ESP_IP4TOADDR(255, 255, 255, 0);
esp_netif_dhcps_stop(ap);
ESP_RETURN_ON_ERROR(esp_netif_set_ip_info(ap, &ip), TAG, "ap ip");
esp_netif_dhcps_start(ap);
wifi_config_t ac = { 0 };
strlcpy((char *)ac.ap.ssid, ap_ssid, sizeof(ac.ap.ssid));
ac.ap.ssid_len = strlen((char *)ac.ap.ssid);
ac.ap.channel = CONFIG_ESPNOW_CHANNEL;
if (ap_password && strlen(ap_password) >= 8) {
strlcpy((char *)ac.ap.password, ap_password, sizeof(ac.ap.password));
ac.ap.authmode = WIFI_AUTH_WPA2_PSK;
} else {
ac.ap.authmode = WIFI_AUTH_OPEN;
}
ac.ap.max_connection = 4;
ESP_RETURN_ON_ERROR(esp_wifi_set_mode(WIFI_MODE_APSTA), TAG, "mode");
ESP_RETURN_ON_ERROR(esp_wifi_set_config(WIFI_IF_AP, &ac), TAG, "ap config");
} else {
ESP_RETURN_ON_ERROR(esp_wifi_set_mode(WIFI_MODE_STA), TAG, "mode");
}
ESP_RETURN_ON_ERROR(esp_wifi_start(), TAG, "start");
ESP_RETURN_ON_ERROR(esp_wifi_set_ps(WIFI_PS_NONE), TAG, "ps");
ESP_RETURN_ON_ERROR(esp_wifi_set_max_tx_power(80), TAG, "tx power"); // 20 dBm