|
|
@@ -83,7 +83,6 @@ extern std::string getHTMLversion(void);
|
|
|
extern std::string getHTMLcommit(void);
|
|
|
|
|
|
std::vector<std::string> splitString(const std::string &str);
|
|
|
-void migrateConfiguration(void);
|
|
|
bool setCpuFrequency(void);
|
|
|
|
|
|
static const char *TAG = "MAIN";
|
|
|
@@ -167,9 +166,10 @@ bool Init_NVS_SDCard()
|
|
|
// formatted in case when mounting fails.
|
|
|
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
|
|
.format_if_mount_failed = false,
|
|
|
- .max_files = 12, // previously -> 2022-09-21: 5, 2023-01-02: 7
|
|
|
+ .max_files = 8,
|
|
|
.allocation_unit_size = 0, // 0 = auto
|
|
|
- .disk_status_check_enable = 0,
|
|
|
+ .disk_status_check_enable = false,
|
|
|
+ .use_one_fat = false,
|
|
|
};
|
|
|
|
|
|
sdmmc_card_t *card;
|
|
|
@@ -214,8 +214,6 @@ extern "C" void app_main(void)
|
|
|
ESP_ERROR_CHECK(heap_trace_init_standalone(trace_record, NUM_RECORDS));
|
|
|
#endif
|
|
|
|
|
|
- TickType_t xDelay;
|
|
|
-
|
|
|
#ifdef DISABLE_BROWNOUT_DETECTOR
|
|
|
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // disable brownout detector
|
|
|
#endif
|
|
|
@@ -234,6 +232,7 @@ extern "C" void app_main(void)
|
|
|
if (!Init_NVS_SDCard())
|
|
|
{
|
|
|
ESP_LOGE(TAG, "Device init aborted!");
|
|
|
+ vTaskDelay(pdMS_TO_TICKS(2000));
|
|
|
return; // No way to continue without working SD card!
|
|
|
}
|
|
|
|
|
|
@@ -269,7 +268,10 @@ extern "C" void app_main(void)
|
|
|
// delete error
|
|
|
StatusLED(SDCARD_CHECK, 3, true);
|
|
|
}
|
|
|
+
|
|
|
setSystemStatusFlag(SYSTEM_STATUS_SDCARD_CHECK_BAD); // reduced web interface going to be loaded
|
|
|
+ vTaskDelay(pdMS_TO_TICKS(2000));
|
|
|
+ return; // No way to continue without working SD card!
|
|
|
}
|
|
|
|
|
|
// SD card: Create further mandatory directories (if not already existing)
|
|
|
@@ -280,113 +282,72 @@ extern "C" void app_main(void)
|
|
|
MakeDir("/sdcard/demo"); // mandatory for demo mode
|
|
|
MakeDir("/sdcard/config/certs"); // mandatory for mqtt certificates
|
|
|
|
|
|
- // Check for updates
|
|
|
- // ********************************************
|
|
|
- CheckOTAUpdate();
|
|
|
- CheckUpdate();
|
|
|
-
|
|
|
// Init external PSRAM
|
|
|
// ********************************************
|
|
|
esp_err_t PSRAMStatus = esp_psram_init();
|
|
|
- if (PSRAMStatus == ESP_FAIL)
|
|
|
- { // ESP_FAIL -> Failed to init PSRAM
|
|
|
+ if (PSRAMStatus != ESP_OK)
|
|
|
+ {
|
|
|
+ // ESP_FAIL -> Failed to init PSRAM
|
|
|
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "PSRAM init failed (" + std::to_string(PSRAMStatus) + ")! PSRAM not found or defective");
|
|
|
setSystemStatusFlag(SYSTEM_STATUS_PSRAM_BAD);
|
|
|
StatusLED(PSRAM_INIT, 1, true);
|
|
|
+ vTaskDelay(pdMS_TO_TICKS(2000));
|
|
|
+ return; // No way to continue without psram
|
|
|
}
|
|
|
else
|
|
|
- { // ESP_OK -> PSRAM init OK --> continue to check PSRAM size
|
|
|
+ {
|
|
|
+ // ESP_OK -> PSRAM init OK --> continue to check PSRAM size
|
|
|
size_t psram_size = esp_psram_get_size(); // size_t psram_size = esp_psram_get_size(); // comming in IDF 5.0
|
|
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "PSRAM size: " + std::to_string(psram_size) + " byte (" + std::to_string(psram_size / 1024 / 1024) + "MB / " + std::to_string(psram_size / 1024 / 1024 * 8) + "MBit)");
|
|
|
|
|
|
// Check PSRAM size
|
|
|
// ********************************************
|
|
|
if (psram_size < (4 * 1024 * 1024))
|
|
|
- { // PSRAM is below 4 MBytes (32Mbit)
|
|
|
+ {
|
|
|
+ // PSRAM is below 4 MBytes (32Mbit)
|
|
|
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "PSRAM size >= 4MB (32Mbit) is mandatory to run this application");
|
|
|
setSystemStatusFlag(SYSTEM_STATUS_PSRAM_BAD);
|
|
|
StatusLED(PSRAM_INIT, 2, true);
|
|
|
+ vTaskDelay(pdMS_TO_TICKS(2000));
|
|
|
+ return; // No way to continue without psram
|
|
|
}
|
|
|
else
|
|
|
- { // PSRAM size OK --> continue to check heap size
|
|
|
+ {
|
|
|
+ // PSRAM size OK --> continue to check heap size
|
|
|
size_t _hsize = getESPHeapSize();
|
|
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Total heap: " + std::to_string(_hsize) + " byte");
|
|
|
|
|
|
// Check heap memory
|
|
|
// ********************************************
|
|
|
if (_hsize < 4000000)
|
|
|
- { // Check available Heap memory for a bit less than 4 MB (a test on a good device showed 4187558 bytes to be available)
|
|
|
+ {
|
|
|
+ // Check available Heap memory for a bit less than 4 MB (a test on a good device showed 4187558 bytes to be available)
|
|
|
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Total heap >= 4000000 byte is mandatory to run this application");
|
|
|
setSystemStatusFlag(SYSTEM_STATUS_HEAP_TOO_SMALL);
|
|
|
StatusLED(PSRAM_INIT, 3, true);
|
|
|
+ vTaskDelay(pdMS_TO_TICKS(2000));
|
|
|
+ return; // No way to continue without psram
|
|
|
}
|
|
|
else
|
|
|
- { // HEAP size OK --> continue to reserve shared memory block and check camera init
|
|
|
+ {
|
|
|
+ // HEAP size OK --> continue to reserve shared memory block and check camera init
|
|
|
/* Allocate static PSRAM memory regions */
|
|
|
if (!reserve_psram_shared_region())
|
|
|
{
|
|
|
setSystemStatusFlag(SYSTEM_STATUS_HEAP_TOO_SMALL);
|
|
|
StatusLED(PSRAM_INIT, 3, true);
|
|
|
- }
|
|
|
- else
|
|
|
- { // PSRAM OK
|
|
|
- // Init camera
|
|
|
- // ********************************************
|
|
|
- esp_err_t camStatus = ESP_OK;
|
|
|
- Camera.LightOnOff(true);
|
|
|
-
|
|
|
- for (int i = 0; i < 3; i++)
|
|
|
- {
|
|
|
- camStatus = Camera.InitCam();
|
|
|
- if (camStatus == ESP_OK)
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
- // De-init in case it was already initialized
|
|
|
- esp_camera_deinit();
|
|
|
- vTaskDelay(pdMS_TO_TICKS(200));
|
|
|
- }
|
|
|
-
|
|
|
- if (camStatus != ESP_OK)
|
|
|
- {
|
|
|
- // Camera init failed, retry to init
|
|
|
- char camStatusHex[33];
|
|
|
- sprintf(camStatusHex, "0x%02x", camStatus);
|
|
|
- LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Camera init failed (" + std::string(camStatusHex) + ")! Check camera module and/or proper electrical connection");
|
|
|
- setSystemStatusFlag(SYSTEM_STATUS_CAM_BAD);
|
|
|
- StatusLED(CAM_INIT, 1, true);
|
|
|
- }
|
|
|
- // Camera framebuffer check
|
|
|
- // ********************************************
|
|
|
- else if (!Camera.testCamera())
|
|
|
- {
|
|
|
- LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Camera framebuffer check failed");
|
|
|
- // Easiest would be to simply restart here and try again,
|
|
|
- // how ever there seem to be systems where it fails at startup but still work correctly later.
|
|
|
- // Therefore we treat it still as successed! */
|
|
|
- setSystemStatusFlag(SYSTEM_STATUS_CAM_FB_BAD);
|
|
|
- StatusLED(CAM_INIT, 2, false);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // Print camera infos
|
|
|
- // ********************************************
|
|
|
- char caminfo[50];
|
|
|
- sensor_t *sensor = esp_camera_sensor_get();
|
|
|
- sprintf(caminfo, "PID: 0x%02x, VER: 0x%02x, MIDL: 0x%02x, MIDH: 0x%02x", sensor->id.PID, sensor->id.VER, sensor->id.MIDH, sensor->id.MIDL);
|
|
|
- LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Camera info: " + std::string(caminfo));
|
|
|
- }
|
|
|
-
|
|
|
- Camera.LightOnOff(false); // make sure flashlight is off before start of flow
|
|
|
+ vTaskDelay(pdMS_TO_TICKS(2000));
|
|
|
+ return; // No way to continue without psram
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Migrate parameter in config.ini to new naming (firmware 15.0 and newer)
|
|
|
+ // Check for updates
|
|
|
// ********************************************
|
|
|
- migrateConfiguration();
|
|
|
-
|
|
|
+ CheckOTAUpdate();
|
|
|
+ CheckUpdate();
|
|
|
+
|
|
|
// Init time (as early as possible, but SD card needs to be initialized)
|
|
|
// ********************************************
|
|
|
setupTime(); // NTP time service: Status of time synchronization will be checked after every round (server_tflite.cpp)
|
|
|
@@ -412,20 +373,23 @@ extern "C" void app_main(void)
|
|
|
|
|
|
// Check version information
|
|
|
// ********************************************
|
|
|
- std::string versionFormated = getFwVersion() + ", Date/Time: " + std::string(BUILD_TIME) +
|
|
|
- ", Web UI: " + getHTMLversion();
|
|
|
+ std::string versionFormated = getFwVersion() + ", Date/Time: " + std::string(BUILD_TIME) + ", Web UI: " + getHTMLversion();
|
|
|
|
|
|
if (std::string(GIT_TAG) != "")
|
|
|
- { // We are on a tag, add it as prefix
|
|
|
+ {
|
|
|
+ // We are on a tag, add it as prefix
|
|
|
versionFormated = "Tag: '" + std::string(GIT_TAG) + "', " + versionFormated;
|
|
|
}
|
|
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, versionFormated);
|
|
|
|
|
|
if (getHTMLcommit().substr(0, 7) == "?")
|
|
|
+ {
|
|
|
LogFile.WriteToFile(ESP_LOG_WARN, TAG, std::string("Failed to read file html/version.txt to parse Web UI version"));
|
|
|
+ }
|
|
|
|
|
|
if (getHTMLcommit().substr(0, 7) != std::string(GIT_REV).substr(0, 7))
|
|
|
- { // Compare the first 7 characters of both hashes
|
|
|
+ {
|
|
|
+ // Compare the first 7 characters of both hashes
|
|
|
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Web UI version (" + getHTMLcommit() + ") does not match firmware version (" + std::string(GIT_REV) + ")");
|
|
|
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Recommendation: Repeat installation using AI-on-the-edge-device__update__*.zip");
|
|
|
}
|
|
|
@@ -433,8 +397,10 @@ extern "C" void app_main(void)
|
|
|
// Check reboot reason
|
|
|
// ********************************************
|
|
|
CheckIsPlannedReboot();
|
|
|
+
|
|
|
if (!getIsPlannedReboot() && (esp_reset_reason() == ESP_RST_PANIC))
|
|
|
- { // If system reboot was not triggered by user and reboot was caused by execption
|
|
|
+ {
|
|
|
+ // If system reboot was not triggered by user and reboot was caused by execption
|
|
|
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Reset reason: " + getResetReason());
|
|
|
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Device was rebooted due to a software exception! Log level is set to DEBUG until the next reboot. "
|
|
|
"Flow init is delayed by 5 minutes to check the logs or do an OTA update");
|
|
|
@@ -465,33 +431,27 @@ extern "C" void app_main(void)
|
|
|
{
|
|
|
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "WIFI init failed. Device init aborted!");
|
|
|
StatusLED(WLAN_INIT, 3, true);
|
|
|
+ vTaskDelay(pdMS_TO_TICKS(2000));
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
init_basic_auth();
|
|
|
}
|
|
|
else if (iWLANStatus == -1)
|
|
|
- { // wlan.ini not available, potentially empty or content not readable
|
|
|
+ {
|
|
|
+ // wlan.ini not available, potentially empty or content not readable
|
|
|
StatusLED(WLAN_INIT, 1, true);
|
|
|
+ vTaskDelay(pdMS_TO_TICKS(2000));
|
|
|
return; // No way to continue without reading the wlan.ini
|
|
|
}
|
|
|
else if (iWLANStatus == -2)
|
|
|
- { // SSID or password not configured
|
|
|
+ {
|
|
|
+ // SSID or password not configured
|
|
|
StatusLED(WLAN_INIT, 2, true);
|
|
|
+ vTaskDelay(pdMS_TO_TICKS(2000));
|
|
|
return; // No way to continue with empty SSID or password!
|
|
|
}
|
|
|
|
|
|
- xDelay = 2000 / portTICK_PERIOD_MS;
|
|
|
- ESP_LOGD(TAG, "main: sleep for: %ldms", (long)xDelay * CONFIG_FREERTOS_HZ / portTICK_PERIOD_MS);
|
|
|
- vTaskDelay(xDelay);
|
|
|
-
|
|
|
- // manual reset the time
|
|
|
- // ********************************************
|
|
|
- if (!time_manual_reset_sync())
|
|
|
- {
|
|
|
- LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Manual Time Sync failed during startup");
|
|
|
- }
|
|
|
-
|
|
|
// Set log level for wifi component to WARN level (default: INFO; only relevant for serial console)
|
|
|
// ********************************************
|
|
|
esp_log_level_set("wifi", ESP_LOG_WARN);
|
|
|
@@ -515,26 +475,74 @@ extern "C" void app_main(void)
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
+ // Init camera
|
|
|
+ // ********************************************
|
|
|
+ esp_err_t camStatus = ESP_OK;
|
|
|
+ Camera.LightOnOff(true);
|
|
|
+
|
|
|
+ for (int i = 0; i < 3; i++)
|
|
|
+ {
|
|
|
+ camStatus = Camera.InitCam();
|
|
|
+ if (camStatus == ESP_OK)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // De-init in case it was already initialized
|
|
|
+ esp_camera_deinit();
|
|
|
+ vTaskDelay(pdMS_TO_TICKS(200));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (camStatus != ESP_OK)
|
|
|
+ {
|
|
|
+ // Camera init failed, retry to init
|
|
|
+ char camStatusHex[33];
|
|
|
+ sprintf(camStatusHex, "0x%02x", camStatus);
|
|
|
+ LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Camera init failed (" + std::string(camStatusHex) + ")! Check camera module and/or proper electrical connection");
|
|
|
+ setSystemStatusFlag(SYSTEM_STATUS_CAM_BAD);
|
|
|
+ StatusLED(CAM_INIT, 1, true);
|
|
|
+ vTaskDelay(pdMS_TO_TICKS(2000));
|
|
|
+ return; // No way to continue without working Camera!
|
|
|
+ }
|
|
|
+ // Camera framebuffer check
|
|
|
+ // ********************************************
|
|
|
+ else if (!Camera.testCamera())
|
|
|
+ {
|
|
|
+ LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Camera framebuffer check failed");
|
|
|
+ // Easiest would be to simply restart here and try again,
|
|
|
+ // how ever there seem to be systems where it fails at startup but still work correctly later.
|
|
|
+ // Therefore we treat it still as successed! */
|
|
|
+ setSystemStatusFlag(SYSTEM_STATUS_CAM_FB_BAD);
|
|
|
+ StatusLED(CAM_INIT, 2, false);
|
|
|
+ // vTaskDelay(pdMS_TO_TICKS(2000));
|
|
|
+ // return; // No way to continue without working Camera!
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Print camera infos
|
|
|
+ // ********************************************
|
|
|
+ char caminfo[50];
|
|
|
+ sensor_t *sensor = esp_camera_sensor_get();
|
|
|
+ sprintf(caminfo, "PID: 0x%02x, VER: 0x%02x, MIDL: 0x%02x, MIDH: 0x%02x", sensor->id.PID, sensor->id.VER, sensor->id.MIDH, sensor->id.MIDL);
|
|
|
+ LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Camera info: " + std::string(caminfo));
|
|
|
+ }
|
|
|
+
|
|
|
+ Camera.LightOnOff(false); // make sure flashlight is off before start of flow
|
|
|
+
|
|
|
// Print Device info
|
|
|
// ********************************************
|
|
|
esp_chip_info_t chipInfo;
|
|
|
esp_chip_info(&chipInfo);
|
|
|
-
|
|
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Device info: CPU cores: " + std::to_string(chipInfo.cores) + ", Chip revision: " + std::to_string(chipInfo.revision));
|
|
|
|
|
|
// Print SD-Card info
|
|
|
// ********************************************
|
|
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "SD card info: Name: " + getSDCardName() + ", Capacity: " + getSDCardCapacity() + "MB, Free: " + getSDCardFreePartitionSpace() + "MB");
|
|
|
|
|
|
- xDelay = 2000 / portTICK_PERIOD_MS;
|
|
|
- ESP_LOGD(TAG, "main: sleep for: %ldms", (long)xDelay * CONFIG_FREERTOS_HZ / portTICK_PERIOD_MS);
|
|
|
- vTaskDelay(xDelay);
|
|
|
-
|
|
|
// Start webserver + register handler
|
|
|
// ********************************************
|
|
|
ESP_LOGD(TAG, "starting servers");
|
|
|
-
|
|
|
server = start_webserver();
|
|
|
+
|
|
|
register_server_camera_uri(server);
|
|
|
register_server_main_flow_task_uri(server);
|
|
|
register_server_file_uri(server, "/sdcard");
|
|
|
@@ -548,441 +556,34 @@ extern "C" void app_main(void)
|
|
|
ESP_LOGD(TAG, "Before reg server main");
|
|
|
register_server_main_uri(server, "/sdcard");
|
|
|
|
|
|
- // Only for testing purpose
|
|
|
- // setSystemStatusFlag(SYSTEM_STATUS_CAM_FB_BAD);
|
|
|
- // setSystemStatusFlag(SYSTEM_STATUS_PSRAM_BAD);
|
|
|
-
|
|
|
+ // manual reset the time
|
|
|
+ // ********************************************
|
|
|
+ if (!time_manual_reset_sync())
|
|
|
+ {
|
|
|
+ LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Manual Time Sync failed during startup");
|
|
|
+ }
|
|
|
+
|
|
|
// Check main init + start TFlite task
|
|
|
// ********************************************
|
|
|
if (getSystemStatus() == 0)
|
|
|
- { // No error flag is set
|
|
|
+ {
|
|
|
+ // No error flag is set
|
|
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Initialization completed successfully");
|
|
|
InitializeFlowTask();
|
|
|
}
|
|
|
- else if (isSetSystemStatusFlag(SYSTEM_STATUS_CAM_FB_BAD) || // Non critical errors occured, we try to continue...
|
|
|
- isSetSystemStatusFlag(SYSTEM_STATUS_NTP_BAD))
|
|
|
+ else if (isSetSystemStatusFlag(SYSTEM_STATUS_CAM_FB_BAD) || isSetSystemStatusFlag(SYSTEM_STATUS_NTP_BAD))
|
|
|
{
|
|
|
+ // Non critical errors occured, we try to continue...
|
|
|
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Initialization completed with non-critical errors!");
|
|
|
InitializeFlowTask();
|
|
|
}
|
|
|
else
|
|
|
- { // Any other error is critical and makes running the flow impossible. Init is going to abort.
|
|
|
+ {
|
|
|
+ // Any other error is critical and makes running the flow impossible. Init is going to abort.
|
|
|
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Initialization failed. Flow task start aborted. Loading reduced web interface...");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void migrateConfiguration(void)
|
|
|
-{
|
|
|
- std::vector<string> splitted;
|
|
|
- bool migrated = false;
|
|
|
-
|
|
|
- bool CamZoom_found = false;
|
|
|
- int CamZoom_lines = 0;
|
|
|
- bool CamZoom_value = false;
|
|
|
- int CamZoomSize_lines = 0;
|
|
|
- int CamZoomSize_value = 0;
|
|
|
- int CamZoomOffsetX_lines = 0;
|
|
|
- int CamZoomOffsetX_value = 0;
|
|
|
- int CamZoomOffsetY_lines = 0;
|
|
|
- int CamZoomOffsetY_value = 0;
|
|
|
-
|
|
|
- if (!FileExists(CONFIG_FILE))
|
|
|
- {
|
|
|
- LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Config file seems to be missing!");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- std::string section = "";
|
|
|
- std::ifstream ifs(CONFIG_FILE);
|
|
|
- std::string content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
|
|
|
-
|
|
|
- /* Split config file it array of lines */
|
|
|
- std::vector<std::string> configLines = splitString(content);
|
|
|
-
|
|
|
- /* Process each line */
|
|
|
- for (int i = 0; i < configLines.size(); i++)
|
|
|
- {
|
|
|
- // ESP_LOGI(TAG, "Line %d: %s", i, configLines[i].c_str());
|
|
|
-
|
|
|
- if (configLines[i].find("[") != std::string::npos)
|
|
|
- {
|
|
|
- // Start of new section
|
|
|
- section = configLines[i];
|
|
|
- replaceString(section, ";", "", false); // Remove possible semicolon (just for the string comparison)
|
|
|
- // ESP_LOGI(TAG, "New section: %s", section.c_str());
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- splitted = ZerlegeZeile(configLines[i]);
|
|
|
- }
|
|
|
-
|
|
|
- /* Migrate parameters as needed
|
|
|
- * For the boolean parameters, we make them enabled all the time now:
|
|
|
- * 1. If they where disabled, set them to their default value
|
|
|
- * 2. Enable them
|
|
|
- * Notes:
|
|
|
- * The migration has some simplifications:
|
|
|
- * - Case Sensitiveness must be like in the initial config.ini
|
|
|
- * - No Whitespace after a semicollon
|
|
|
- * - Only one whitespace before/after the equal sign
|
|
|
- */
|
|
|
- if (section == "[MakeImage]")
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], "[MakeImage]", "[TakeImage]"); // Rename the section itself
|
|
|
- }
|
|
|
-
|
|
|
- if (section == "[MakeImage]" || section == "[TakeImage]")
|
|
|
- {
|
|
|
- if ((isInString(configLines[i], "Brightness")) && (!isInString(configLines[i], "CamBrightness")))
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], "Brightness", "CamBrightness");
|
|
|
- }
|
|
|
- else if ((isInString(configLines[i], "Contrast")) && (!isInString(configLines[i], "CamContrast")))
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], "Contrast", "CamContrast");
|
|
|
- }
|
|
|
- else if ((isInString(configLines[i], "Saturation")) && (!isInString(configLines[i], "CamSaturation")))
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], "Saturation", "CamSaturation");
|
|
|
- }
|
|
|
- else if ((isInString(configLines[i], "Sharpness")) && (!isInString(configLines[i], "CamSharpness")) && (!isInString(configLines[i], "CamAutoSharpness")))
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], "Sharpness", "CamSharpness");
|
|
|
- }
|
|
|
- else if ((isInString(configLines[i], "Aec2")) && (!isInString(configLines[i], "CamAec")) && (!isInString(configLines[i], "CamAec2")))
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], "Aec2", "CamAec2");
|
|
|
- }
|
|
|
- else if ((isInString(configLines[i], "Zoom")) && (!isInString(configLines[i], "CamZoom")) && (!isInString(configLines[i], "ZoomMode")) && (!isInString(configLines[i], "ZoomOffsetX")) && (!isInString(configLines[i], "ZoomOffsetY")))
|
|
|
- {
|
|
|
- CamZoom_lines = i;
|
|
|
- if (splitted.size() < 2)
|
|
|
- {
|
|
|
- CamZoom_value = false;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // ESP_LOGI(TAG, "splitted[1]: %s", splitted[1].c_str());
|
|
|
- CamZoom_value = alphanumericToBoolean(splitted[1]);
|
|
|
- }
|
|
|
- CamZoom_found = true;
|
|
|
- }
|
|
|
- else if ((isInString(configLines[i], "ZoomMode")) && (!isInString(configLines[i], "CamZoom")))
|
|
|
- {
|
|
|
- CamZoomSize_lines = i;
|
|
|
- if (splitted.size() < 2)
|
|
|
- {
|
|
|
- CamZoomSize_value = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (isStringNumeric(splitted[1]))
|
|
|
- {
|
|
|
- CamZoomSize_value = std::stof(splitted[1]);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- CamZoomSize_value = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- CamZoom_found = true;
|
|
|
- }
|
|
|
- else if ((isInString(configLines[i], "ZoomOffsetX")) && (!isInString(configLines[i], "CamZoom")) && (!isInString(configLines[i], "ZoomOffsetY")))
|
|
|
- {
|
|
|
- CamZoomOffsetX_lines = i;
|
|
|
- if (splitted.size() < 2)
|
|
|
- {
|
|
|
- CamZoomOffsetX_value = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (isStringNumeric(splitted[1]))
|
|
|
- {
|
|
|
- CamZoomOffsetX_value = std::stof(splitted[1]);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- CamZoomOffsetX_value = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- CamZoom_found = true;
|
|
|
- }
|
|
|
- else if ((isInString(configLines[i], "ZoomOffsetY")) && (!isInString(configLines[i], "CamZoom")) && (!isInString(configLines[i], "ZoomOffsetX")))
|
|
|
- {
|
|
|
- CamZoomOffsetY_lines = i;
|
|
|
- if (splitted.size() < 2)
|
|
|
- {
|
|
|
- CamZoomOffsetY_value = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (isStringNumeric(splitted[1]))
|
|
|
- {
|
|
|
- CamZoomOffsetY_value = std::stof(splitted[1]);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- CamZoomOffsetY_value = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- CamZoom_found = true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], "LogImageLocation", "RawImagesLocation");
|
|
|
- migrated = migrated | replaceString(configLines[i], "LogfileRetentionInDays", "RawImagesRetention");
|
|
|
-
|
|
|
- migrated = migrated | replaceString(configLines[i], ";Demo = true", ";Demo = false"); // Set it to its default value
|
|
|
- migrated = migrated | replaceString(configLines[i], ";Demo", "Demo"); // Enable it
|
|
|
-
|
|
|
- migrated = migrated | replaceString(configLines[i], "ImageQuality", "CamQuality");
|
|
|
- migrated = migrated | replaceString(configLines[i], "AutoExposureLevel", "CamAeLevel");
|
|
|
- migrated = migrated | replaceString(configLines[i], "FixedExposure", "CamAec");
|
|
|
-
|
|
|
- migrated = migrated | replaceString(configLines[i], "ImageSize", ";UNUSED_PARAMETER"); // This parameter is no longer used
|
|
|
- migrated = migrated | replaceString(configLines[i], "Grayscale", ";UNUSED_PARAMETER"); // This parameter is no longer used
|
|
|
- migrated = migrated | replaceString(configLines[i], "Negative", ";UNUSED_PARAMETER"); // This parameter is no longer used
|
|
|
- }
|
|
|
- }
|
|
|
- else if (section == "[Alignment]")
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], "InitialMirror", ";UNUSED_PARAMETER"); // This parameter is no longer used
|
|
|
- migrated = migrated | replaceString(configLines[i], ";InitialMirror", ";UNUSED_PARAMETER"); // This parameter is no longer used
|
|
|
- migrated = migrated | replaceString(configLines[i], "FlipImageSize", ";UNUSED_PARAMETER"); // This parameter is no longer used
|
|
|
- migrated = migrated | replaceString(configLines[i], ";FlipImageSize", ";UNUSED_PARAMETER"); // This parameter is no longer used
|
|
|
- }
|
|
|
- else if (section == "[Digits]")
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], "LogImageLocation", "ROIImagesLocation");
|
|
|
- migrated = migrated | replaceString(configLines[i], "LogfileRetentionInDays", "ROIImagesRetention");
|
|
|
- }
|
|
|
- else if (section == "[Analog]")
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], "LogImageLocation", "ROIImagesLocation");
|
|
|
- migrated = migrated | replaceString(configLines[i], "LogfileRetentionInDays", "ROIImagesRetention");
|
|
|
- migrated = migrated | replaceString(configLines[i], "ExtendedResolution", ";UNUSED_PARAMETER"); // This parameter is no longer used
|
|
|
- }
|
|
|
- else if (section == "[PostProcessing]")
|
|
|
- {
|
|
|
- /* AllowNegativeRates has a <NUMBER> as prefix! */
|
|
|
- if (isInString(configLines[i], "AllowNegativeRates") && isInString(configLines[i], ";"))
|
|
|
- {
|
|
|
- // It is the parameter "AllowNegativeRates" and it is commented out
|
|
|
- migrated = migrated | replaceString(configLines[i], "true", "false"); // Set it to its default value
|
|
|
- migrated = migrated | replaceString(configLines[i], ";", ""); // Enable it
|
|
|
- }
|
|
|
- /* IgnoreLeadingNaN has a <NUMBER> as prefix! */
|
|
|
- else if (isInString(configLines[i], "IgnoreLeadingNaN") && isInString(configLines[i], ";"))
|
|
|
- {
|
|
|
- // It is the parameter "IgnoreLeadingNaN" and it is commented out
|
|
|
- migrated = migrated | replaceString(configLines[i], "true", "false"); // Set it to its default value
|
|
|
- migrated = migrated | replaceString(configLines[i], ";", ""); // Enable it
|
|
|
- }
|
|
|
- /* ExtendedResolution has a <NUMBER> as prefix! */
|
|
|
- else if (isInString(configLines[i], "ExtendedResolution") && isInString(configLines[i], ";"))
|
|
|
- {
|
|
|
- // It is the parameter "ExtendedResolution" and it is commented out
|
|
|
- migrated = migrated | replaceString(configLines[i], "true", "false"); // Set it to its default value
|
|
|
- migrated = migrated | replaceString(configLines[i], ";", ""); // Enable it
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], ";PreValueUse = true", ";PreValueUse = false"); // Set it to its default value
|
|
|
- migrated = migrated | replaceString(configLines[i], ";PreValueUse", "PreValueUse"); // Enable it
|
|
|
-
|
|
|
- migrated = migrated | replaceString(configLines[i], ";ErrorMessage = true", ";ErrorMessage = false"); // Set it to its default value
|
|
|
- migrated = migrated | replaceString(configLines[i], ";ErrorMessage", "ErrorMessage"); // Enable it
|
|
|
-
|
|
|
- migrated = migrated | replaceString(configLines[i], ";CheckDigitIncreaseConsistency = true", ";CheckDigitIncreaseConsistency = false"); // Set it to its default value
|
|
|
- migrated = migrated | replaceString(configLines[i], ";CheckDigitIncreaseConsistency", "CheckDigitIncreaseConsistency"); // Enable it
|
|
|
- }
|
|
|
- }
|
|
|
- else if (section == "[MQTT]")
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], "SetRetainFlag", "RetainMessages"); // First rename it, enable it with its default value
|
|
|
- migrated = migrated | replaceString(configLines[i], ";RetainMessages = true", ";RetainMessages = false"); // Set it to its default value
|
|
|
- migrated = migrated | replaceString(configLines[i], ";RetainMessages", "RetainMessages"); // Enable it
|
|
|
-
|
|
|
- migrated = migrated | replaceString(configLines[i], ";HomeassistantDiscovery = true", ";HomeassistantDiscovery = false"); // Set it to its default value
|
|
|
- migrated = migrated | replaceString(configLines[i], ";HomeassistantDiscovery", "HomeassistantDiscovery"); // Enable it
|
|
|
-
|
|
|
- // only if string starts with "Topic" (Was the naming in very old version)
|
|
|
- if (configLines[i].rfind("Topic", 0) != std::string::npos)
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], "Topic", "MainTopic");
|
|
|
- }
|
|
|
- }
|
|
|
- else if (section == "[InfluxDB]")
|
|
|
- {
|
|
|
- /* Fieldname has a <NUMBER> as prefix! */
|
|
|
- if (isInString(configLines[i], "Fieldname"))
|
|
|
- {
|
|
|
- // It is the parameter "Fieldname"
|
|
|
- migrated = migrated | replaceString(configLines[i], "Fieldname", "Field"); // Rename it to Field
|
|
|
- }
|
|
|
- }
|
|
|
- else if (section == "[InfluxDBv2]")
|
|
|
- {
|
|
|
- /* Fieldname has a <NUMBER> as prefix! */
|
|
|
- if (isInString(configLines[i], "Fieldname"))
|
|
|
- {
|
|
|
- // It is the parameter "Fieldname"
|
|
|
- migrated = migrated | replaceString(configLines[i], "Fieldname", "Field"); // Rename it to Field
|
|
|
- }
|
|
|
- /* Database got renamed to Bucket! */
|
|
|
- else if (isInString(configLines[i], "Database"))
|
|
|
- {
|
|
|
- // It is the parameter "Database"
|
|
|
- migrated = migrated | replaceString(configLines[i], "Database", "Bucket"); // Rename it to Bucket
|
|
|
- }
|
|
|
- }
|
|
|
- else if (section == "[GPIO]")
|
|
|
- {
|
|
|
- }
|
|
|
- else if (section == "[DataLogging]")
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], "DataLogRetentionInDays", "DataFilesRetention");
|
|
|
- /* DataLogActive is true by default! */
|
|
|
- migrated = migrated | replaceString(configLines[i], ";DataLogActive = false", ";DataLogActive = true"); // Set it to its default value
|
|
|
- migrated = migrated | replaceString(configLines[i], ";DataLogActive", "DataLogActive"); // Enable it
|
|
|
- }
|
|
|
- else if (section == "[AutoTimer]")
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], "Intervall", "Interval");
|
|
|
- migrated = migrated | replaceString(configLines[i], "Autostart", ";UNUSED_PARAMETER"); // This parameter is no longer used
|
|
|
- }
|
|
|
- else if (section == "[Debug]")
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], "Logfile ", "LogLevel "); // Whitespace needed so it does not match `LogfileRetentionInDays`
|
|
|
- /* LogLevel (resp. LogFile) was originally a boolean, but we switched it to an int
|
|
|
- * For both cases (true/false), we set it to level 2 (WARNING) */
|
|
|
- migrated = migrated | replaceString(configLines[i], "LogLevel = true", "LogLevel = 2");
|
|
|
- migrated = migrated | replaceString(configLines[i], "LogLevel = false", "LogLevel = 2");
|
|
|
- migrated = migrated | replaceString(configLines[i], "LogfileRetentionInDays", "LogfilesRetention");
|
|
|
- }
|
|
|
- else if (section == "[System]")
|
|
|
- {
|
|
|
- migrated = migrated | replaceString(configLines[i], "RSSIThreashold", "RSSIThreshold");
|
|
|
- migrated = migrated | replaceString(configLines[i], "AutoAdjustSummertime", ";UNUSED_PARAMETER"); // This parameter is no longer used
|
|
|
-
|
|
|
- migrated = migrated | replaceString(configLines[i], ";SetupMode = true", ";SetupMode = false"); // Set it to its default value
|
|
|
- migrated = migrated | replaceString(configLines[i], ";SetupMode", "SetupMode"); // Enable it
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (CamZoom_found == true)
|
|
|
- {
|
|
|
- if (CamZoomSize_value == 0)
|
|
|
- {
|
|
|
- // mode0
|
|
|
- // 1600 - 640 = 960 / 2 = max-Offset (+/-) 480
|
|
|
- // 1200 - 480 = 720 / 2 = max-Offset (+/-) 360
|
|
|
-
|
|
|
- if (CamZoomOffsetX_value > 960)
|
|
|
- {
|
|
|
- CamZoomOffsetX_value = 960;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- CamZoomOffsetX_value = (floor((CamZoomOffsetX_value - 480) / 8) * 8);
|
|
|
- }
|
|
|
-
|
|
|
- if (CamZoomOffsetY_value > 720)
|
|
|
- {
|
|
|
- CamZoomOffsetY_value = 720;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- CamZoomOffsetY_value = (floor((CamZoomOffsetY_value - 360) / 8) * 8);
|
|
|
- }
|
|
|
-
|
|
|
- CamZoomSize_value = 29;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // mode1
|
|
|
- // 800 - 640 = 160 / 2 = max-Offset (+/-) 80
|
|
|
- // 600 - 480 = 120 / 2 = max-Offset (+/-) 60
|
|
|
-
|
|
|
- if (CamZoomOffsetX_value > 160)
|
|
|
- {
|
|
|
- CamZoomOffsetX_value = 160;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- CamZoomOffsetX_value = (floor(((CamZoomOffsetX_value - 80) * 2) / 8) * 8);
|
|
|
- }
|
|
|
-
|
|
|
- if (CamZoomOffsetY_value > 120)
|
|
|
- {
|
|
|
- CamZoomOffsetY_value = 120;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- CamZoomOffsetY_value = (floor(((CamZoomOffsetY_value - 60) * 2) / 8) * 8);
|
|
|
- }
|
|
|
-
|
|
|
- CamZoomSize_value = 9;
|
|
|
- }
|
|
|
-
|
|
|
- if (CamZoom_lines > 0)
|
|
|
- {
|
|
|
- if (CamZoom_value)
|
|
|
- {
|
|
|
- configLines[CamZoom_lines] = ("CamZoom = true");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- configLines[CamZoom_lines] = ("CamZoom = false");
|
|
|
- }
|
|
|
- LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Migrated Configfile line 'Zoom' to 'CamZoom'");
|
|
|
- migrated = true;
|
|
|
- }
|
|
|
- if (CamZoomSize_lines > 0)
|
|
|
- {
|
|
|
- configLines[CamZoomSize_lines] = ("CamZoomSize = " + std::to_string(CamZoomSize_value));
|
|
|
- LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Migrated Configfile line 'ZoomMode' to 'CamZoomSize'");
|
|
|
- migrated = true;
|
|
|
- }
|
|
|
- if (CamZoomOffsetX_lines > 0)
|
|
|
- {
|
|
|
- configLines[CamZoomOffsetX_lines] = ("CamZoomOffsetX = " + std::to_string(CamZoomOffsetX_value));
|
|
|
- LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Migrated Configfile line 'ZoomOffsetX' to 'CamZoomOffsetX'");
|
|
|
- migrated = true;
|
|
|
- }
|
|
|
- if (CamZoomOffsetY_lines > 0)
|
|
|
- {
|
|
|
- configLines[CamZoomOffsetY_lines] = ("CamZoomOffsetY = " + std::to_string(CamZoomOffsetY_value));
|
|
|
- LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Migrated Configfile line 'ZoomOffsetY' to 'CamZoomOffsetY'");
|
|
|
- migrated = true;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (migrated)
|
|
|
- {
|
|
|
- // At least one replacement happened
|
|
|
- if (!RenameFile(CONFIG_FILE, CONFIG_FILE_BACKUP))
|
|
|
- {
|
|
|
- LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to create backup of Config file!");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- FILE *pfile = fopen(CONFIG_FILE, "w");
|
|
|
-
|
|
|
- for (int i = 0; i < configLines.size(); i++)
|
|
|
- {
|
|
|
- if (!isInString(configLines[i], ";UNUSED_PARAMETER"))
|
|
|
- {
|
|
|
- fwrite(configLines[i].c_str(), configLines[i].length(), 1, pfile);
|
|
|
- fwrite("\n", 1, 1, pfile);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- fclose(pfile);
|
|
|
- LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Config file migrated. Saved backup to " + string(CONFIG_FILE_BACKUP));
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
std::vector<std::string> splitString(const std::string &str)
|
|
|
{
|
|
|
std::vector<std::string> tokens;
|
|
|
@@ -998,33 +599,6 @@ std::vector<std::string> splitString(const std::string &str)
|
|
|
return tokens;
|
|
|
}
|
|
|
|
|
|
-/*bool replace_all(std::string& s, std::string const& toReplace, std::string const& replaceWith) {
|
|
|
- std::string buf;
|
|
|
- std::size_t pos = 0;
|
|
|
- std::size_t prevPos;
|
|
|
- bool found = false;
|
|
|
-
|
|
|
- // Reserves rough estimate of final size of string.
|
|
|
- buf.reserve(s.size());
|
|
|
-
|
|
|
- while (true) {
|
|
|
- prevPos = pos;
|
|
|
- pos = s.find(toReplace, pos);
|
|
|
- if (pos == std::string::npos) {
|
|
|
- break;
|
|
|
- }
|
|
|
- found = true;
|
|
|
- buf.append(s, prevPos, pos - prevPos);
|
|
|
- buf += replaceWith;
|
|
|
- pos += toReplace.size();
|
|
|
- }
|
|
|
-
|
|
|
- buf.append(s, prevPos, s.size() - prevPos);
|
|
|
- s.swap(buf);
|
|
|
-
|
|
|
- return found;
|
|
|
-}*/
|
|
|
-
|
|
|
bool setCpuFrequency(void)
|
|
|
{
|
|
|
ConfigFile configFile = ConfigFile(CONFIG_FILE);
|
|
|
@@ -1043,9 +617,7 @@ bool setCpuFrequency(void)
|
|
|
bool eof = false;
|
|
|
|
|
|
/* Load config from config file */
|
|
|
- while ((!configFile.GetNextParagraph(line, disabledLine, eof) ||
|
|
|
- (line.compare("[System]") != 0)) &&
|
|
|
- !eof)
|
|
|
+ while ((!configFile.GetNextParagraph(line, disabledLine, eof) || (line.compare("[System]") != 0)) && !eof)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
@@ -1054,8 +626,7 @@ bool setCpuFrequency(void)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- while (configFile.getNextLine(&line, disabledLine, eof) &&
|
|
|
- !configFile.isNewParagraph(line))
|
|
|
+ while (configFile.getNextLine(&line, disabledLine, eof) && !configFile.isNewParagraph(line))
|
|
|
{
|
|
|
splitted = ZerlegeZeile(line);
|
|
|
|