Page 1 of 1

How to convert OV7670' output into MIME (base64 coding)

Posted: Fri Oct 05, 2018 3:13 pm
by pszemek
Hi,

Im trying to send email with photo captured from OV7670 as attachement.

Already I have achieved sending emails with attachement (also images in base64 coding) but I don't know how to convert OV7670 output to something what I could transform to base64.

I'm using Bitluni's driver to OV7670 from https://github.com/bitluni/ESP32CameraI2S, how can I achieve this?

My code:

Code: Select all

// ....
client.println("From: <" + String(FROM) + '>');
client.println("To: <" + to + '>');  
client.print("Subject: ");
client.println(_subject);
client.println("Content-Type: image/png; name=\"picture.png\"\r\nContent-Disposition: attachment; filename=\"picture.png\"\r\nContent-Transfer-Encoding: base64\r\n\r\n");

for(int i = 0; i < BMP::headerSize; i++)
    client.write(bmpHeader[i]);
for(int i = 0; i < camera->xres * camera->yres * 2; i++)
    client.write(camera->frame[i]);
// ...

Re: How to convert OV7670' output into MIME (base64 coding)

Posted: Fri Oct 19, 2018 8:06 pm
by chegewara
Hi,
sorry for late reply but i just started similar project to yours. This is how i am changing data from camera to base64 string:

Code: Select all

	size_t size = image.size;
	const uint8_t* image = image.data;

	uint8_t *buffer = calloc((size + 2 - ((size + 2) % 3)) / 3 * 4 + 1, sizeof(char));   // <--- equation from internet
	size_t buff_size = 0;
	int err = mbedtls_base64_encode(buffer, (size + 2 - ((size + 2) % 3)) / 3 * 4 + 1, &buff_size, image, size);
	if (err != 0) {
		ESP_LOGE(TAG, "error base64 encoding, error %d, buff size: %d", err, buff_size);  
		return;	
	}