adafruit / adafruit/Adafruit-VC0706-Serial-Camera-Library
Crashing on file write using ESP-01 w/SPIFFS
- Dominant language
- C++
- Stars
- 139
- Forks
- 108
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to convert the use of the example to write to a file in SPIFFS on an esp8266 instead of an SD card. I would really like to see if I could get the serial camera working on an ESP-01 due to it's small size and the fact the camera only needs the two data pins.
I'm using the ESPSoftwareSerial which appears to work fine as the code recognizes my camera. I changed the file open command to the SPIFFS variation, adding '/' in front of the filename and replacing the FILE_WRITE with "w". But when the .write(buffer, len) is called, it crashes. I think this is to do with the fact the buffer is unbounded. (is not a fixed length array)
This got me to examining how the adafruit code worked and they seem to be passing a pointer to an internal unbounded array out of the code. Isn't that a no-no in C++? i.e. shouldn't you accept a pointer 'into' the function then populate it locally so that the 'buffer' is sure to be memory resident when it returns to the main program?
Any suggestions or help to get this working would be appreciated. As written, I can't seem to get it to to work.
My relevant code:
```
// Create an image with the name Image.jpg
String filename = "/Image.jpg";
Serial.println("Writing file to SPIFFS: " + filename);
if (!SPIFFS.exists(filename))
SPIFFS.remove(filename);
// Open the file for writing
File imgFile = SPIFFS.open(filename, "w");
// Get the size of the image (frame) taken
uint16_t jpglen = cam.frameLength();
byte wCount = 0; // For counting # of writes
// read 64 bytes at a time;
uint16_t minByte = 64;
Serial.print("Storing ");
Serial.print(jpglen, DEC);
Serial.print(" byte image.");
int32_t time = millis();
// Read all the data up to # bytes!
while (jpglen > 0) {
uint8_t *buffer;
uint8_t bytesToRead = min(minByte, jpglen);
// reads data from a jpeg camera on SoftwareSerial 64 bytes at a time
buffer = cam.readPicture(bytesToRead);
Serial.print("-> Read "); Serial.print(bytesToRead, DEC); Serial.println(" bytes");
// **** ------>>>> throwing exception at the following line <<<<------ ****
imgFile.write(buffer, bytesToRead);
Serial.print("Wrote -> "); Serial.print(bytesToRead, DEC); Serial.println(" bytes");
jpglen -= bytesToRead;
}
imgFile.close();
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the provided SPIFFS file-writing code, especially the call from cam.readPicture(bytesToRead) into imgFile.write(buffer, bytesToRead). Check the ESP-01/SPIFFS write path and the returned buffer's lifetime to isolate why the write crashes. Done means the captured JPEG writes completely to SPIFFS without crashing and can be opened afterward.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- arduino, cpp
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100