change schema via REST
Some checks failed
ESP-IDF Build / build (esp32c6, release-v5.4) (push) Failing after 4m46s
ESP-IDF Build / build (esp32c6, release-v5.5) (push) Failing after 4m56s
ESP-IDF Build / build (esp32s3, release-v5.4) (push) Failing after 4m45s
ESP-IDF Build / build (esp32s3, release-v5.5) (push) Failing after 4m44s

Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
2026-01-18 16:41:41 +01:00
parent 3d7de05614
commit dc40acfd06
3 changed files with 22 additions and 2 deletions

View File

@@ -358,7 +358,25 @@ esp_err_t api_light_schema_handler(httpd_req_t *req)
ESP_LOGI(TAG, "Received schema setting: %s", buf); ESP_LOGI(TAG, "Received schema setting: %s", buf);
// TODO: Parse JSON and set active schema cJSON *json = cJSON_Parse(buf);
if (json)
{
cJSON *schema_file = cJSON_GetObjectItem(json, "schema");
if (cJSON_IsString(schema_file))
{
int schema_id = 0;
sscanf(schema_file->valuestring, "schema_%d.csv", &schema_id);
message_t msg = {};
msg.type = MESSAGE_TYPE_SETTINGS;
msg.data.settings.type = SETTINGS_TYPE_INT;
strncpy(msg.data.settings.key, "light_variant", sizeof(msg.data.settings.key) - 1);
msg.data.settings.value.int_value = schema_id;
message_manager_post(&msg, pdMS_TO_TICKS(100));
}
cJSON_Delete(json);
}
set_cors_headers(req); set_cors_headers(req);
return httpd_resp_sendstr(req, "{\"status\":\"ok\"}"); return httpd_resp_sendstr(req, "{\"status\":\"ok\"}");
} }

View File

@@ -10,6 +10,7 @@ idf_component_register(SRCS
driver driver
nvs_flash nvs_flash
esp_insights esp_insights
analytics
led-manager led-manager
api-server api-server
) )

View File

@@ -1,8 +1,8 @@
#include "wifi_manager.h" #include "wifi_manager.h"
#include "dns_hijack.h" #include "dns_hijack.h"
#include "analytics.h"
#include "api_server.h" #include "api_server.h"
#include <esp_event.h> #include <esp_event.h>
#include <esp_insights.h> #include <esp_insights.h>
#include <esp_log.h> #include <esp_log.h>
@@ -59,6 +59,7 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t e
{ {
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data; ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
ESP_LOGI(TAG, "IP_EVENT_STA_GOT_IP: IP-Adresse erhalten: " IPSTR, IP2STR(&event->ip_info.ip)); ESP_LOGI(TAG, "IP_EVENT_STA_GOT_IP: IP-Adresse erhalten: " IPSTR, IP2STR(&event->ip_info.ip));
analytics_init();
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
} }
else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_LOST_IP) else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_LOST_IP)