added application log file in storage partition

This commit is contained in:
Bogdan Pilyugin 2023-05-08 10:29:57 +02:00
parent 832bd3e623
commit 918ac98b35
2 changed files with 20 additions and 1 deletions

View File

@ -40,5 +40,6 @@ esp_err_t spi_device_polling_transmit_synchronized(spi_device_handle_t handle, s
bool GetUserAppNeedReset(void);
void SetUserAppNeedReset(bool res);
void LogFile(char *fname, char *mess);
#endif /* COMPONENTS_WEBGUIAPPCOMPONENT_INCLUDE_WEBGUIAPP_H_ */

View File

@ -65,7 +65,6 @@ StaticSemaphore_t xSemaphoreSPIBuf;
#define NETWORK_START_TIMEOUT (5)
static int NetworkStartTimeout = 0;
static bool isUserAppNeedReset = false;
static void InitSysIO(void);
@ -511,3 +510,22 @@ void SetUserAppNeedReset(bool res)
isUserAppNeedReset = res;
}
void LogFile(char *fname, char *mess)
{
char filename[32];
strcpy(filename, "/data/");
strcat(filename, fname);
FILE *f = fopen(filename, "a");
if (f == NULL)
{
ESP_LOGE(TAG, "Failed to open file %s for writing", filename);
return;
}
fwrite(esp_log_system_timestamp(), 1, 12, f);
fwrite(" ", 1, 1, f);
fwrite(mess, 1, strlen(mess), f);
fwrite("\r\n", 1, 2, f);
fclose(f);
ESP_LOGI(TAG, "File written to %s", filename);
}