ESP32-CAM | How to send frame buffer through Serial

So I created a PCB that was based on ESP32-CAM actually but something seems to be wrong that when I use the camera, somehow the WiFi transmission or antenna doesn't work. So I decided to use serial communication to transmit the frame buffer across UART to another ESP module and host a server there.

However, I'm really bad at going about changing between data types especially when pointers are involved. From what I've known so fb is a uint_8t which is similar to byte. So how do I transmit this using Serial.write() properly and receive the same thing in another ESP board and switch it back to uint_8t so that I can use it to host a webserver.
In this program that I'm doing the serial monitor just went crazy probably bcoz it can't turn the characters into ASCII, so I really have no idea whats going on or what im doing.

Transmiter code:

#include "WiFi.h"
#include "esp_camera.h"
#define CAMERA_MODEL_AI_THINKER
#include "camera_pins.h"

bool initCamera(){
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;
  config.frame_size = FRAMESIZE_SVGA;  //resolution
  config.jpeg_quality = 12;
  config.fb_count = 1;
  config.fb_location = CAMERA_FB_IN_DRAM;

  esp_err_t result = esp_camera_init(&config);

  return true;
}

void setup() {
  Serial.begin(115200);
  if(!initCamera()){
    Serial.printf("Failed to Initialize OV2640 Camera");
    return;
  }

}

void loop() {
  camera_fb_t * fb = NULL;
  fb = esp_camera_fb_get();

  Serial.write((unsigned char*)fb->buf,fb->len);
  Serial.write('\n');
  
  esp_camera_fb_return(fb);
  delay(10);
}

Receiver code:

#include "ESP8266WiFi.h"
#include "ESPAsyncWebServer.h"
 
const char* ssid = "myssid";
const char* password = "mypass";
 
AsyncWebServer server(80);
uint8_t fb;
size_t fblen;
 
void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }
 
  Serial.println(WiFi.localIP());
 
  server.on("/picture", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send_P(200, "image/jpeg", (const char *)fb, sizeof(fb));
  });
 
  server.begin();
}
 
void loop(){
  int count = 0;
  while(Serial.available()>0){
    byte message = Serial.read();
    if(message == 0x0A)
    break;
    fb[count] = uint8_t*(message);
    count++;
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.