esp32cam saving log txt file to sd card but only append odd character

Im trying to make my own log function inside an esp32cam, reason is i cant use the serial monitor thanks an odd hardware error while using the esp32cam-mb,

I manage to initialized the sd card and make the file, but for some odd reason I only get the same odd character

in my function i ask for a const char value but im passing a plain string Log("got ip: ") as well other error string from esp32 const char *string_err = esp_err_to_name(wifi_err), i know i shouldnt be mixing string and const but honestly i dont know how to handle strings in c, i know i can declared it in c++ but here im lost, im adding my code below.

i use it here like this

const char *string_err = esp_err_to_name(wifi_err); 
Log("This my ip:");

but all i get on my log.txt file is this


what might be the error? this is my code

void Log(const char *info){
    sdmmc_card_t *card;
    FILE *f;
    const char mount_point[] = MOUNT_POINT;
    const char *file_foo = MOUNT_POINT"/Log.txt";

    // open cards
    card = Open_Card(); // here i initialized the sd card for further use

    // check if file exist, then append to file
    if (access(file_foo,F_OK) == 0){
        f = fopen(file_foo, "a");   //append mode
        fwrite(&info , 1, sizeof(info), f);
        f = fopen(file_foo, "w");   //creates and write mode
        fwrite(&info, 1,sizeof(info),f);
        // All done, unmount partition and disable SDMMC peripheral
    esp_vfs_fat_sdcard_unmount(mount_point, card);

im using esp32cam, platformio + vscode , espressif 5.3.0 (v6 wont support esp32cam)

>Solution :

this line

 fwrite(&info , 1, sizeof(info), f);

is just writing a pointer to the file, you need fprintf

 fprintf(f , "%s", info);

Leave a Reply