Trying to solve ESP32-webcam timeouts

Trying to solve ESP32-webcam timeouts on Settings save by adding delays in between file write chunks and diabling NVS writes when stream is active. (#13882)
This commit is contained in:
Theo Arends 2021-12-12 18:04:46 +01:00
parent 21cda658d6
commit fa7b0302a7
4 changed files with 53 additions and 22 deletions

View File

@ -694,7 +694,7 @@ void SettingsLoad(void) {
if (source) {
settings_location = 1;
if (Settings->cfg_holder == (uint16_t)CFG_HOLDER) {
AddLog(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG "Loaded from %s, " D_COUNT " %lu"), (source)?"File":"Nvm", Settings->save_flag);
AddLog(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG "Loaded from %s, " D_COUNT " %lu"), (2 == source)?"File":"NVS", Settings->save_flag);
}
}
#endif // ESP32

View File

@ -137,34 +137,43 @@ String GetDeviceHardware(void) {
#include <esp_phy_init.h>
void NvmLoad(const char *sNvsName, const char *sName, void *pSettings, unsigned nSettingsLen) {
nvs_handle handle;
noInterrupts();
nvs_open(sNvsName, NVS_READONLY, &handle);
bool NvmLoad(const char *sNvsName, const char *sName, void *pSettings, unsigned nSettingsLen) {
nvs_handle_t handle;
// noInterrupts();
esp_err_t result = nvs_open(sNvsName, NVS_READONLY, &handle);
if (result != ESP_OK) {
AddLog(LOG_LEVEL_DEBUG, PSTR("NVS: Error %d"), result);
return false;
}
size_t size = nSettingsLen;
nvs_get_blob(handle, sName, pSettings, &size);
nvs_close(handle);
interrupts();
// interrupts();
return true;
}
void NvmSave(const char *sNvsName, const char *sName, const void *pSettings, unsigned nSettingsLen) {
nvs_handle handle;
noInterrupts();
nvs_open(sNvsName, NVS_READWRITE, &handle);
nvs_handle_t handle;
// noInterrupts();
esp_err_t result = nvs_open(sNvsName, NVS_READWRITE, &handle);
if (result != ESP_OK) {
AddLog(LOG_LEVEL_DEBUG, PSTR("NVS: Error %d"), result);
return;
}
nvs_set_blob(handle, sName, pSettings, nSettingsLen);
nvs_commit(handle);
nvs_close(handle);
interrupts();
// interrupts();
}
int32_t NvmErase(const char *sNvsName) {
nvs_handle handle;
noInterrupts();
nvs_handle_t handle;
// noInterrupts();
int32_t result = nvs_open(sNvsName, NVS_READWRITE, &handle);
if (ESP_OK == result) { result = nvs_erase_all(handle); }
if (ESP_OK == result) { result = nvs_commit(handle); }
nvs_close(handle);
interrupts();
// interrupts();
return result;
}
@ -208,21 +217,23 @@ void SettingsErase(uint8_t type) {
}
uint32_t SettingsRead(void *data, size_t size) {
uint32_t source = 1;
#ifdef USE_UFILESYS
if (!TfsLoadFile(TASM_FILE_SETTINGS, (uint8_t*)data, size)) {
#endif
source = 0;
NvmLoad("main", "Settings", data, size);
#ifdef USE_UFILESYS
if (TfsLoadFile(TASM_FILE_SETTINGS, (uint8_t*)data, size)) {
return 2;
}
#endif
return source;
if (NvmLoad("main", "Settings", data, size)) {
return 1;
};
return 0;
}
void SettingsWrite(const void *pSettings, unsigned nSettingsLen) {
#ifdef USE_UFILESYS
TfsSaveFile(TASM_FILE_SETTINGS, (const uint8_t*)pSettings, nSettingsLen);
#endif
#ifdef USE_WEBCAM
if (!WcStreamActive())
#endif
NvmSave("main", "Settings", pSettings, nSettingsLen);
}

View File

@ -294,7 +294,23 @@ bool TfsSaveFile(const char *fname, const uint8_t *buf, uint32_t len) {
return false;
}
file.write(buf, len);
// This will timeout on ESP32-webcam
// file.write(buf, len);
uint32_t count = len / 512;
uint32_t chunk = len / count;
for (uint32_t i = 0; i < count; i++) {
file.write(buf + (i * chunk), chunk);
// do actually wait a little to allow ESP32 tasks to tick
// fixes task timeout in ESP32Solo1 style unicore code and webcam.
delay(10);
OsWatchLoop();
}
uint32_t left = len % count;
if (left) {
file.write(buf + (count * chunk), left);
}
file.close();
return true;
}

View File

@ -876,6 +876,10 @@ void WcStreamControl() {
WcSetup(Settings->webcam_config.resolution);
}
bool WcStreamActive(void) {
return (Wc.stream_active);
}
/*********************************************************************************************/