New Text Document (2)
New Text Document (2)
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
#include "Base64.h"
#include "esp_camera.h"
//CAMERA_MODEL_AI_THINKER GPIO.
#define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27
#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 21
#define Y4_GPIO_NUM 19
#define Y3_GPIO_NUM 18
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22
// Initialize WiFiClientSecure.
WiFiClientSecure client;
// camera init
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf("Camera init failed with error 0x%x", err);
Serial.println();
Serial.println("Restarting the ESP32 CAM.");
delay(1000);
ESP.restart();
}
sensor_t* s = esp_camera_sensor_get();
s->set_framesize(s, FRAMESIZE_QVGA); //--> UXGA|SXGA|XGA|SVGA|VGA|CIF|QVGA|
HQVGA|QQVGA
}
client.setInsecure();
if (client.connect(host, 443)) {
Serial.println("Connection successful.");
Serial.println("-----------");
client.stop();
break;
} else {
Serial.println("Connected to " + String(host) + " failed.");
Serial.println("Wait a moment for reconnecting.");
Serial.println("-----------");
client.stop();
}
delay(10);
}
}
if (LED_Flash_ON == true) {
digitalWrite(FLASH_LED_PIN, HIGH);
delay(10);
}
camera_fb_t * fb = NULL;
fb = esp_camera_fb_get();
if(!fb) {
Serial.println("Camera capture failed");
Serial.println("Restarting the ESP32 CAM.");
delay(10);
ESP.restart();
return;
}
Serial.println();
int chunk = 0;
for (int i = 0; i < fbLen; i += chunkSize) {
int l = base64_encode(output, input, min(fbLen - i, chunkSize));
client.print(l, HEX);
client.print("\r\n");
client.print(output);
client.print("\r\n");
delay(10);
input += chunkSize;
Serial.print(".");
chunk++;
if (chunk % 50 == 0) {
Serial.println();
}
}
client.print("0\r\n");
client.print("\r\n");
esp_camera_fb_return(fb);
//..............................
Serial.println("-----------");
client.stop();
}
//________________________________________________________________________________
//________________________________________________________________________________
VOID SETUP()
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println();
delay(1000);
pinMode(FLASH_LED_PIN, OUTPUT);
//The process of connecting ESP32 CAM with WiFi Hotspot / WiFi Router.
Serial.println();
Serial.print("Connecting to : ");
Serial.println(ssid);
WiFi.begin(ssid, password);
// The process timeout of connecting ESP32 CAM with WiFi Hotspot / WiFi Router is
20 seconds.
// If within 20 seconds the ESP32 CAM has not been successfully connected to
WiFi, the ESP32 CAM will restart.
// I made this condition because on my ESP32-CAM, there are times when it seems
like it can't connect to WiFi, so it needs to be restarted to be able to connect to
WiFi.
int connecting_process_timed_out = 20; //--> 20 = 20 seconds.
connecting_process_timed_out = connecting_process_timed_out * 2;
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
digitalWrite(FLASH_LED_PIN, HIGH);
delay(250);
digitalWrite(FLASH_LED_PIN, LOW);
delay(250);
if(connecting_process_timed_out > 0) connecting_process_timed_out--;
if(connecting_process_timed_out == 0) {
Serial.println();
Serial.print("Failed to connect to ");
Serial.println(ssid);
Serial.println("Restarting the ESP32 CAM.");
delay(100);
ESP.restart();
}
}
digitalWrite(FLASH_LED_PIN, LOW);
Serial.println();
Serial.print("Successfully connected to ");
Serial.println(ssid);