Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

i use it here like this

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

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

 L@?L@?L@?L@?L@?L@?L@?L@?L@?L@?L@?L@?L@?L@?L@?L@?L@?L@?L@?L@?L@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?�/@?��@?

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
        //fgets(info,sizeof(info),f);
        fwrite(&info , 1, sizeof(info), f);
        fclose(f);
    }else{
        f = fopen(file_foo, "w");   //creates and write mode
        fwrite(&info, 1,sizeof(info),f);
        fclose(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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading