mafia2g2001 wrote: ↑Mon Aug 21, 2023 8:26 am
I really appreciate the help thank you. I expected since the code to append has some print string and it is only printed once to the terminal that is why I claimed to be sure.
What I think is happening is that after programming, the ESP32 is reset and will actually run without its output being captured. Then, a little bit later when the terminal program starts up again, the ESP32 is reset again and the program will run a second time.
I could not follow your suggestion on adding the code with vTaskDelay(pdMS_TO_TICKS(2000)) on top of app_main, If you can explain more please.
See below:
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
void app_main(void){
vTaskDelay(pdMS_TO_TICKS(2000));
// Mounting partition -- shows ESP_LOGI -->Sensor: Partition html mounted with /page directory....
mount_fatfs_custom_partition(HTML_PART_LABEL, HTML_PART_FOLDER);
// Opening file in append mode
FILE *file_obj_a = fopen("/page/index.txt", "a");
fputs("log1", file_obj_a);
fclose(file_obj_a);
printf("/////log appended/////\n"); \\-->This is printed only once but the file appended twice
// Opening file in read mode
FILE *file_obj_r = fopen("/page/index.txt", "r");
do{
char c = fgetc(file_obj_r);
if (feof(file_obj_r)){
break;
}
printf("%c", c);
} while (1);
fclose(file_obj_r);
printf("\n");
}
If my hunch is correct, the first time the program runs, it only runs for a short while. By delaying startup for two seconds, it will never get to the append routine before being reset again, meaning you should now only have one 'log appended'.