1

I am doing a wifi camera project using the OV7670 and ESP32 bundles: https://github.com/bitluni/ESP32CameraI2S.

How can I save the bitmap using SPIFFS in File?

Part of the code:

void Get_photo (AsyncWebServerRequest * request) {
   camera-> oneFrame ();
   File file = SPIFFS.open ("/ Images / test.bmp", FILE_WRITE); // How to save to this file?

   for (int i = 0; i <BMP :: headerSize; i ++)
   {
       bmpHeader [i];
   }

   for (int i = 0; i <camera-> xres * camera-> yres * 2; i ++)
   {
      camera-> frame [i];
   }


  Serial.println ("PHOTO_OK!");
}
bcperth
  • 2,191
  • 1
  • 10
  • 16
Michael S
  • 21
  • 3

1 Answers1

1

Not sure you still need the answer, but it may help someone. You are reading the values, but not writing it to file.

void Get_photo (AsyncWebServerRequest * request) {

  camera-> oneFrame ();
  File file = SPIFFS.open ("/ Images / test.bmp", FILE_WRITE); // Here the file is opened

  if (!file) {
    Serial.println("Error opening the file."); // Good practice to check if the file was correctly opened
    return; // If file not opened, do not proceed
  }

  for (int i = 0; i <BMP :: headerSize; i ++)
  {
    file.write(bmpHeader [i]); // Writes header information to the BMP file
  }

  for (int i = 0; i <camera-> xres * camera-> yres * 2; i ++)
  {
    file.write(camera-> frame [i]); // Writes pixel information to the BMP file
  }

  file.close(); // Closing the file saves its content

  Serial.println ("PHOTO_OK!");

}

Have in mind that every time you call Get_photo, it will overwrite test.bmp because two files cannot have the same name.

Hope that helps someone.

Victor Oliveira
  • 352
  • 2
  • 10