fix(api): standalone rollt bei 503 zurueck, Tests fuer Grenzen und behaltene Felder
This commit is contained in:
+7
-3
@@ -324,7 +324,7 @@ static void handle_get_settings(const nl_api_ctx_t *ctx, nl_api_response_t *resp
|
||||
/* Der WIRKSAME Name, nicht der gespeicherte: ohne eigenen Namen heisst der AP
|
||||
* wie der Hostname. Wer hier einen leeren String saehe, muesste die Vorgabe
|
||||
* selbst nachbilden. Das AP-Passwort steht bewusst nicht hier. */
|
||||
cJSON_AddStringToObject(sa, "ssid", s.ap_ssid[0] ? s.ap_ssid : (ctx->hostname ? ctx->hostname : ""));
|
||||
cJSON_AddStringToObject(sa, "ssid", s.ap_ssid[0] ? s.ap_ssid : ctx->hostname);
|
||||
cJSON_AddNumberToObject(sa, "channel", s.ap_channel ? s.ap_channel : 6);
|
||||
cJSON_AddBoolToObject(sa, "pulse", s.standalone_pulse != 0);
|
||||
}
|
||||
@@ -366,6 +366,7 @@ static void handle_put_settings(const nl_api_ctx_t *ctx, const nl_http_request_t
|
||||
long ch = 0;
|
||||
int asp, app, chp;
|
||||
bool will_enable;
|
||||
nl_settings_t prev = s; /* Stand vor der Aenderung, zum Zurueckrollen bei 503 */
|
||||
|
||||
will_enable = cJSON_IsBool(en) && cJSON_IsTrue(en);
|
||||
asp = get_string(j, "ssid", 1, NL_SSID_LEN - 1, &as);
|
||||
@@ -401,9 +402,12 @@ static void handle_put_settings(const nl_api_ctx_t *ctx, const nl_http_request_t
|
||||
* Antwort ist 202 und muss vorher ausgefuellt sein. */
|
||||
if (ctx->save_settings(&s) != 0) {
|
||||
reply_error(resp, 500, "save failed");
|
||||
} else if (!ctx->standalone_configure ||
|
||||
ctx->standalone_configure(will_enable, s.ap_ssid, s.ap_pass,
|
||||
} else if (ctx->standalone_configure(will_enable, s.ap_ssid, s.ap_pass,
|
||||
s.ap_channel, s.standalone_pulse != 0) != 0) {
|
||||
/* 503 heisst "nicht uebernommen": was schon im Flash steht, muss zurueck,
|
||||
* sonst startet die Lampe nach einem Neustart doch im neuen Modus. Best
|
||||
* effort - scheitert auch das, bleibt nur die Meldung. */
|
||||
(void)ctx->save_settings(&prev);
|
||||
reply_error(resp, 503, "wifi busy");
|
||||
} else {
|
||||
reply(resp, 202, "{\"status\":\"standalone\"}");
|
||||
|
||||
Reference in New Issue
Block a user