Skip to content

Commit

Permalink
fixed local web form
Browse files Browse the repository at this point in the history
  • Loading branch information
Supersilvia authored and Supersilvia committed Mar 18, 2024
1 parent 40dff69 commit 3400ef8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
13 changes: 7 additions & 6 deletions lib/groundlight/src/groundlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<detectors.size){
Expand Down
59 changes: 32 additions & 27 deletions src/deployable_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,30 +295,6 @@ const char index_html[] PROGMEM = R"rawliteral(
background-color: #45a049;
}
</style>
</head><body>
<form action="/config">
WiFi SSID: <input type="text" name="ssid" value="%ssid%">
WiFi Password: <input type="password" name="pw" value="%password%">
API Key: <input type="password" name="api_key" value="%api_key%">
Autoconfig: <input type="checkbox" id="autoconfig" name="autoconfig" value="true" onchange="toggleAutoConfig()">
<div id="autoConfigMessage" style="display:none;" >
<p>If autoconfig is checked, all of the settings below will be ignored and get updated automatically.</p>
</div>
Detector Id: <input type="text" name="det_id" value="%det_id%">
Query Delay (seconds): <input type="text" name="query_delay" value="%query_delay%">
Endpoint: <input type="text" name="endpoint" value="%endpoint%">
Target Confidence: <input type="text" name="tConf" value="%tConf%">
Enable Motion Detector: <input type="checkbox" id="motionDetectorCheckbox" name="motionDetector" value="true" onchange="toggleMotionSettings()">
<div id="motionSettings" style="display:none;">
Motion Alpha (float between 0 and 1): <input type="text" name="mot_a" value="%mot_a%">
Motion Beta (float between 0 and 1): <input type="text" name="mot_b" value="%mot_b%">
</div>
Enable Stacklight: <input type="checkbox" id="stacklightCheckbox" name="stacklightbox" value="true" onchange="toggleStacklightSettings()">
<div id="stacklightSettings" style="display:none;">
Stacklight UUID: <input type="text" name="sl_uuid" value="%sl_uuid%">
</div>
<input type="submit" value="Submit">
</form>
<script>
function toggleAutoConfig() {
var isChecked = document.getElementById('autoconfig').checked;
Expand All @@ -333,6 +309,35 @@ const char index_html[] PROGMEM = R"rawliteral(
document.getElementById('stacklightSettings').style.display = isChecked ? 'block' : 'none';
}
</script>
</head><body>
<form action="/config">
WiFi SSID: <input type="text" name="ssid" value="%ssid%">
WiFi Password: <input type="password" name="pw" value="%password%">
API Key: <input type="password" name="api_key" value="%api_key%">
Autoconfig: <input type="checkbox" id="autoconfig" name="autoconfig" value="true" onchange="toggleAutoConfig()">
<div id="autoConfigMessage" style="display:none;" >
<p>If autoconfig is checked, all of the settings below will be ignored and get updated automatically.</p>
</div>
Detector Id: <input type="text" name="det_id" value="%det_id%">
Query Delay (seconds): <input type="text" name="query_delay" value="%query_delay%">
Endpoint: <input type="text" name="endpoint" value="%endpoint%">
Target Confidence: <input type="text" name="tConf" value="%tConf%">)rawliteral"
#ifdef ENABLE_STACKLIGHT
R"rawliteral(
Enable Motion Detector: <input type="checkbox" id="motionDetectorCheckbox" name="motionDetector" value="true" onchange="toggleMotionSettings()">
<div id="motionSettings" style="display:none;">
Motion Alpha (float between 0 and 1): <input type="text" name="mot_a" value="%mot_a%"><br>
Motion Beta (float between 0 and 1): <input type="text" name="mot_b" value="%mot_b%">
</div>
Enable Stacklight: <input type="checkbox" id="stacklightCheckbox" name="stacklightbox" value="true" onchange="toggleStacklightSettings()">
<div id="stacklightSettings" style="display:none;">
Stacklight UUID: <input type="text" name="sl_uuid" value="%sl_uuid%">
</div>
)rawliteral"
#else
#endif
R"rawliteral( <input type="submit" value="Submit">
</form>
</body></html>
)rawliteral";

Expand Down Expand Up @@ -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);
Expand All @@ -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()) {
Expand Down

0 comments on commit 3400ef8

Please sign in to comment.