It's me again,
Since I can't get everything from scratch anymore, I've been trying to learn things with code that actually works. I'm reading and trying to understand line by line. It's been like this, slow, but it's good.
Even better with the help of some of you.
This code below receives via serial a photo taken by an esp32-cam.
I don't remember where I got the original code from. What I do know is that he sent the photo over the internet via FTP.
In my case I just want to save the photo on the SD card of the esp32 wroom receiver, in which I will write this code.
This line is not compiling as it says that
myFile.println((unsigned char*)tempImageBuffer, ImgMetaData.imSize));
Because it has arguments accepted only by FTP_upload()
I couldn't test the reception of the photo coming from esp-cam because it gets to this point and doesn't compile.
Can anyone fix it ?
I know I could save to the esp-cam's own SD card, but I want to save to the esp32 wroom's SD card. So, I'm going to see how the serial communication works, the photo transfer and the saving.
#include "SerialTransfer.h"
#include <SPI.h>
#include <mySD.h>
#define CHIPSELECT 5
#define MOSI 23
#define MISO 19
#define CLOCK 18
File myFile;
SerialTransfer myTransfer;
struct img_meta_data{
uint16_t counter;
uint16_t imSize;
uint16_t numLoops;
uint16_t sizeLastLoop;
} ImgMetaData;
uint16_t packetCounter=1;
uint16_t bufferPointer=0;
char tempImageBuffer[32000];
// picture name
String picPrefix ="";
String pic_name;
void setup(){
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, 17, 16);
myTransfer.begin(Serial2);
pinMode(CHIPSELECT, OUTPUT);
// Inicializa SD card
if (!SD.begin(5, 23, 19, 18)) {
Serial.println("Falha na inicialização do SD card");
} else {
Serial.println("SD card OK");
delay(100);
}
}
void loop(){
if(myTransfer.available()) {
myTransfer.rxObj(ImgMetaData, sizeof(ImgMetaData));
if(ImgMetaData.counter==1){
copyToImageBuff(MAX_PACKET_SIZE-sizeof(ImgMetaData));
}else{
if(ImgMetaData.counter==packetCounter){
if(packetCounter<ImgMetaData.numLoops){
copyToImageBuff(MAX_PACKET_SIZE-sizeof(ImgMetaData));
}else if(ImgMetaData.counter==packetCounter){
copyToImageBuff(ImgMetaData.sizeLastLoop);
}
}
}
if(packetCounter>ImgMetaData.numLoops){
pic_name = picPrefix;
pic_name += ".jpg"; //getDateTime() + ".jpg";
sdcard();
packetCounter=1;
bufferPointer=0;
delay(2000);
//while(1){}
}
}
}
void copyToImageBuff(uint16_t dataLenght){
for(int y=0;y<dataLenght;y++){
tempImageBuffer[bufferPointer+y] = myTransfer.rxBuff[y+sizeof(ImgMetaData)];
}
bufferPointer+=dataLenght;
packetCounter++;
}
}
void sdcard(){
myFile = SD.open(pic_name.c_str(), FILE_WRITE);
if (myFile) {
const char *f_name = pic_name.c_str();
myFile.println((unsigned char*)tempImageBuffer, ImgMetaData.imSize));
delay(100);
myFile.close();
}
}