Skip to content

Commit

Permalink
Merge pull request #36 from groundlight/esp-form-uiupdate
Browse files Browse the repository at this point in the history
Added auto-configuration feature for the local setup web page
  • Loading branch information
siyangye authored Mar 18, 2024
2 parents d520038 + 257c216 commit c6f18a1
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 142 deletions.
46 changes: 37 additions & 9 deletions lib/groundlight/src/groundlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,20 +367,26 @@ String get_query_id(const String &jsonResults) {

StaticJsonDocument<DET_DOC_SIZE> groundlight_json_doc;

// Parses the detectors from the Groundlight API.
detector_list get_detector_list(const char *endpoint, const char *apiToken) {
deserializeJson(groundlight_json_doc, get_detectors(endpoint, apiToken));
JsonArray detectors = groundlight_json_doc["results"];
detector *_detector_list = new detector[detectors.size()];
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);
strlcpy(_detector_list[i].metadata, metadataStr.c_str(), sizeof(_detector_list[i].metadata));
} else {
_detector_list[i].metadata[0] = '\0';
}
}
detector_list res = { _detector_list, detectors.size() };
return res;
Expand All @@ -401,16 +407,38 @@ String detector_to_string(detector d) {
res += d.group_name;
res += "\n\tConfidence threshold: ";
res += d.confidence_threshold;
res += "\n\tMetadata: ";
res += d.metadata;
return res;
}

detector get_detector_by_id(const char *endpoint, const char *detectorId, const char *apiToken) {
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].id) == String(detectorId)) {
return detectors.detectors[i];
det = detectors.detectors[i];
break;
}
}
if (0<detectors.size){
delete[] detectors.detectors;
}
return det;
}

detector get_detector_by_name(const char *endpoint, const char *detectorName, const char *apiToken) {
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)) {
det = detectors.detectors[i];
}
}
return detector { "NONE", "NONE", "NONE", "NONE", "NONE", "NONE", 0.0 };
if (0<detectors.size){
delete[] detectors.detectors;
}

return det;
}
#endif
4 changes: 3 additions & 1 deletion lib/groundlight/src/groundlight.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ struct detector
char query[200];
char group_name[40];
float confidence_threshold;
};
char metadata[1024];
};

struct detector_list
{
Expand All @@ -46,6 +47,7 @@ struct detector_list
detector_list get_detector_list(const char *endpoint, const char *apiToken);
String detector_to_string(detector d);
detector get_detector_by_id(const char *endpoint, const char *detectorId, const char *apiToken);
detector get_detector_by_name(const char *endpoint, const char *detectorName, const char *apiToken);
float get_query_confidence(const String &jsonResults);
String get_query_id(const String &jsonResults);
#endif
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ build_flags =
'-D CAMERA_MODEL_M5STACK_PSRAM'
'-D NAME="GROUNDLIGHT_DEMO_UNIT"'
'-D ENABLE_AP'
# '-D ENABLE_STACKLIGHT'
lib_deps =
${env.lib_deps}
https://github.com/me-no-dev/ESPAsyncWebServer.git#master
Expand Down
Loading

0 comments on commit c6f18a1

Please sign in to comment.