From b4b85fd786bc4bc0f48ca2fd6ec05ccdc83fb18d Mon Sep 17 00:00:00 2001 From: Supersilvia Date: Mon, 4 Mar 2024 09:43:27 -0800 Subject: [PATCH] cleaned up form --- lib/groundlight/src/groundlight.cpp | 10 +++- src/deployable_example.cpp | 74 +++++++++++++++++++---------- 2 files changed, 58 insertions(+), 26 deletions(-) diff --git a/lib/groundlight/src/groundlight.cpp b/lib/groundlight/src/groundlight.cpp index cb50c93..41135ad 100644 --- a/lib/groundlight/src/groundlight.cpp +++ b/lib/groundlight/src/groundlight.cpp @@ -437,11 +437,17 @@ detector get_detector_by_id(const char *endpoint, const char *detector_id, const detector get_detector_by_name(const char *endpoint, const char *detectorName, const char *apiToken) { //given input: detectorName detector_list detectors = get_detector_list(endpoint, apiToken); + detector det = { "NONE", "NONE", "NONE", "NONE", "NONE", "NONE", 0.0, "None" }; for (int i = 0; i < detectors.size; i++) { if (String(detectors.detectors[i].name) == String(detectorName)) { - return detectors.detectors[i]; + det = detectors.detectors[i]; } } - return detector { "NONE", "NONE", "NONE", "NONE", "NONE", "NONE", 0.0, "None" }; + // return detector { "NONE", "NONE", "NONE", "NONE", "NONE", "NONE", 0.0, "None" }; + if (0 WiFi Password: API Key: - Autoconfig: + Autoconfig: + Detector Id: Query Delay (seconds): Endpoint: Target Confidence: - Motion Alpha (float between 0 and 1): - Motion Beta (float between 0 and 1): - Stacklight UUID: - Slack URL: - Email: - Email Endpoint: - Email Key: - Email Host: - Twilio SID: - Twilio Token: - Twilio Number: - Twilio Recipient: + Enable Motion Detector: + + Enable Stacklight: + + )rawliteral"; @@ -397,20 +412,15 @@ void performAutoConfig(AsyncWebServerRequest *request){ Serial.println("Error: Detector not found. Try connect to the previous configured detector."); return; } - //deserialize metadata: String metadataStr = esp_det.metadata; - DynamicJsonDocument metadataDoc(1024); - DeserializationError error = deserializeJson(metadataDoc, metadataStr); - if (error) { Serial.print(F("deserializeJson() failed: ")); Serial.println(error.c_str()); return; } - // from metadata: get query_delay if (metadataDoc.containsKey("Query Delay (seconds)") && !metadataDoc["Query Delay (seconds)"].isNull() && metadataDoc.containsKey("Target Confidence") && !metadataDoc["Target Confidence"].isNull()) { preferences.putString("det_id", esp_det.id); @@ -426,15 +436,31 @@ void performAutoConfig(AsyncWebServerRequest *request){ Serial.print(F("Target Confidence: ")); Serial.println(targetConfidence); + if (metadataDoc.containsKey("Motion Alpha (float between 0 and 1)") && !metadataDoc["Motion Alpha (float between 0 and 1)"].isNull()){ + String mot_a = metadataDoc["Motion Alpha (float between 0 and 1)"]; + preferences.putString("mot_a",mot_a); + } else { + preferences.remove("mot_a"); + } + if (metadataDoc.containsKey("Motion Beta (float between 0 and 1):") && !metadataDoc["Motion Beta (float between 0 and 1):"].isNull()){ + String mot_b = metadataDoc["Motion Beta (float between 0 and 1):"]; + preferences.putString("mot_b",mot_b); + } else { + preferences.remove("mot_b"); + } + if (metadataDoc.containsKey("Stacklight UUID:") && !metadataDoc["Stacklight UUID:"].isNull()){ + String sl_uuid = metadataDoc["Stacklight UUID:"]; + preferences.putString("sl_uuid",sl_uuid); + Serial.println("we got stacklight UUID"); + } else { + preferences.putString("sl_uuid", " "); + Serial.println("stacklight UUID is empty"); + } } else { Serial.println(F("Query Delay or Target confidence not found in metadata or no value stored in query delay.")); return; } - //optional: - //motion alpha - //motion beta - //SL UUID } #endif