kopia lustrzana https://github.com/alanesq/esp32cam-demo
Update ESP32cam-demo.ino
rodzic
597f4f5fc0
commit
7b4242e43e
|
@ -102,7 +102,7 @@
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
|
|
||||||
char* stitle = "ESP32Cam"; // title of this sketch
|
char* stitle = "ESP32Cam"; // title of this sketch
|
||||||
char* sversion = "23Feb25"; // Sketch version
|
char* sversion = "08Mar25"; // Sketch version
|
||||||
|
|
||||||
framesize_t FRAME_SIZE_IMAGE = FRAMESIZE_SVGA; // default camera resolution
|
framesize_t FRAME_SIZE_IMAGE = FRAMESIZE_SVGA; // default camera resolution
|
||||||
// Resolutions available:
|
// Resolutions available:
|
||||||
|
@ -1464,48 +1464,49 @@ bool getNTPtime(int sec) {
|
||||||
// ----------------------------------------------------------------
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
bool handleJPG() {
|
bool handleJPG() {
|
||||||
|
WiFiClient client = server.client();
|
||||||
WiFiClient client = server.client(); // open link with client
|
|
||||||
char buf[32];
|
char buf[32];
|
||||||
|
|
||||||
// capture the jpg image from camera
|
camera_fb_t * fb = NULL;
|
||||||
camera_fb_t * fb = NULL;
|
|
||||||
|
for (int attempts = 0; attempts < 3; attempts++) {
|
||||||
fb = esp_camera_fb_get();
|
fb = esp_camera_fb_get();
|
||||||
// there is a bug where this buffer can be from previous capture so as workaround it is discarded and captured again
|
if (fb && fb->buf && fb->len > 0) break;
|
||||||
esp_camera_fb_return(fb); // dispose the buffered image
|
esp_camera_fb_return(fb);
|
||||||
fb = NULL; // reset to capture errors
|
fb = NULL;
|
||||||
fb = esp_camera_fb_get(); // get fresh image
|
delay(100); // Delay before retry
|
||||||
if (!fb) {
|
}
|
||||||
if (serialDebug) Serial.println("Error: failed to capture image");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// store image resolution info.
|
if (!fb) {
|
||||||
ImageResDetails = String(fb->width) + "x" + String(fb->height);
|
if (serialDebug) Serial.println("Error: failed to capture image after retries");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// html to send a jpg
|
ImageResDetails = String(fb->width) + "x" + String(fb->height);
|
||||||
const char HEADER[] = "HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin: *\r\n";
|
|
||||||
const char CTNTTYPE[] = "Content-Type: image/jpeg\r\nContent-Length: ";
|
|
||||||
const int hdrLen = strlen(HEADER);
|
|
||||||
const int cntLen = strlen(CTNTTYPE);
|
|
||||||
client.write(HEADER, hdrLen);
|
|
||||||
client.write(CTNTTYPE, cntLen);
|
|
||||||
sprintf( buf, "%d\r\n\r\n", fb->len); // put text size in to 'buf' char array and send
|
|
||||||
client.write(buf, strlen(buf));
|
|
||||||
|
|
||||||
// send the captured jpg data
|
const char HEADER[] = "HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin: *\r\n";
|
||||||
client.write((char *)fb->buf, fb->len);
|
const char CTNTTYPE[] = "Content-Type: image/jpeg\r\nContent-Length: ";
|
||||||
|
client.write(HEADER, strlen(HEADER));
|
||||||
|
client.write(CTNTTYPE, strlen(CTNTTYPE));
|
||||||
|
|
||||||
// close network client connection
|
sprintf(buf, "%d\r\n\r\n", fb->len);
|
||||||
delay(3);
|
client.write(buf, strlen(buf));
|
||||||
client.stop();
|
|
||||||
|
|
||||||
esp_camera_fb_return(fb); // return camera frame buffer
|
if (client.connected()) {
|
||||||
|
client.write((char *)fb->buf, fb->len);
|
||||||
|
} else {
|
||||||
|
if (serialDebug) Serial.println("Error: client disconnected during transmission");
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(3);
|
||||||
|
client.flush();
|
||||||
|
client.stop();
|
||||||
|
|
||||||
|
esp_camera_fb_return(fb);
|
||||||
|
fb = NULL;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
} // handleJPG
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------
|
// ----------------------------------------------------------------
|
||||||
|
|
Ładowanie…
Reference in New Issue