From 3400ef8a0c89ba9bf7f84e84feacc9cc22820093 Mon Sep 17 00:00:00 2001 From: Supersilvia Date: Mon, 18 Mar 2024 14:38:21 -0700 Subject: [PATCH] fixed local web form --- lib/groundlight/src/groundlight.cpp | 13 ++++--- src/deployable_example.cpp | 59 ++++++++++++++++------------- 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/lib/groundlight/src/groundlight.cpp b/lib/groundlight/src/groundlight.cpp index 3d3e3c7..a931c28 100644 --- a/lib/groundlight/src/groundlight.cpp +++ b/lib/groundlight/src/groundlight.cpp @@ -374,12 +374,12 @@ detector_list get_detector_list(const char *endpoint, const char *apiToken) { for (int i = 0; i < detectors.size(); i++) { _detector_list[i].confidence_threshold = detectors[i]["confidence_threshold"]; - strcpy(_detector_list[i].id, detectors[i]["id"]); - strcpy(_detector_list[i].type, detectors[i]["type"]); - strcpy(_detector_list[i].created_at, detectors[i]["created_at"]); - strcpy(_detector_list[i].name, detectors[i]["name"]); - strcpy(_detector_list[i].query, detectors[i]["query"]); - strcpy(_detector_list[i].group_name, detectors[i]["group_name"]); + strlcpy(_detector_list[i].id, detectors[i]["id"], sizeof(_detector_list[i].id)); + strlcpy(_detector_list[i].type, detectors[i]["type"], sizeof(_detector_list[i].type)); + strlcpy(_detector_list[i].created_at, detectors[i]["created_at"], sizeof((_detector_list[i].created_at))); + strlcpy(_detector_list[i].name, detectors[i]["name"], sizeof(_detector_list[i].name)); + strlcpy(_detector_list[i].query, detectors[i]["query"], sizeof(_detector_list[i].query)); + strlcpy(_detector_list[i].group_name, detectors[i]["group_name"], sizeof(_detector_list[i].group_name)); if (!detectors[i]["metadata"].isNull()) { String metadataStr; serializeJson(detectors[i]["metadata"], metadataStr); @@ -418,6 +418,7 @@ detector get_detector_by_id(const char *endpoint, const char *detectorId, const for (int i = 0; i < detectors.size; i++) { if (String(detectors.detectors[i].id) == String(detectorId)) { det = detectors.detectors[i]; + break; } } if (0 - -
- WiFi SSID: - WiFi Password: - API Key: - Autoconfig: - - Detector Id: - Query Delay (seconds): - Endpoint: - Target Confidence: - Enable Motion Detector: - - Enable Stacklight: - - -
+ +
+ WiFi SSID: + WiFi Password: + API Key: + Autoconfig: + + Detector Id: + Query Delay (seconds): + Endpoint: + Target Confidence: )rawliteral" + #ifdef ENABLE_STACKLIGHT + R"rawliteral( + Enable Motion Detector: + + Enable Stacklight: + + )rawliteral" + #else + #endif + R"rawliteral( +
)rawliteral"; @@ -396,7 +401,7 @@ void performAutoConfig(AsyncWebServerRequest *request){ detector esp_det = get_detector_by_name(endpoint, esp_detector_name.c_str(), apiToken); if (strcmp(esp_det.id, "NONE") == 0) { preferences.putString("det_id", "DETECTOR NOT FOUND"); - Serial.println("Error: Detector not found."); + debug_printf("Error: Detector not found."); return; } preferences.putString("det_id", esp_det.id); @@ -405,8 +410,8 @@ void performAutoConfig(AsyncWebServerRequest *request){ DynamicJsonDocument metadataDoc(1024); DeserializationError error = deserializeJson(metadataDoc, metadataStr); if (error) { - Serial.print(F("deserializeJson() failed: ")); - Serial.println(error.c_str()); + debug_printf(("deserializeJson() failed: ")); + debug_printf(error.c_str()); return; } if (metadataDoc.containsKey("Query Delay (seconds)") && !metadataDoc["Query Delay (seconds)"].isNull()) {