Write binary file to SPIFFS folder
Posted: Wed Mar 10, 2021 8:08 am
Hei guys, how are u doing ,
i am trying to write a binary file into my flash memey using SPIFFS, so i can perform update
here its the idea, i am using sim800 to get the information from my FTP server, in the other hand i am listening to the serial port to read data comming from the sim800, and stock it into string, so every 1024bytes i write its to a bin file to the memory,
but in the end i find that the size is not the same as the size of the real folder,
PS : when i do the same things with a txt file , everything is good
any advice, thank you
i post just the block concerne the process
i am trying to write a binary file into my flash memey using SPIFFS, so i can perform update
here its the idea, i am using sim800 to get the information from my FTP server, in the other hand i am listening to the serial port to read data comming from the sim800, and stock it into string, so every 1024bytes i write its to a bin file to the memory,
but in the end i find that the size is not the same as the size of the real folder,
PS : when i do the same things with a txt file , everything is good
any advice, thank you
i post just the block concerne the process
- File file = SPIFFS.open("/firm.bin","w");
- if(!file) Serial.println("Error opening file for writing");
- else Serial.println("file ready for write");
- for (int i=0;i<ii;i++)
- {
- Serial2.println("AT+FTPGET=2,1024");
- tempFtp = Serial2.readString();
- uint8_t ind1 = tempFtp.indexOf(',');
- uint8_t ind2 = tempFtp.indexOf(',', ind1 + 1);
- // Serial.print(tempFtp.substring(ind2+strlen(fileSize.c_str())+3,ind2+strlen(fileSize.c_str())+3+1024));
- //Serial.print(tempFtp.substring(ind2+7,ind2+1031));
- file.print(tempFtp.substring(ind2+7,ind2+1031));
- Serial.println(i);
- //Serial.println(tempFtp);
- }
- if(m!=0) // test if there is more data to read ( <1024 bytes )
- {
- char atComFileSize[size]={0};
- sprintf(atComFileSize,"AT+FTPGET=2,%d",m);
- Serial2.println(atComFileSize);
- tempFtp = Serial2.readString();
- uint8_t ind1 = tempFtp.indexOf(',');
- uint8_t ind2 = tempFtp.indexOf(',', ind1 + 1);
- file.print(tempFtp.substring(ind2+3+l,ind2+m+3+l));
- }
- file.close();
- Serial.println("Done");