Skip to content

Commit

Permalink
fixed autoconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Supersilvia authored and Supersilvia committed Feb 22, 2024
1 parent 1b77c3d commit e155974
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/deployable_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include "integrations.h"
#include "stacklight.h"

// #include "../credentials/api_keys.h" //testing only

#ifdef PRELOADED_CREDENTIALS
#include "credentials.h"
#endif
Expand Down Expand Up @@ -388,16 +386,20 @@ bool shouldPerformAutoConfig(AsyncWebServerRequest *request) {
void performAutoConfig(AsyncWebServerRequest *request){
const char* endpoint = groundlight_endpoint;
const char* apiToken = groundlight_API_key;
detector esp_det = get_detector_by_name(endpoint, "ESP32-CAM-87E1AC", apiToken); // ESP32-CAM-87E1AC
//error handling detector name doesn't exist
// mac address to detectorName
String mac = WiFi.macAddress();
mac.replace(":", "");
mac = mac.substring(6);
String esp_detector_name = (StringSumHelper) "ESP32-CAM-" + mac;
debug_printf("esp cam detector name: %s\n",esp_detector_name.c_str());
detector esp_det = get_detector_by_name(endpoint, esp_detector_name.c_str(), apiToken);
if (strcmp(esp_det.id, "NONE") == 0) {
Serial.println("Error: Detector not found. Try connect to the previous configured detector.");
return;
}

//deserialize metadata:
String metadataStr = esp_det.metadata;
Serial.println(esp_det.metadata);

DynamicJsonDocument metadataDoc(1024);

Expand Down Expand Up @@ -710,8 +712,7 @@ void setup() {
// alloc memory for 565 frames
frame_565 = (uint8_t *) ps_malloc(FRAME_ARR_LEN);
frame_565_old = (uint8_t *) ps_malloc(FRAME_ARR_LEN);

debug_printf("detector_id : %s\n",groundlight_det_id);

#ifdef LED_BUILTIN
digitalWrite(LED_BUILTIN, LOW);
#endif
Expand Down Expand Up @@ -864,16 +865,6 @@ void loop () {
}
if (WiFi.isConnected()) {
debug_printf("WIFI connected to SSID %s\n", ssid);
// //TESTING ONLY:
// const char* endpoint = "api.groundlight.ai";
// const char* apiToken = API_TOKEN;
// String detectors = get_detectors(endpoint, apiToken);
// Serial.println("detectors string:");
// Serial.println(detectors);
// const char* detectorName = "cat";
// detector det = get_detector_by_name(endpoint,detectorName,apiToken);
// Serial.println("get detector id by name: ");
// Serial.print(det.id);//succeeded!


} else {
Expand Down

0 comments on commit e155974

Please sign in to comment.