feat: access point name and password setting, ap_on in status

- ap_ssid and ap_password on /api/network: empty name uses led-XXXXXX, a password of 8-63 characters
  makes the access point WPA2, empty is open; the password is never sent back (ap_password_set)
- a running access point restarts when its name or password changes
- /api/status reports ap_on; the web page gets the fields

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Sonnet 5.5 committed 2026-11-12 00:46:04 +13:00
1 parent af82cb4c4a
commit 59eb37cad5
7 files changed
+97 -6

No files matched your search

+24
View File
@@ -244,6 +244,7 @@ static esp_err_t status_get(api_req_t *req)
settings_load_net(&n);
cJSON *o = preset_to_json(&p);
cJSON_AddStringToObject(o, "ap_ssid", ap);
cJSON_AddBoolToObject(o, "ap_on", net_ap_on());
cJSON_AddStringToObject(o, "hostname", n.hostname);
cJSON_AddBoolToObject(o, "sta_connected", up);
cJSON_AddStringToObject(o, "sta_ip", ip);
@@ -389,6 +390,11 @@ static esp_err_t network_get(api_req_t *req)
cJSON_AddBoolToObject(o, "connected", up);
cJSON_AddStringToObject(o, "current_ip", ip);
cJSON_AddBoolToObject(o, "ap_enabled", n.ap_enabled);
char ap_name[33];
net_ap_ssid(ap_name, sizeof(ap_name));
cJSON_AddStringToObject(o, "ap_ssid", ap_name); // the name in use now
cJSON_AddBoolToObject(o, "ap_ssid_custom", n.ap_ssid[0] != '\0');
cJSON_AddBoolToObject(o, "ap_password_set", strlen(n.ap_pass) >= 8); // the password itself is never sent
cJSON_AddBoolToObject(o, "ddp_enabled", n.ddp_enabled);
return send_json(req, o);
}
@@ -448,6 +454,24 @@ static esp_err_t network_post(api_req_t *req)
if (cJSON_IsBool(ap)) {
n.ap_enabled = cJSON_IsTrue(ap);
}
// Access point name: empty goes back to led-XXXXXX. Password: empty is open, else 8-63 characters.
cJSON *apn = cJSON_GetObjectItem(in, "ap_ssid");
if (cJSON_IsString(apn)) {
if (strlen(apn->valuestring) > 32) {
cJSON_Delete(in);
return send_error(req, "400 Bad Request", "ap_ssid: up to 32 characters, or empty for the default name");
}
snprintf(n.ap_ssid, sizeof(n.ap_ssid), "%s", apn->valuestring);
}
cJSON *app = cJSON_GetObjectItem(in, "ap_password");
if (cJSON_IsString(app)) {
const size_t plen = strlen(app->valuestring);
if (plen != 0 && (plen < 8 || plen > 63)) {
cJSON_Delete(in);
return send_error(req, "400 Bad Request", "ap_password: empty (open) or 8-63 characters");
}
snprintf(n.ap_pass, sizeof(n.ap_pass), "%s", app->valuestring);
}
cJSON *ddp = cJSON_GetObjectItem(in, "ddp_enabled");
if (cJSON_IsBool(ddp)) {
n.ddp_enabled = cJSON_IsTrue(ddp);