change light mode
day/night/simulation Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
@@ -309,7 +309,37 @@ esp_err_t api_light_mode_handler(httpd_req_t *req)
|
||||
|
||||
ESP_LOGI(TAG, "Received light mode: %s", buf);
|
||||
|
||||
// TODO: Parse JSON and set light mode
|
||||
cJSON *json = cJSON_Parse(buf);
|
||||
if (json)
|
||||
{
|
||||
cJSON *mode = cJSON_GetObjectItem(json, "mode");
|
||||
if (cJSON_IsString(mode))
|
||||
{
|
||||
message_t msg = {};
|
||||
msg.type = MESSAGE_TYPE_SETTINGS;
|
||||
msg.data.settings.type = SETTINGS_TYPE_INT;
|
||||
strncpy(msg.data.settings.key, "light_mode", sizeof(msg.data.settings.key) - 1);
|
||||
if (strcmp(mode->valuestring, "simulation") == 0)
|
||||
{
|
||||
msg.data.settings.value.int_value = 0;
|
||||
}
|
||||
else if (strcmp(mode->valuestring, "day") == 0)
|
||||
{
|
||||
msg.data.settings.value.int_value = 1;
|
||||
}
|
||||
else if (strcmp(mode->valuestring, "night") == 0)
|
||||
{
|
||||
msg.data.settings.value.int_value = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.data.settings.value.int_value = -1; // Unbekannter Modus
|
||||
}
|
||||
message_manager_post(&msg, pdMS_TO_TICKS(100));
|
||||
}
|
||||
cJSON_Delete(json);
|
||||
}
|
||||
|
||||
set_cors_headers(req);
|
||||
return httpd_resp_sendstr(req, "{\"status\":\"ok\"}");
|
||||
}
|
||||
|
||||
@@ -13,8 +13,21 @@ cJSON *create_light_status_json(void)
|
||||
|
||||
bool light_active = persistence_manager_get_bool(&pm, "light_active", false);
|
||||
cJSON_AddBoolToObject(json, "on", light_active);
|
||||
|
||||
cJSON_AddBoolToObject(json, "thunder", false);
|
||||
cJSON_AddStringToObject(json, "mode", "day");
|
||||
|
||||
int mode = persistence_manager_get_int(&pm, "light_mode", 0);
|
||||
const char *mode_str = "simulation";
|
||||
if (mode == 1)
|
||||
{
|
||||
mode_str = "day";
|
||||
}
|
||||
else if (mode == 2)
|
||||
{
|
||||
mode_str = "night";
|
||||
}
|
||||
cJSON_AddStringToObject(json, "mode", mode_str);
|
||||
|
||||
cJSON_AddStringToObject(json, "schema", "schema_03.csv");
|
||||
cJSON *color = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(color, "r", 255);
|
||||
|
||||
Reference in New Issue
Block a user