mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 02:36:35 +00:00
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:
parent
21cda658d6
commit
fa7b0302a7
@ -694,7 +694,7 @@ void SettingsLoad(void) {
|
|||||||
if (source) {
|
if (source) {
|
||||||
settings_location = 1;
|
settings_location = 1;
|
||||||
if (Settings->cfg_holder == (uint16_t)CFG_HOLDER) {
|
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
|
#endif // ESP32
|
||||||
|
@ -137,34 +137,43 @@ String GetDeviceHardware(void) {
|
|||||||
|
|
||||||
#include <esp_phy_init.h>
|
#include <esp_phy_init.h>
|
||||||
|
|
||||||
void NvmLoad(const char *sNvsName, const char *sName, void *pSettings, unsigned nSettingsLen) {
|
bool NvmLoad(const char *sNvsName, const char *sName, void *pSettings, unsigned nSettingsLen) {
|
||||||
nvs_handle handle;
|
nvs_handle_t handle;
|
||||||
noInterrupts();
|
// noInterrupts();
|
||||||
nvs_open(sNvsName, NVS_READONLY, &handle);
|
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;
|
size_t size = nSettingsLen;
|
||||||
nvs_get_blob(handle, sName, pSettings, &size);
|
nvs_get_blob(handle, sName, pSettings, &size);
|
||||||
nvs_close(handle);
|
nvs_close(handle);
|
||||||
interrupts();
|
// interrupts();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NvmSave(const char *sNvsName, const char *sName, const void *pSettings, unsigned nSettingsLen) {
|
void NvmSave(const char *sNvsName, const char *sName, const void *pSettings, unsigned nSettingsLen) {
|
||||||
nvs_handle handle;
|
nvs_handle_t handle;
|
||||||
noInterrupts();
|
// noInterrupts();
|
||||||
nvs_open(sNvsName, NVS_READWRITE, &handle);
|
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_set_blob(handle, sName, pSettings, nSettingsLen);
|
||||||
nvs_commit(handle);
|
nvs_commit(handle);
|
||||||
nvs_close(handle);
|
nvs_close(handle);
|
||||||
interrupts();
|
// interrupts();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t NvmErase(const char *sNvsName) {
|
int32_t NvmErase(const char *sNvsName) {
|
||||||
nvs_handle handle;
|
nvs_handle_t handle;
|
||||||
noInterrupts();
|
// noInterrupts();
|
||||||
int32_t result = nvs_open(sNvsName, NVS_READWRITE, &handle);
|
int32_t result = nvs_open(sNvsName, NVS_READWRITE, &handle);
|
||||||
if (ESP_OK == result) { result = nvs_erase_all(handle); }
|
if (ESP_OK == result) { result = nvs_erase_all(handle); }
|
||||||
if (ESP_OK == result) { result = nvs_commit(handle); }
|
if (ESP_OK == result) { result = nvs_commit(handle); }
|
||||||
nvs_close(handle);
|
nvs_close(handle);
|
||||||
interrupts();
|
// interrupts();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,23 +217,25 @@ void SettingsErase(uint8_t type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SettingsRead(void *data, size_t size) {
|
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
|
#ifdef USE_UFILESYS
|
||||||
|
if (TfsLoadFile(TASM_FILE_SETTINGS, (uint8_t*)data, size)) {
|
||||||
|
return 2;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return source;
|
if (NvmLoad("main", "Settings", data, size)) {
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsWrite(const void *pSettings, unsigned nSettingsLen) {
|
void SettingsWrite(const void *pSettings, unsigned nSettingsLen) {
|
||||||
#ifdef USE_UFILESYS
|
#ifdef USE_UFILESYS
|
||||||
TfsSaveFile(TASM_FILE_SETTINGS, (const uint8_t*)pSettings, nSettingsLen);
|
TfsSaveFile(TASM_FILE_SETTINGS, (const uint8_t*)pSettings, nSettingsLen);
|
||||||
#endif
|
#endif
|
||||||
NvmSave("main", "Settings", pSettings, nSettingsLen);
|
#ifdef USE_WEBCAM
|
||||||
|
if (!WcStreamActive())
|
||||||
|
#endif
|
||||||
|
NvmSave("main", "Settings", pSettings, nSettingsLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QPCRead(void *pSettings, unsigned nSettingsLen) {
|
void QPCRead(void *pSettings, unsigned nSettingsLen) {
|
||||||
|
@ -294,7 +294,23 @@ bool TfsSaveFile(const char *fname, const uint8_t *buf, uint32_t len) {
|
|||||||
return false;
|
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();
|
file.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -876,6 +876,10 @@ void WcStreamControl() {
|
|||||||
WcSetup(Settings->webcam_config.resolution);
|
WcSetup(Settings->webcam_config.resolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WcStreamActive(void) {
|
||||||
|
return (Wc.stream_active);
|
||||||
|
}
|
||||||
|
|
||||||
/*********************************************************************************************/
|
/*********************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user