I have a toucscreen tft connected to an ESP8266 the aim for which is to take a screeenshot (.bmp format) and upload to Google Drive. I have been following this tutorial.
Where I am stuck in how to proceed is the actual upload part. I have used the code in the tutorial up to line 264, and it is thereafter I don't know how to solve for. This reference project uses a function in a special library for the camera to parse it into packets and use client.write() to upload the packets. Relevant code here:
int i;
int packet_num = cameraPacketNum();
char packet[PIC_PKT_LEN] = {0};
for(i = 0; i < packet_num; i++)
{
long packet_len = cameraGetPacket(i, packet);
client.write((const uint8_t *)&packet[4], packet_len - 6);
total += packet_len - 6;
}
cameraGetPacket(i, packet);
client.print(end_boundary);
I looked at the code for the function but can't figure out what it's doing and how to replicate it. This is it here:
long cameraGetPacket(unsigned int i, char* buf) {
char cmd[] = { 0xaa, 0x0e | camera_address, 0x00, 0x00, 0x00, 0x00 };
Serial.setTimeout(100);
if(i < camera_packet_num) {
cmd[4] = i & 0xff;
cmd[5] = (i >> 8) & 0xff;
cameraClearRxBuf();
cameraSendCmd(cmd, 6);
int pkt_len;
if(i < (camera_packet_num - 1))
pkt_len = PIC_PKT_LEN ;
else
pkt_len = camera_last_packet_len;
uint16_t cnt = Serial.readBytes((char *)buf, pkt_len);
return cnt;
} else {
cmd[4] = 0xf0;
cmd[5] = 0xf0;
cameraSendCmd(cmd, 6);
}
return "";
}
The Google Drive API reference states: "Add the chunk's data to the request body. Create chunks in multiples of 256 KB (256 x 1024 bytes) in size, except for the final chunk that completes the upload. Keep the chunk size as large as possible so that the upload is efficient."
How can I take an image saved to the SD on the tft and cut it into the appropriate sized chunks and use client.write() to upload it to Google Drive? This example (which received no responses) seems to have divided the image file into 1,000's to upload but I don't know if that is correct or efficient.
int Index;
for (Index = 0; Index < imageFile.length(); Index = Index+1000) {
client.print(imageFile.substring(Index, Index+1000));
}
Another thing I am unsure about is whether I need to have the image file itself converted into Base64 or URLencoded. I have seen examples for the ESP32 CAM which do that, but I wonder if that is just the way that camera encodes images which then need to converted. The first example cited above doesn't have conversion code as it isn't an ESP32 CAM, but maybe it's happening in the background. The Google API doesn't make mention of it.
Any help would be greatly appreciated. Or any examples you can point me to that do this would be helpful too.