led-driver: channel default 11, bare ESP-NOW build, settings and USB config updates

Default ESP-NOW channel is now 11. Adds the bare ESP-NOW-only build option
(CONFIG_LED_ESPNOW_ONLY) with its sdkconfig fragments, a default hostname from
the Wi-Fi MAC, and the related net, link, web and settings changes.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Haiku 5.5 committed 2026-11-21 01:18:55 +13:00
1 parent 12a8e225ad
commit c9838d1cbe
18 files changed
+268 -31

No files matched your search

+19 -4
View File
@@ -1,8 +1,11 @@
/*
* SPDX-License-Identifier: Apache-2.0
*/
#include <cstdio>
#include <cstring>
#include "esp_mac.h"
#include "nvs.h"
#include "settings.h"
@@ -108,24 +111,36 @@ static void get_str(nvs_handle_t h, const char *key, char *buf, size_t len, cons
}
}
// A driver that was never named is led-<its Wi-Fi MAC, 12 lowercase hex>, so boards are told apart from the start.
// "led" was the old default and is saved by any network settings change, so it counts as not named.
static void default_hostname(char *buf, size_t len)
{
uint8_t mac[6] = {};
esp_read_mac(mac, ESP_MAC_WIFI_STA);
snprintf(buf, len, "led-%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
esp_err_t settings_load_net(net_cfg_t *c)
{
memset(c, 0, sizeof(*c));
c->ap_enabled = true;
c->ddp_enabled = true;
c->espnow_enabled = true;
c->espnow_channel = 6;
c->espnow_channel = 11;
nvs_handle_t h;
esp_err_t err = nvs_open(NS, NVS_READONLY, &h);
if (err == ESP_ERR_NVS_NOT_FOUND) {
// Nothing saved yet: defaults
strncpy(c->hostname, "led", sizeof(c->hostname) - 1);
default_hostname(c->hostname, sizeof(c->hostname));
return ESP_OK;
}
if (err != ESP_OK) {
return err;
}
get_str(h, "hostname", c->hostname, sizeof(c->hostname), "led");
get_str(h, "hostname", c->hostname, sizeof(c->hostname), "");
if (!c->hostname[0] || strcmp(c->hostname, "led") == 0) {
default_hostname(c->hostname, sizeof(c->hostname));
}
char mode[8];
get_str(h, "ip_mode", mode, sizeof(mode), "dhcp");
c->use_static = strcmp(mode, "static") == 0;
@@ -146,7 +161,7 @@ esp_err_t settings_load_net(net_cfg_t *c)
c->espnow_enabled = strcmp(espnow, "off") != 0;
int64_t ch = 6;
nvs_get_i64(h, "espnow_ch", &ch);
c->espnow_channel = (uint8_t)(ch >= 1 && ch <= 13 ? ch : 6);
c->espnow_channel = (uint8_t)(ch >= 1 && ch <= 13 ? ch : 11);
nvs_close(h);
return ESP_OK;
}