From 281f2e0ab2d5963c246698b9d7be0293c25ebb57 Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Sat, 14 Dec 2024 22:14:06 +0700 Subject: [PATCH 01/18] CAMERA_MODEL_XIAO_ESP32S3 added --- examples/Camera/snapshot-camera/camera_pins.h | 20 ++++++++++++++ .../snapshot-camera/snapshot-camera.ino | 26 +++++++++++-------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/examples/Camera/snapshot-camera/camera_pins.h b/examples/Camera/snapshot-camera/camera_pins.h index 89eca49..1fe24c7 100644 --- a/examples/Camera/snapshot-camera/camera_pins.h +++ b/examples/Camera/snapshot-camera/camera_pins.h @@ -267,6 +267,26 @@ #define HREF_GPIO_NUM 7 #define PCLK_GPIO_NUM 13 +#elif defined(CAMERA_MODEL_XIAO_ESP32S3) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 10 +#define SIOD_GPIO_NUM 40 +#define SIOC_GPIO_NUM 39 + +#define Y9_GPIO_NUM 48 +#define Y8_GPIO_NUM 11 +#define Y7_GPIO_NUM 12 +#define Y6_GPIO_NUM 14 +#define Y5_GPIO_NUM 16 +#define Y4_GPIO_NUM 18 +#define Y3_GPIO_NUM 17 +#define Y2_GPIO_NUM 15 +#define VSYNC_GPIO_NUM 38 +#define HREF_GPIO_NUM 47 +#define PCLK_GPIO_NUM 13 + +#define LED_GPIO_NUM 21 #else #error "Camera model not selected" #endif diff --git a/examples/Camera/snapshot-camera/snapshot-camera.ino b/examples/Camera/snapshot-camera/snapshot-camera.ino index 5eb9cf8..8d4aaff 100644 --- a/examples/Camera/snapshot-camera/snapshot-camera.ino +++ b/examples/Camera/snapshot-camera/snapshot-camera.ino @@ -23,20 +23,24 @@ #include +// =================== // Select camera model -//#define CAMERA_MODEL_WROVER_KIT -//#define CAMERA_MODEL_ESP_EYE -//#define CAMERA_MODEL_M5STACK_PSRAM -//#define CAMERA_MODEL_M5STACK_V2_PSRAM -//#define CAMERA_MODEL_M5STACK_WIDE -//#define CAMERA_MODEL_M5STACK_ESP32CAM -//#define CAMERA_MODEL_M5STACK_UNITCAM -//#define CAMERA_MODEL_AI_THINKER -//#define CAMERA_MODEL_TTGO_T_JOURNAL +// =================== +//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM +//#define CAMERA_MODEL_ESP_EYE // Has PSRAM +//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM. +//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM +//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM +//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM +//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM +//#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM +//#define CAMERA_MODEL_AI_THINKER // Has PSRAM +//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM +// ** Espressif Internal Boards ** //#define CAMERA_MODEL_ESP32_CAM_BOARD -//#define CAMERA_MODEL_ESP32S3_CAM_LCD //#define CAMERA_MODEL_ESP32S2_CAM_BOARD -//#define CAMERA_MODEL_ESP32S3_EYE +//#define CAMERA_MODEL_ESP32S3_CAM_LCD +//#define CAMERA_MODEL_XIAO_ESP32S3 #include "camera_pins.h" From 312c7f323ccf97fdcbd8a3e1d8d4fd7e85e7d41a Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Sat, 14 Dec 2024 22:19:01 +0700 Subject: [PATCH 02/18] chore: additional cam models. --- examples/Camera/mjpeg-camera/camera_pins.h | 485 +++++++++-------- examples/Camera/mjpeg-camera/mjpeg-camera.ino | 30 +- examples/Camera/rtsp-camera/camera_pins.h | 485 +++++++++-------- examples/Camera/rtsp-camera/rtsp-camera.ino | 31 +- examples/Camera/snapshot-camera/camera_pins.h | 506 ++++++++++-------- .../snapshot-camera/snapshot-camera.ino | 10 +- 6 files changed, 870 insertions(+), 677 deletions(-) diff --git a/examples/Camera/mjpeg-camera/camera_pins.h b/examples/Camera/mjpeg-camera/camera_pins.h index e1be287..a007ffd 100644 --- a/examples/Camera/mjpeg-camera/camera_pins.h +++ b/examples/Camera/mjpeg-camera/camera_pins.h @@ -1,259 +1,305 @@ #if defined(CAMERA_MODEL_WROVER_KIT) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 21 -#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 19 -#define Y4_GPIO_NUM 18 -#define Y3_GPIO_NUM 5 -#define Y2_GPIO_NUM 4 -#define VSYNC_GPIO_NUM 25 -#define HREF_GPIO_NUM 23 -#define PCLK_GPIO_NUM 22 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 21 +#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 19 +#define Y4_GPIO_NUM 18 +#define Y3_GPIO_NUM 5 +#define Y2_GPIO_NUM 4 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 23 +#define PCLK_GPIO_NUM 22 #elif defined(CAMERA_MODEL_ESP_EYE) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 4 -#define SIOD_GPIO_NUM 18 -#define SIOC_GPIO_NUM 23 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 4 +#define SIOD_GPIO_NUM 18 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 37 +#define Y7_GPIO_NUM 38 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 35 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 13 +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 -#define Y9_GPIO_NUM 36 -#define Y8_GPIO_NUM 37 -#define Y7_GPIO_NUM 38 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 35 -#define Y4_GPIO_NUM 14 -#define Y3_GPIO_NUM 13 -#define Y2_GPIO_NUM 34 -#define VSYNC_GPIO_NUM 5 -#define HREF_GPIO_NUM 27 -#define PCLK_GPIO_NUM 25 +#define LED_GPIO_NUM 22 #elif defined(CAMERA_MODEL_M5STACK_PSRAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 #elif defined(CAMERA_MODEL_M5STACK_V2_PSRAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 22 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 25 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 22 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 #elif defined(CAMERA_MODEL_M5STACK_WIDE) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 22 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 25 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 22 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#define LED_GPIO_NUM 2 #elif defined(CAMERA_MODEL_M5STACK_ESP32CAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 17 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 17 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 #elif defined(CAMERA_MODEL_M5STACK_UNITCAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#elif defined(CAMERA_MODEL_M5STACK_CAMS3_UNIT) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 21 +#define XCLK_GPIO_NUM 11 +#define SIOD_GPIO_NUM 17 +#define SIOC_GPIO_NUM 41 + +#define Y9_GPIO_NUM 13 +#define Y8_GPIO_NUM 4 +#define Y7_GPIO_NUM 10 +#define Y6_GPIO_NUM 5 +#define Y5_GPIO_NUM 7 +#define Y4_GPIO_NUM 16 +#define Y3_GPIO_NUM 15 +#define Y2_GPIO_NUM 6 +#define VSYNC_GPIO_NUM 42 +#define HREF_GPIO_NUM 18 +#define PCLK_GPIO_NUM 12 + +#define LED_GPIO_NUM 14 #elif defined(CAMERA_MODEL_AI_THINKER) -#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 +#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 + +// 4 for flash led or 33 for normal led +#define LED_GPIO_NUM 4 #elif defined(CAMERA_MODEL_TTGO_T_JOURNAL) -#define PWDN_GPIO_NUM 0 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 17 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM 0 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 17 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#elif defined(CAMERA_MODEL_XIAO_ESP32S3) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 10 +#define SIOD_GPIO_NUM 40 +#define SIOC_GPIO_NUM 39 +#define Y9_GPIO_NUM 48 +#define Y8_GPIO_NUM 11 +#define Y7_GPIO_NUM 12 +#define Y6_GPIO_NUM 14 +#define Y5_GPIO_NUM 16 +#define Y4_GPIO_NUM 18 +#define Y3_GPIO_NUM 17 +#define Y2_GPIO_NUM 15 +#define VSYNC_GPIO_NUM 38 +#define HREF_GPIO_NUM 47 +#define PCLK_GPIO_NUM 13 #elif defined(CAMERA_MODEL_ESP32_CAM_BOARD) // The 18 pin header on the board has Y5 and Y3 swapped -#define USE_BOARD_HEADER 0 +#define USE_BOARD_HEADER 0 #define PWDN_GPIO_NUM 32 #define RESET_GPIO_NUM 33 -#define XCLK_GPIO_NUM 4 +#define XCLK_GPIO_NUM 4 #define SIOD_GPIO_NUM 18 #define SIOC_GPIO_NUM 23 -#define Y9_GPIO_NUM 36 -#define Y8_GPIO_NUM 19 -#define Y7_GPIO_NUM 21 -#define Y6_GPIO_NUM 39 +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 19 +#define Y7_GPIO_NUM 21 +#define Y6_GPIO_NUM 39 #if USE_BOARD_HEADER -#define Y5_GPIO_NUM 13 +#define Y5_GPIO_NUM 13 #else -#define Y5_GPIO_NUM 35 +#define Y5_GPIO_NUM 35 #endif -#define Y4_GPIO_NUM 14 +#define Y4_GPIO_NUM 14 #if USE_BOARD_HEADER -#define Y3_GPIO_NUM 35 +#define Y3_GPIO_NUM 35 #else -#define Y3_GPIO_NUM 13 +#define Y3_GPIO_NUM 13 #endif -#define Y2_GPIO_NUM 34 -#define VSYNC_GPIO_NUM 5 -#define HREF_GPIO_NUM 27 -#define PCLK_GPIO_NUM 25 +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 #elif defined(CAMERA_MODEL_ESP32S3_CAM_LCD) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 40 -#define SIOD_GPIO_NUM 17 -#define SIOC_GPIO_NUM 18 - -#define Y9_GPIO_NUM 39 -#define Y8_GPIO_NUM 41 -#define Y7_GPIO_NUM 42 -#define Y6_GPIO_NUM 12 -#define Y5_GPIO_NUM 3 -#define Y4_GPIO_NUM 14 -#define Y3_GPIO_NUM 47 -#define Y2_GPIO_NUM 13 -#define VSYNC_GPIO_NUM 21 -#define HREF_GPIO_NUM 38 -#define PCLK_GPIO_NUM 11 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 40 +#define SIOD_GPIO_NUM 17 +#define SIOC_GPIO_NUM 18 + +#define Y9_GPIO_NUM 39 +#define Y8_GPIO_NUM 41 +#define Y7_GPIO_NUM 42 +#define Y6_GPIO_NUM 12 +#define Y5_GPIO_NUM 3 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 47 +#define Y2_GPIO_NUM 13 +#define VSYNC_GPIO_NUM 21 +#define HREF_GPIO_NUM 38 +#define PCLK_GPIO_NUM 11 #elif defined(CAMERA_MODEL_ESP32S2_CAM_BOARD) // The 18 pin header on the board has Y5 and Y3 swapped #define USE_BOARD_HEADER 0 -#define PWDN_GPIO_NUM 1 -#define RESET_GPIO_NUM 2 -#define XCLK_GPIO_NUM 42 -#define SIOD_GPIO_NUM 41 -#define SIOC_GPIO_NUM 18 - -#define Y9_GPIO_NUM 16 -#define Y8_GPIO_NUM 39 -#define Y7_GPIO_NUM 40 -#define Y6_GPIO_NUM 15 +#define PWDN_GPIO_NUM 1 +#define RESET_GPIO_NUM 2 +#define XCLK_GPIO_NUM 42 +#define SIOD_GPIO_NUM 41 +#define SIOC_GPIO_NUM 18 + +#define Y9_GPIO_NUM 16 +#define Y8_GPIO_NUM 39 +#define Y7_GPIO_NUM 40 +#define Y6_GPIO_NUM 15 #if USE_BOARD_HEADER -#define Y5_GPIO_NUM 12 +#define Y5_GPIO_NUM 12 #else -#define Y5_GPIO_NUM 13 +#define Y5_GPIO_NUM 13 #endif -#define Y4_GPIO_NUM 5 +#define Y4_GPIO_NUM 5 #if USE_BOARD_HEADER -#define Y3_GPIO_NUM 13 +#define Y3_GPIO_NUM 13 #else -#define Y3_GPIO_NUM 12 +#define Y3_GPIO_NUM 12 #endif -#define Y2_GPIO_NUM 14 -#define VSYNC_GPIO_NUM 38 -#define HREF_GPIO_NUM 4 -#define PCLK_GPIO_NUM 3 +#define Y2_GPIO_NUM 14 +#define VSYNC_GPIO_NUM 38 +#define HREF_GPIO_NUM 4 +#define PCLK_GPIO_NUM 3 #elif defined(CAMERA_MODEL_ESP32S3_EYE) -#define PWDN_GPIO_NUM -1 +#define PWDN_GPIO_NUM -1 #define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 15 -#define SIOD_GPIO_NUM 4 -#define SIOC_GPIO_NUM 5 +#define XCLK_GPIO_NUM 15 +#define SIOD_GPIO_NUM 4 +#define SIOC_GPIO_NUM 5 #define Y2_GPIO_NUM 11 #define Y3_GPIO_NUM 9 @@ -265,9 +311,28 @@ #define Y9_GPIO_NUM 16 #define VSYNC_GPIO_NUM 6 -#define HREF_GPIO_NUM 7 -#define PCLK_GPIO_NUM 13 +#define HREF_GPIO_NUM 7 +#define PCLK_GPIO_NUM 13 + +#elif defined(CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3) || defined(CAMERA_MODEL_DFRobot_Romeo_ESP32S3) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 45 +#define SIOD_GPIO_NUM 1 +#define SIOC_GPIO_NUM 2 + +#define Y9_GPIO_NUM 48 +#define Y8_GPIO_NUM 46 +#define Y7_GPIO_NUM 8 +#define Y6_GPIO_NUM 7 +#define Y5_GPIO_NUM 4 +#define Y4_GPIO_NUM 41 +#define Y3_GPIO_NUM 40 +#define Y2_GPIO_NUM 39 +#define VSYNC_GPIO_NUM 6 +#define HREF_GPIO_NUM 42 +#define PCLK_GPIO_NUM 5 #else #error "Camera model not selected" -#endif +#endif \ No newline at end of file diff --git a/examples/Camera/mjpeg-camera/mjpeg-camera.ino b/examples/Camera/mjpeg-camera/mjpeg-camera.ino index 488152d..8f8e0c5 100644 --- a/examples/Camera/mjpeg-camera/mjpeg-camera.ino +++ b/examples/Camera/mjpeg-camera/mjpeg-camera.ino @@ -4,20 +4,28 @@ #include "SinricPro.h" #include "SinricProCamera.h" +// =================== // Select camera model -//#define CAMERA_MODEL_WROVER_KIT -//#define CAMERA_MODEL_ESP_EYE -//#define CAMERA_MODEL_M5STACK_PSRAM -//#define CAMERA_MODEL_M5STACK_V2_PSRAM -//#define CAMERA_MODEL_M5STACK_WIDE -//#define CAMERA_MODEL_M5STACK_ESP32CAM -//#define CAMERA_MODEL_M5STACK_UNITCAM -//#define CAMERA_MODEL_AI_THINKER -//#define CAMERA_MODEL_TTGO_T_JOURNAL +// =================== +//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM +//#define CAMERA_MODEL_ESP_EYE // Has PSRAM +//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM +//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM +//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM +//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM +//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM +//#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM +//#define CAMERA_MODEL_M5STACK_CAMS3_UNIT // Has PSRAM +//#define CAMERA_MODEL_AI_THINKER // Has PSRAM +//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM +//#define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM +// ** Espressif Internal Boards ** //#define CAMERA_MODEL_ESP32_CAM_BOARD -//#define CAMERA_MODEL_ESP32S3_CAM_LCD //#define CAMERA_MODEL_ESP32S2_CAM_BOARD -//#define CAMERA_MODEL_ESP32S3_EYE +//#define CAMERA_MODEL_ESP32S3_CAM_LCD +//#define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM +//#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM +#include "camera_pins.h" #include "camera_pins.h" diff --git a/examples/Camera/rtsp-camera/camera_pins.h b/examples/Camera/rtsp-camera/camera_pins.h index e1be287..a007ffd 100644 --- a/examples/Camera/rtsp-camera/camera_pins.h +++ b/examples/Camera/rtsp-camera/camera_pins.h @@ -1,259 +1,305 @@ #if defined(CAMERA_MODEL_WROVER_KIT) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 21 -#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 19 -#define Y4_GPIO_NUM 18 -#define Y3_GPIO_NUM 5 -#define Y2_GPIO_NUM 4 -#define VSYNC_GPIO_NUM 25 -#define HREF_GPIO_NUM 23 -#define PCLK_GPIO_NUM 22 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 21 +#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 19 +#define Y4_GPIO_NUM 18 +#define Y3_GPIO_NUM 5 +#define Y2_GPIO_NUM 4 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 23 +#define PCLK_GPIO_NUM 22 #elif defined(CAMERA_MODEL_ESP_EYE) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 4 -#define SIOD_GPIO_NUM 18 -#define SIOC_GPIO_NUM 23 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 4 +#define SIOD_GPIO_NUM 18 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 37 +#define Y7_GPIO_NUM 38 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 35 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 13 +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 -#define Y9_GPIO_NUM 36 -#define Y8_GPIO_NUM 37 -#define Y7_GPIO_NUM 38 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 35 -#define Y4_GPIO_NUM 14 -#define Y3_GPIO_NUM 13 -#define Y2_GPIO_NUM 34 -#define VSYNC_GPIO_NUM 5 -#define HREF_GPIO_NUM 27 -#define PCLK_GPIO_NUM 25 +#define LED_GPIO_NUM 22 #elif defined(CAMERA_MODEL_M5STACK_PSRAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 #elif defined(CAMERA_MODEL_M5STACK_V2_PSRAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 22 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 25 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 22 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 #elif defined(CAMERA_MODEL_M5STACK_WIDE) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 22 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 25 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 22 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#define LED_GPIO_NUM 2 #elif defined(CAMERA_MODEL_M5STACK_ESP32CAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 17 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 17 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 #elif defined(CAMERA_MODEL_M5STACK_UNITCAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#elif defined(CAMERA_MODEL_M5STACK_CAMS3_UNIT) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 21 +#define XCLK_GPIO_NUM 11 +#define SIOD_GPIO_NUM 17 +#define SIOC_GPIO_NUM 41 + +#define Y9_GPIO_NUM 13 +#define Y8_GPIO_NUM 4 +#define Y7_GPIO_NUM 10 +#define Y6_GPIO_NUM 5 +#define Y5_GPIO_NUM 7 +#define Y4_GPIO_NUM 16 +#define Y3_GPIO_NUM 15 +#define Y2_GPIO_NUM 6 +#define VSYNC_GPIO_NUM 42 +#define HREF_GPIO_NUM 18 +#define PCLK_GPIO_NUM 12 + +#define LED_GPIO_NUM 14 #elif defined(CAMERA_MODEL_AI_THINKER) -#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 +#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 + +// 4 for flash led or 33 for normal led +#define LED_GPIO_NUM 4 #elif defined(CAMERA_MODEL_TTGO_T_JOURNAL) -#define PWDN_GPIO_NUM 0 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 17 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM 0 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 17 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#elif defined(CAMERA_MODEL_XIAO_ESP32S3) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 10 +#define SIOD_GPIO_NUM 40 +#define SIOC_GPIO_NUM 39 +#define Y9_GPIO_NUM 48 +#define Y8_GPIO_NUM 11 +#define Y7_GPIO_NUM 12 +#define Y6_GPIO_NUM 14 +#define Y5_GPIO_NUM 16 +#define Y4_GPIO_NUM 18 +#define Y3_GPIO_NUM 17 +#define Y2_GPIO_NUM 15 +#define VSYNC_GPIO_NUM 38 +#define HREF_GPIO_NUM 47 +#define PCLK_GPIO_NUM 13 #elif defined(CAMERA_MODEL_ESP32_CAM_BOARD) // The 18 pin header on the board has Y5 and Y3 swapped -#define USE_BOARD_HEADER 0 +#define USE_BOARD_HEADER 0 #define PWDN_GPIO_NUM 32 #define RESET_GPIO_NUM 33 -#define XCLK_GPIO_NUM 4 +#define XCLK_GPIO_NUM 4 #define SIOD_GPIO_NUM 18 #define SIOC_GPIO_NUM 23 -#define Y9_GPIO_NUM 36 -#define Y8_GPIO_NUM 19 -#define Y7_GPIO_NUM 21 -#define Y6_GPIO_NUM 39 +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 19 +#define Y7_GPIO_NUM 21 +#define Y6_GPIO_NUM 39 #if USE_BOARD_HEADER -#define Y5_GPIO_NUM 13 +#define Y5_GPIO_NUM 13 #else -#define Y5_GPIO_NUM 35 +#define Y5_GPIO_NUM 35 #endif -#define Y4_GPIO_NUM 14 +#define Y4_GPIO_NUM 14 #if USE_BOARD_HEADER -#define Y3_GPIO_NUM 35 +#define Y3_GPIO_NUM 35 #else -#define Y3_GPIO_NUM 13 +#define Y3_GPIO_NUM 13 #endif -#define Y2_GPIO_NUM 34 -#define VSYNC_GPIO_NUM 5 -#define HREF_GPIO_NUM 27 -#define PCLK_GPIO_NUM 25 +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 #elif defined(CAMERA_MODEL_ESP32S3_CAM_LCD) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 40 -#define SIOD_GPIO_NUM 17 -#define SIOC_GPIO_NUM 18 - -#define Y9_GPIO_NUM 39 -#define Y8_GPIO_NUM 41 -#define Y7_GPIO_NUM 42 -#define Y6_GPIO_NUM 12 -#define Y5_GPIO_NUM 3 -#define Y4_GPIO_NUM 14 -#define Y3_GPIO_NUM 47 -#define Y2_GPIO_NUM 13 -#define VSYNC_GPIO_NUM 21 -#define HREF_GPIO_NUM 38 -#define PCLK_GPIO_NUM 11 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 40 +#define SIOD_GPIO_NUM 17 +#define SIOC_GPIO_NUM 18 + +#define Y9_GPIO_NUM 39 +#define Y8_GPIO_NUM 41 +#define Y7_GPIO_NUM 42 +#define Y6_GPIO_NUM 12 +#define Y5_GPIO_NUM 3 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 47 +#define Y2_GPIO_NUM 13 +#define VSYNC_GPIO_NUM 21 +#define HREF_GPIO_NUM 38 +#define PCLK_GPIO_NUM 11 #elif defined(CAMERA_MODEL_ESP32S2_CAM_BOARD) // The 18 pin header on the board has Y5 and Y3 swapped #define USE_BOARD_HEADER 0 -#define PWDN_GPIO_NUM 1 -#define RESET_GPIO_NUM 2 -#define XCLK_GPIO_NUM 42 -#define SIOD_GPIO_NUM 41 -#define SIOC_GPIO_NUM 18 - -#define Y9_GPIO_NUM 16 -#define Y8_GPIO_NUM 39 -#define Y7_GPIO_NUM 40 -#define Y6_GPIO_NUM 15 +#define PWDN_GPIO_NUM 1 +#define RESET_GPIO_NUM 2 +#define XCLK_GPIO_NUM 42 +#define SIOD_GPIO_NUM 41 +#define SIOC_GPIO_NUM 18 + +#define Y9_GPIO_NUM 16 +#define Y8_GPIO_NUM 39 +#define Y7_GPIO_NUM 40 +#define Y6_GPIO_NUM 15 #if USE_BOARD_HEADER -#define Y5_GPIO_NUM 12 +#define Y5_GPIO_NUM 12 #else -#define Y5_GPIO_NUM 13 +#define Y5_GPIO_NUM 13 #endif -#define Y4_GPIO_NUM 5 +#define Y4_GPIO_NUM 5 #if USE_BOARD_HEADER -#define Y3_GPIO_NUM 13 +#define Y3_GPIO_NUM 13 #else -#define Y3_GPIO_NUM 12 +#define Y3_GPIO_NUM 12 #endif -#define Y2_GPIO_NUM 14 -#define VSYNC_GPIO_NUM 38 -#define HREF_GPIO_NUM 4 -#define PCLK_GPIO_NUM 3 +#define Y2_GPIO_NUM 14 +#define VSYNC_GPIO_NUM 38 +#define HREF_GPIO_NUM 4 +#define PCLK_GPIO_NUM 3 #elif defined(CAMERA_MODEL_ESP32S3_EYE) -#define PWDN_GPIO_NUM -1 +#define PWDN_GPIO_NUM -1 #define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 15 -#define SIOD_GPIO_NUM 4 -#define SIOC_GPIO_NUM 5 +#define XCLK_GPIO_NUM 15 +#define SIOD_GPIO_NUM 4 +#define SIOC_GPIO_NUM 5 #define Y2_GPIO_NUM 11 #define Y3_GPIO_NUM 9 @@ -265,9 +311,28 @@ #define Y9_GPIO_NUM 16 #define VSYNC_GPIO_NUM 6 -#define HREF_GPIO_NUM 7 -#define PCLK_GPIO_NUM 13 +#define HREF_GPIO_NUM 7 +#define PCLK_GPIO_NUM 13 + +#elif defined(CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3) || defined(CAMERA_MODEL_DFRobot_Romeo_ESP32S3) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 45 +#define SIOD_GPIO_NUM 1 +#define SIOC_GPIO_NUM 2 + +#define Y9_GPIO_NUM 48 +#define Y8_GPIO_NUM 46 +#define Y7_GPIO_NUM 8 +#define Y6_GPIO_NUM 7 +#define Y5_GPIO_NUM 4 +#define Y4_GPIO_NUM 41 +#define Y3_GPIO_NUM 40 +#define Y2_GPIO_NUM 39 +#define VSYNC_GPIO_NUM 6 +#define HREF_GPIO_NUM 42 +#define PCLK_GPIO_NUM 5 #else #error "Camera model not selected" -#endif +#endif \ No newline at end of file diff --git a/examples/Camera/rtsp-camera/rtsp-camera.ino b/examples/Camera/rtsp-camera/rtsp-camera.ino index df79bac..0d60170 100644 --- a/examples/Camera/rtsp-camera/rtsp-camera.ino +++ b/examples/Camera/rtsp-camera/rtsp-camera.ino @@ -39,21 +39,28 @@ #include "OV2640Streamer.h" #include "CRtspSession.h" +// =================== // Select camera model - -//#define CAMERA_MODEL_WROVER_KIT -//#define CAMERA_MODEL_ESP_EYE -//#define CAMERA_MODEL_M5STACK_PSRAM -//#define CAMERA_MODEL_M5STACK_V2_PSRAM -//#define CAMERA_MODEL_M5STACK_WIDE -//#define CAMERA_MODEL_M5STACK_ESP32CAM -//#define CAMERA_MODEL_M5STACK_UNITCAM -//#define CAMERA_MODEL_AI_THINKER -//#define CAMERA_MODEL_TTGO_T_JOURNAL +// =================== +//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM +//#define CAMERA_MODEL_ESP_EYE // Has PSRAM +//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM +//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM +//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM +//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM +//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM +//#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM +//#define CAMERA_MODEL_M5STACK_CAMS3_UNIT // Has PSRAM +//#define CAMERA_MODEL_AI_THINKER // Has PSRAM +//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM +//#define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM +// ** Espressif Internal Boards ** //#define CAMERA_MODEL_ESP32_CAM_BOARD -//#define CAMERA_MODEL_ESP32S3_CAM_LCD //#define CAMERA_MODEL_ESP32S2_CAM_BOARD -//#define CAMERA_MODEL_ESP32S3_EYE +//#define CAMERA_MODEL_ESP32S3_CAM_LCD +//#define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM +//#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM +#include "camera_pins.h" /* Notice: diff --git a/examples/Camera/snapshot-camera/camera_pins.h b/examples/Camera/snapshot-camera/camera_pins.h index 1fe24c7..a007ffd 100644 --- a/examples/Camera/snapshot-camera/camera_pins.h +++ b/examples/Camera/snapshot-camera/camera_pins.h @@ -1,258 +1,305 @@ + #if defined(CAMERA_MODEL_WROVER_KIT) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 21 -#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 19 -#define Y4_GPIO_NUM 18 -#define Y3_GPIO_NUM 5 -#define Y2_GPIO_NUM 4 -#define VSYNC_GPIO_NUM 25 -#define HREF_GPIO_NUM 23 -#define PCLK_GPIO_NUM 22 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 21 +#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 19 +#define Y4_GPIO_NUM 18 +#define Y3_GPIO_NUM 5 +#define Y2_GPIO_NUM 4 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 23 +#define PCLK_GPIO_NUM 22 #elif defined(CAMERA_MODEL_ESP_EYE) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 4 -#define SIOD_GPIO_NUM 18 -#define SIOC_GPIO_NUM 23 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 4 +#define SIOD_GPIO_NUM 18 +#define SIOC_GPIO_NUM 23 -#define Y9_GPIO_NUM 36 -#define Y8_GPIO_NUM 37 -#define Y7_GPIO_NUM 38 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 35 -#define Y4_GPIO_NUM 14 -#define Y3_GPIO_NUM 13 -#define Y2_GPIO_NUM 34 -#define VSYNC_GPIO_NUM 5 -#define HREF_GPIO_NUM 27 -#define PCLK_GPIO_NUM 25 +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 37 +#define Y7_GPIO_NUM 38 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 35 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 13 +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 + +#define LED_GPIO_NUM 22 #elif defined(CAMERA_MODEL_M5STACK_PSRAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 #elif defined(CAMERA_MODEL_M5STACK_V2_PSRAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 22 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 25 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 22 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 #elif defined(CAMERA_MODEL_M5STACK_WIDE) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 22 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 25 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 22 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#define LED_GPIO_NUM 2 #elif defined(CAMERA_MODEL_M5STACK_ESP32CAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 17 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 17 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 #elif defined(CAMERA_MODEL_M5STACK_UNITCAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#elif defined(CAMERA_MODEL_M5STACK_CAMS3_UNIT) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 21 +#define XCLK_GPIO_NUM 11 +#define SIOD_GPIO_NUM 17 +#define SIOC_GPIO_NUM 41 + +#define Y9_GPIO_NUM 13 +#define Y8_GPIO_NUM 4 +#define Y7_GPIO_NUM 10 +#define Y6_GPIO_NUM 5 +#define Y5_GPIO_NUM 7 +#define Y4_GPIO_NUM 16 +#define Y3_GPIO_NUM 15 +#define Y2_GPIO_NUM 6 +#define VSYNC_GPIO_NUM 42 +#define HREF_GPIO_NUM 18 +#define PCLK_GPIO_NUM 12 + +#define LED_GPIO_NUM 14 #elif defined(CAMERA_MODEL_AI_THINKER) -#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 +#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 + +// 4 for flash led or 33 for normal led +#define LED_GPIO_NUM 4 #elif defined(CAMERA_MODEL_TTGO_T_JOURNAL) -#define PWDN_GPIO_NUM 0 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 17 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM 0 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 17 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 +#elif defined(CAMERA_MODEL_XIAO_ESP32S3) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 10 +#define SIOD_GPIO_NUM 40 +#define SIOC_GPIO_NUM 39 + +#define Y9_GPIO_NUM 48 +#define Y8_GPIO_NUM 11 +#define Y7_GPIO_NUM 12 +#define Y6_GPIO_NUM 14 +#define Y5_GPIO_NUM 16 +#define Y4_GPIO_NUM 18 +#define Y3_GPIO_NUM 17 +#define Y2_GPIO_NUM 15 +#define VSYNC_GPIO_NUM 38 +#define HREF_GPIO_NUM 47 +#define PCLK_GPIO_NUM 13 #elif defined(CAMERA_MODEL_ESP32_CAM_BOARD) // The 18 pin header on the board has Y5 and Y3 swapped -#define USE_BOARD_HEADER 0 +#define USE_BOARD_HEADER 0 #define PWDN_GPIO_NUM 32 #define RESET_GPIO_NUM 33 -#define XCLK_GPIO_NUM 4 +#define XCLK_GPIO_NUM 4 #define SIOD_GPIO_NUM 18 #define SIOC_GPIO_NUM 23 -#define Y9_GPIO_NUM 36 -#define Y8_GPIO_NUM 19 -#define Y7_GPIO_NUM 21 -#define Y6_GPIO_NUM 39 +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 19 +#define Y7_GPIO_NUM 21 +#define Y6_GPIO_NUM 39 #if USE_BOARD_HEADER -#define Y5_GPIO_NUM 13 +#define Y5_GPIO_NUM 13 #else -#define Y5_GPIO_NUM 35 +#define Y5_GPIO_NUM 35 #endif -#define Y4_GPIO_NUM 14 +#define Y4_GPIO_NUM 14 #if USE_BOARD_HEADER -#define Y3_GPIO_NUM 35 +#define Y3_GPIO_NUM 35 #else -#define Y3_GPIO_NUM 13 +#define Y3_GPIO_NUM 13 #endif -#define Y2_GPIO_NUM 34 -#define VSYNC_GPIO_NUM 5 -#define HREF_GPIO_NUM 27 -#define PCLK_GPIO_NUM 25 +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 #elif defined(CAMERA_MODEL_ESP32S3_CAM_LCD) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 40 -#define SIOD_GPIO_NUM 17 -#define SIOC_GPIO_NUM 18 - -#define Y9_GPIO_NUM 39 -#define Y8_GPIO_NUM 41 -#define Y7_GPIO_NUM 42 -#define Y6_GPIO_NUM 12 -#define Y5_GPIO_NUM 3 -#define Y4_GPIO_NUM 14 -#define Y3_GPIO_NUM 47 -#define Y2_GPIO_NUM 13 -#define VSYNC_GPIO_NUM 21 -#define HREF_GPIO_NUM 38 -#define PCLK_GPIO_NUM 11 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 40 +#define SIOD_GPIO_NUM 17 +#define SIOC_GPIO_NUM 18 + +#define Y9_GPIO_NUM 39 +#define Y8_GPIO_NUM 41 +#define Y7_GPIO_NUM 42 +#define Y6_GPIO_NUM 12 +#define Y5_GPIO_NUM 3 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 47 +#define Y2_GPIO_NUM 13 +#define VSYNC_GPIO_NUM 21 +#define HREF_GPIO_NUM 38 +#define PCLK_GPIO_NUM 11 #elif defined(CAMERA_MODEL_ESP32S2_CAM_BOARD) // The 18 pin header on the board has Y5 and Y3 swapped #define USE_BOARD_HEADER 0 -#define PWDN_GPIO_NUM 1 -#define RESET_GPIO_NUM 2 -#define XCLK_GPIO_NUM 42 -#define SIOD_GPIO_NUM 41 -#define SIOC_GPIO_NUM 18 - -#define Y9_GPIO_NUM 16 -#define Y8_GPIO_NUM 39 -#define Y7_GPIO_NUM 40 -#define Y6_GPIO_NUM 15 +#define PWDN_GPIO_NUM 1 +#define RESET_GPIO_NUM 2 +#define XCLK_GPIO_NUM 42 +#define SIOD_GPIO_NUM 41 +#define SIOC_GPIO_NUM 18 + +#define Y9_GPIO_NUM 16 +#define Y8_GPIO_NUM 39 +#define Y7_GPIO_NUM 40 +#define Y6_GPIO_NUM 15 #if USE_BOARD_HEADER -#define Y5_GPIO_NUM 12 +#define Y5_GPIO_NUM 12 #else -#define Y5_GPIO_NUM 13 +#define Y5_GPIO_NUM 13 #endif -#define Y4_GPIO_NUM 5 +#define Y4_GPIO_NUM 5 #if USE_BOARD_HEADER -#define Y3_GPIO_NUM 13 +#define Y3_GPIO_NUM 13 #else -#define Y3_GPIO_NUM 12 +#define Y3_GPIO_NUM 12 #endif -#define Y2_GPIO_NUM 14 -#define VSYNC_GPIO_NUM 38 -#define HREF_GPIO_NUM 4 -#define PCLK_GPIO_NUM 3 +#define Y2_GPIO_NUM 14 +#define VSYNC_GPIO_NUM 38 +#define HREF_GPIO_NUM 4 +#define PCLK_GPIO_NUM 3 #elif defined(CAMERA_MODEL_ESP32S3_EYE) -#define PWDN_GPIO_NUM -1 +#define PWDN_GPIO_NUM -1 #define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 15 -#define SIOD_GPIO_NUM 4 -#define SIOC_GPIO_NUM 5 +#define XCLK_GPIO_NUM 15 +#define SIOD_GPIO_NUM 4 +#define SIOC_GPIO_NUM 5 #define Y2_GPIO_NUM 11 #define Y3_GPIO_NUM 9 @@ -264,29 +311,28 @@ #define Y9_GPIO_NUM 16 #define VSYNC_GPIO_NUM 6 -#define HREF_GPIO_NUM 7 -#define PCLK_GPIO_NUM 13 +#define HREF_GPIO_NUM 7 +#define PCLK_GPIO_NUM 13 + +#elif defined(CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3) || defined(CAMERA_MODEL_DFRobot_Romeo_ESP32S3) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 45 +#define SIOD_GPIO_NUM 1 +#define SIOC_GPIO_NUM 2 + +#define Y9_GPIO_NUM 48 +#define Y8_GPIO_NUM 46 +#define Y7_GPIO_NUM 8 +#define Y6_GPIO_NUM 7 +#define Y5_GPIO_NUM 4 +#define Y4_GPIO_NUM 41 +#define Y3_GPIO_NUM 40 +#define Y2_GPIO_NUM 39 +#define VSYNC_GPIO_NUM 6 +#define HREF_GPIO_NUM 42 +#define PCLK_GPIO_NUM 5 -#elif defined(CAMERA_MODEL_XIAO_ESP32S3) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 10 -#define SIOD_GPIO_NUM 40 -#define SIOC_GPIO_NUM 39 - -#define Y9_GPIO_NUM 48 -#define Y8_GPIO_NUM 11 -#define Y7_GPIO_NUM 12 -#define Y6_GPIO_NUM 14 -#define Y5_GPIO_NUM 16 -#define Y4_GPIO_NUM 18 -#define Y3_GPIO_NUM 17 -#define Y2_GPIO_NUM 15 -#define VSYNC_GPIO_NUM 38 -#define HREF_GPIO_NUM 47 -#define PCLK_GPIO_NUM 13 - -#define LED_GPIO_NUM 21 #else #error "Camera model not selected" -#endif +#endif \ No newline at end of file diff --git a/examples/Camera/snapshot-camera/snapshot-camera.ino b/examples/Camera/snapshot-camera/snapshot-camera.ino index 8d4aaff..64c1d60 100644 --- a/examples/Camera/snapshot-camera/snapshot-camera.ino +++ b/examples/Camera/snapshot-camera/snapshot-camera.ino @@ -27,21 +27,23 @@ // Select camera model // =================== //#define CAMERA_MODEL_WROVER_KIT // Has PSRAM -//#define CAMERA_MODEL_ESP_EYE // Has PSRAM -//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM. +//#define CAMERA_MODEL_ESP_EYE // Has PSRAM +//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM //#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM //#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM //#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM //#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM //#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM +//#define CAMERA_MODEL_M5STACK_CAMS3_UNIT // Has PSRAM //#define CAMERA_MODEL_AI_THINKER // Has PSRAM //#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM +//#define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM // ** Espressif Internal Boards ** //#define CAMERA_MODEL_ESP32_CAM_BOARD //#define CAMERA_MODEL_ESP32S2_CAM_BOARD //#define CAMERA_MODEL_ESP32S3_CAM_LCD -//#define CAMERA_MODEL_XIAO_ESP32S3 - +//#define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM +//#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM #include "camera_pins.h" #define WIFI_SSID "YOUR-WIFI-SSID" From 6de16ea5b0bf9988b957bd540f6dc708d929e6ea Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Sat, 14 Dec 2024 23:11:48 +0700 Subject: [PATCH 03/18] chore: formatting and camera init --- .../snapshot-camera/snapshot-camera.ino | 235 ++++++++++-------- 1 file changed, 127 insertions(+), 108 deletions(-) diff --git a/examples/Camera/snapshot-camera/snapshot-camera.ino b/examples/Camera/snapshot-camera/snapshot-camera.ino index 64c1d60..a146d7a 100644 --- a/examples/Camera/snapshot-camera/snapshot-camera.ino +++ b/examples/Camera/snapshot-camera/snapshot-camera.ino @@ -2,7 +2,7 @@ * Example for how to use SinricPro Camera device: * - Create a ESP32 Camera device from portal. * - Copy the secrets below. - * + * * If you encounter any issues: * - check the readme.md at https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md * - ensure all dependent libraries are installed @@ -26,60 +26,59 @@ // =================== // Select camera model // =================== -//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM -//#define CAMERA_MODEL_ESP_EYE // Has PSRAM -//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM -//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM -//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM -//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM -//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM -//#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM -//#define CAMERA_MODEL_M5STACK_CAMS3_UNIT // Has PSRAM -//#define CAMERA_MODEL_AI_THINKER // Has PSRAM -//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM -//#define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM +// #define CAMERA_MODEL_WROVER_KIT // Has PSRAM +// #define CAMERA_MODEL_ESP_EYE // Has PSRAM +// #define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM +// #define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM +// #define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM +// #define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM +// #define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM +// #define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM +// #define CAMERA_MODEL_M5STACK_CAMS3_UNIT // Has PSRAM +// #define CAMERA_MODEL_AI_THINKER // Has PSRAM +// #define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM +// #define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM // ** Espressif Internal Boards ** -//#define CAMERA_MODEL_ESP32_CAM_BOARD -//#define CAMERA_MODEL_ESP32S2_CAM_BOARD -//#define CAMERA_MODEL_ESP32S3_CAM_LCD -//#define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM -//#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM -#include "camera_pins.h" +// #define CAMERA_MODEL_ESP32_CAM_BOARD +// #define CAMERA_MODEL_ESP32S2_CAM_BOARD +// #define CAMERA_MODEL_ESP32S3_CAM_LCD +// #define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM +// #define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM +#include "camera_pins.h" #define WIFI_SSID "YOUR-WIFI-SSID" #define WIFI_PASS "YOUR-WIFI-PASSWORD" #define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx" #define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx" #define CAMERA_ID "YOUR-ESP32-CAMERA-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx" -#define BAUD_RATE 115200 // Change baudrate to your need - -bool onSnapshot(const String& deviceId) { - camera_fb_t* fb = esp_camera_fb_get(); - - if (!fb) { - Serial.println("Failed to grab image"); - return false; - } - - SinricProCamera& myCamera = SinricPro[deviceId]; - int result = myCamera.sendSnapshot(fb->buf, fb->len); - esp_camera_fb_return(fb); - - return result == 200; + +#define BAUD_RATE 115200 // Change baudrate to your need + +bool onSnapshot(const String &deviceId) { + camera_fb_t *fb = esp_camera_fb_get(); + + if (!fb) { + Serial.println("Failed to grab image"); + return false; + } + + SinricProCamera &myCamera = SinricPro[deviceId]; + int result = myCamera.sendSnapshot(fb->buf, fb->len); + esp_camera_fb_return(fb); + + return result == 200; } -bool onPowerState(const String& deviceId, bool& state) { - return true; +bool onPowerState(const String &deviceId, bool &state) { + return true; } // setup function for WiFi connection void setupWiFi() { Serial.printf("\r\n[Wifi]: Connecting"); - WiFi.setSleep(false); - WiFi.setAutoReconnect(true); - - WiFi.begin(WIFI_SSID, WIFI_PASS); + WiFi.begin(WIFI_SSID, WIFI_PASS); + WiFi.setSleep(false); while (WiFi.status() != WL_CONNECTED) { Serial.printf("."); @@ -89,79 +88,99 @@ void setupWiFi() { } void setupSinricPro() { - SinricProCamera& myCamera = SinricPro[CAMERA_ID]; - myCamera.onPowerState(onPowerState); - myCamera.onSnapshot(onSnapshot); - SinricPro.onConnected([]() { Serial.printf("Connected to SinricPro\r\n"); }); - SinricPro.onDisconnected([]() { Serial.printf("Disconnected from SinricPro\r\n"); }); - - SinricPro.begin(APP_KEY, APP_SECRET); + SinricProCamera &myCamera = SinricPro[CAMERA_ID]; + myCamera.onPowerState(onPowerState); + myCamera.onSnapshot(onSnapshot); + SinricPro.onConnected([]() { + Serial.printf("Connected to SinricPro\r\n"); + }); + SinricPro.onDisconnected([]() { + Serial.printf("Disconnected from SinricPro\r\n"); + }); + + SinricPro.begin(APP_KEY, APP_SECRET); } -esp_err_t setupCamera() { - 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_sccb_sda = SIOD_GPIO_NUM; - config.pin_sccb_scl = SIOC_GPIO_NUM; - config.pin_pwdn = PWDN_GPIO_NUM; - config.pin_reset = RESET_GPIO_NUM; - config.xclk_freq_hz = 20000000; - config.frame_size = FRAMESIZE_XGA; - config.pixel_format = PIXFORMAT_JPEG; - config.grab_mode = CAMERA_GRAB_WHEN_EMPTY; - config.fb_location = CAMERA_FB_IN_PSRAM; - config.jpeg_quality = 12; - config.fb_count = 1; - - // if PSRAM IC present, init with UXGA resolution and higher JPEG quality - // for larger pre-allocated frame buffer. - if (psramFound()) { - config.jpeg_quality = 10; - config.fb_count = 2; - config.grab_mode = CAMERA_GRAB_LATEST; - } else { - // Limit the frame size when PSRAM is not available - config.frame_size = FRAMESIZE_SVGA; - config.fb_location = CAMERA_FB_IN_DRAM; - } - - // camera init - esp_err_t err = esp_camera_init(&config); - if (err != ESP_OK) { - return err; - } - - sensor_t* s = esp_camera_sensor_get(); - // initial sensors are flipped vertically and colors are a bit saturated - s->set_vflip(s, 1); // flip it back - s->set_brightness(s, 1); // up the brightness just a bit - s->set_saturation(s, 0); // lower the saturation - - return ESP_OK; +void setupCamera() { + 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_sccb_sda = SIOD_GPIO_NUM; + config.pin_sccb_scl = SIOC_GPIO_NUM; + config.pin_pwdn = PWDN_GPIO_NUM; + config.pin_reset = RESET_GPIO_NUM; + config.xclk_freq_hz = 20000000; + config.frame_size = FRAMESIZE_XGA; + config.pixel_format = PIXFORMAT_JPEG; // do not change! + // config.pixel_format = PIXFORMAT_RGB565; // for face detection/recognition + config.grab_mode = CAMERA_GRAB_WHEN_EMPTY; + config.fb_location = CAMERA_FB_IN_PSRAM; + config.jpeg_quality = 12; + config.fb_count = 1; + + if (psramFound()) { + config.jpeg_quality = 10; + config.fb_count = 2; + config.grab_mode = CAMERA_GRAB_LATEST; + } else { + // Limit the frame size when PSRAM is not available + config.frame_size = FRAMESIZE_SVGA; + config.fb_location = CAMERA_FB_IN_DRAM; + } + +#if defined(CAMERA_MODEL_ESP_EYE) + pinMode(13, INPUT_PULLUP); + pinMode(14, INPUT_PULLUP); +#endif + + // camera init + esp_err_t err = esp_camera_init(&config); + if (err != ESP_OK) { + Serial.printf("Camera init failed with error 0x%x", err); + return; + } + + sensor_t *s = esp_camera_sensor_get(); + // initial sensors are flipped vertically and colors are a bit saturated + if (s->id.PID == OV3660_PID) { + s->set_vflip(s, 1); // flip it back + s->set_brightness(s, 1); // up the brightness just a bit + s->set_saturation(s, -2); // lower the saturation + } + +#if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM) + s->set_vflip(s, 1); + s->set_hmirror(s, 1); +#endif + +#if defined(CAMERA_MODEL_ESP32S3_EYE) + s->set_vflip(s, 1); +#endif } void setup() { - Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n"); - setupWiFi(); - setupSinricPro(); - setupCamera(); + Serial.begin(BAUD_RATE); + Serial.setDebugOutput(true); + Serial.println(); + delay(1500); + + setupCamera(); + setupWiFi(); + setupSinricPro(); } void loop() { - SinricPro.handle(); -} - - + SinricPro.handle(); +} \ No newline at end of file From a9b02ad3ccea84a896f110a59db9a6b15976eb2a Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Sat, 14 Dec 2024 23:14:50 +0700 Subject: [PATCH 04/18] chore: formatting --- examples/Camera/snapshot-camera/snapshot-camera.ino | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/Camera/snapshot-camera/snapshot-camera.ino b/examples/Camera/snapshot-camera/snapshot-camera.ino index a146d7a..61fcecd 100644 --- a/examples/Camera/snapshot-camera/snapshot-camera.ino +++ b/examples/Camera/snapshot-camera/snapshot-camera.ino @@ -172,10 +172,8 @@ void setupCamera() { void setup() { Serial.begin(BAUD_RATE); - Serial.setDebugOutput(true); Serial.println(); - delay(1500); - + setupCamera(); setupWiFi(); setupSinricPro(); @@ -183,4 +181,4 @@ void setup() { void loop() { SinricPro.handle(); -} \ No newline at end of file +} From 18d7b5c5ebe527111b1c85f820b5fcbdbfd71761 Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Fri, 20 Dec 2024 00:46:18 +0700 Subject: [PATCH 05/18] fix: use unique_ptr to clean up client --- src/Capabilities/CameraController.h | 32 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Capabilities/CameraController.h b/src/Capabilities/CameraController.h index 1d989e6..924a336 100644 --- a/src/Capabilities/CameraController.h +++ b/src/Capabilities/CameraController.h @@ -83,26 +83,23 @@ int CameraController::sendSnapshot(uint8_t* buffer, size_t len) { int resCode = -1; #if defined(ESP32) - T *device = static_cast(this); - - // Validate input buffer + T* device = static_cast(this); + if (!buffer) return resCode; HTTPClient http; bool beginSuccess = false; - #ifdef SINRICPRO_NOSSL - WiFiClient *client = new WiFiClient(); - if (!client) return resCode; - - beginSuccess = http.begin(*client, SINRICPRO_CAMERA_URL, 80, SINRICPRO_CAMERA_PATH, false); - #else - WiFiClientSecure *secureClient = new WiFiClientSecure(); - if (!secureClient) return resCode; - - secureClient->setInsecure(); // Skip certificate validation - beginSuccess = http.begin(*secureClient, SINRICPRO_CAMERA_URL, 443, SINRICPRO_CAMERA_PATH, true); - #endif +#ifdef SINRICPRO_NOSSL + std::unique_ptr client = std::make_unique(); + if (!client) return resCode; + beginSuccess = http.begin(*client, SINRICPRO_CAMERA_URL, 80, SINRICPRO_CAMERA_PATH, false); +#else + std::unique_ptr secureClient = std::make_unique(); + if (!secureClient) return resCode; + secureClient->setInsecure(); + beginSuccess = http.begin(*secureClient, SINRICPRO_CAMERA_URL, 443, SINRICPRO_CAMERA_PATH, true); +#endif if (!beginSuccess) { http.end(); @@ -111,7 +108,7 @@ int CameraController::sendSnapshot(uint8_t* buffer, size_t len) { const String& deviceId = device->getDeviceId(); String createdAt = String(device->getTimestamp()); - String signature = device->sign(deviceId+createdAt); + String signature = device->sign(deviceId + createdAt); http.addHeader(FSTR_SINRICPRO_deviceId, deviceId); http.addHeader(FSTR_SINRICPRO_createdAt, createdAt); @@ -120,8 +117,9 @@ int CameraController::sendSnapshot(uint8_t* buffer, size_t len) { resCode = http.POST(buffer, len); http.end(); #endif - + return resCode; } + } // namespace SINRICPRO_NAMESPACE \ No newline at end of file From 96219990e474a528b2f2f667e064b7aad6857a3e Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Sun, 5 Jan 2025 09:07:44 +0700 Subject: [PATCH 06/18] feat: camera motion capture as gif --- examples/Camera/motion-capture/camera_pins.h | 563 ++++++++++++++++++ .../Camera/motion-capture/motion-capture.ino | 367 ++++++++++++ examples/Camera/snapshot-camera/camera_pins.h | 225 +++++++ .../snapshot-camera/snapshot-camera.ino | 45 +- src/Capabilities/CameraController.h | 132 ++-- src/SinricProCamera.h | 2 +- src/SinricProConfig.h | 17 +- 7 files changed, 1299 insertions(+), 52 deletions(-) create mode 100644 examples/Camera/motion-capture/camera_pins.h create mode 100644 examples/Camera/motion-capture/motion-capture.ino diff --git a/examples/Camera/motion-capture/camera_pins.h b/examples/Camera/motion-capture/camera_pins.h new file mode 100644 index 0000000..dbb01e3 --- /dev/null +++ b/examples/Camera/motion-capture/camera_pins.h @@ -0,0 +1,563 @@ + +#if defined(CAMERA_MODEL_WROVER_KIT) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 21 +#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 19 +#define Y4_GPIO_NUM 18 +#define Y3_GPIO_NUM 5 +#define Y2_GPIO_NUM 4 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 23 +#define PCLK_GPIO_NUM 22 + +#elif defined(CAMERA_MODEL_ESP_EYE) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 4 +#define SIOD_GPIO_NUM 18 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 37 +#define Y7_GPIO_NUM 38 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 35 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 13 +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 + +#define LED_GPIO_NUM 22 + +#elif defined(CAMERA_MODEL_M5STACK_PSRAM) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#elif defined(CAMERA_MODEL_M5STACK_V2_PSRAM) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 22 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#elif defined(CAMERA_MODEL_M5STACK_WIDE) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 22 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#define LED_GPIO_NUM 2 + +#elif defined(CAMERA_MODEL_M5STACK_ESP32CAM) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 17 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#elif defined(CAMERA_MODEL_M5STACK_UNITCAM) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#elif defined(CAMERA_MODEL_M5STACK_CAMS3_UNIT) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 21 +#define XCLK_GPIO_NUM 11 +#define SIOD_GPIO_NUM 17 +#define SIOC_GPIO_NUM 41 + +#define Y9_GPIO_NUM 13 +#define Y8_GPIO_NUM 4 +#define Y7_GPIO_NUM 10 +#define Y6_GPIO_NUM 5 +#define Y5_GPIO_NUM 7 +#define Y4_GPIO_NUM 16 +#define Y3_GPIO_NUM 15 +#define Y2_GPIO_NUM 6 +#define VSYNC_GPIO_NUM 42 +#define HREF_GPIO_NUM 18 +#define PCLK_GPIO_NUM 12 + +#define LED_GPIO_NUM 14 + +#elif defined(CAMERA_MODEL_AI_THINKER) +#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 + +// 4 for flash led or 33 for normal led +#define LED_GPIO_NUM 4 + +#elif defined(CAMERA_MODEL_TTGO_T_JOURNAL) +#define PWDN_GPIO_NUM 0 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 17 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#elif defined(CAMERA_MODEL_TTGO_T_V16_VERSION) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 4 +#define SIOD_GPIO_NUM 18 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 15 +#define Y7_GPIO_NUM 12 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 35 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 13 +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 + +#define AS312_PIN 19 +#define BUTTON_1 0 + +#define I2C_SDA 21 +#define I2C_SCL 22 + +#define SSD130_MODLE_TYPE 0 // 0 : GEOMETRY_128_64 // 1: GEOMETRY_128_32 + +#define IIS_SCK 26 +#define IIS_WS 32 +#define IIS_DOUT 33 + +#elif defined(CAMERA_MODEL_TTGO_T_V05_VERSION) + +#define PWDN_GPIO_NUM 26 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 32 +#define SIOD_GPIO_NUM 13 +#define SIOC_GPIO_NUM 12 + +#define Y9_GPIO_NUM 39 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 23 +#define Y6_GPIO_NUM 18 +#define Y5_GPIO_NUM 15 +#define Y4_GPIO_NUM 4 +#define Y3_GPIO_NUM 14 +#define Y2_GPIO_NUM 5 + +#define VSYNC_GPIO_NUM 27 +#define HREF_GPIO_NUM 25 +#define PCLK_GPIO_NUM 19 + +#define AS312_PIN 33 +#define BUTTON_1 34 + +#define I2C_SDA 21 +#define I2C_SCL 22 + +#define SSD130_MODLE_TYPE 0 // 0 : GEOMETRY_128_64 // 1: GEOMETRY_128_32 + + +#elif defined(CAMERA_MODEL_TTGO_T_JORNAL_VERSION) + +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 17 + +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#define I2C_SDA 14 +#define I2C_SCL 13 + +#define BUTTON_1 32 + +#define SSD130_MODLE_TYPE 1 // 0 : GEOMETRY_128_64 // 1: GEOMETRY_128_32 + +#elif defined(CAMERA_MODEL_TTGO_T_PLUS_VERSION) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 4 +#define SIOD_GPIO_NUM 18 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 37 +#define Y7_GPIO_NUM 38 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 35 +#define Y4_GPIO_NUM 26 +#define Y3_GPIO_NUM 13 +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 + +#define I2C_SDA 18 +#define I2C_SCL 23 + +#define IIS_SCK 14 +#define IIS_WS 32 +#define IIS_DOUT 33 + +#define TFT_CS_PIN 12 +#define TFT_DC_PIN 15 +#define TFT_MOSI_PIN 19 +#define TFT_MISO_PIN 22 +#define TFT_SCLK_PIN 21 +#define TFT_BL_PIN 2 + +#define SDCARD_CS_PIN 0 + +#define ENABLE_IP5306 +#define ENABLE_TFT + +#elif defined(CAMERA_MODEL_TTGO_T_V162_VERSION) + +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 4 +#define SIOD_GPIO_NUM 18 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 37 +#define Y7_GPIO_NUM 38 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 35 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 13 +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 + +#define I2C_SDA 21 +#define I2C_SCL 22 + +#define BUTTON_1 15 + +#define SSD130_MODLE_TYPE 0 // 0 : GEOMETRY_128_64 // 1: GEOMETRY_128_32 + +#define AS312_PIN 19 //not rtc io ,can't form deepsleep wakeup + +#define IIS_SCK 26 +#define IIS_WS 32 +#define IIS_DOUT 33 + +#define ENABLE_IP5306 + +#elif defined(CAMERA_MODEL_TTGO_T_MINI_VERSION) + +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 32 +#define SIOD_GPIO_NUM 13 +#define SIOC_GPIO_NUM 12 + +#define Y9_GPIO_NUM 39 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 38 +#define Y6_GPIO_NUM 37 +#define Y5_GPIO_NUM 15 +#define Y4_GPIO_NUM 4 +#define Y3_GPIO_NUM 14 +#define Y2_GPIO_NUM 5 + +#define VSYNC_GPIO_NUM 27 +#define HREF_GPIO_NUM 25 +#define PCLK_GPIO_NUM 19 +#define CAMERA_PWR_PIN 26 + +#define I2C_SDA 21 +#define I2C_SCL 22 + +#define BUTTON_1 33 + +#define POWER_CONTROL_PIN 26 + +#define ENABLE_AXP192 + +#elif defined(CAMERA_MODEL_TTGO_T_V17_VERSION) + +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 32 +#define SIOD_GPIO_NUM 13 +#define SIOC_GPIO_NUM 12 + +#define Y9_GPIO_NUM 39 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 23 +#define Y6_GPIO_NUM 18 +#define Y5_GPIO_NUM 15 +#define Y4_GPIO_NUM 4 +#define Y3_GPIO_NUM 14 +#define Y2_GPIO_NUM 5 + +#define VSYNC_GPIO_NUM 27 +#define HREF_GPIO_NUM 25 +#define PCLK_GPIO_NUM 19 + +#define I2C_SDA 21 +#define I2C_SCL 22 + +#define BUTTON_1 34 + +#define SSD130_MODLE_TYPE 0 // 0 : GEOMETRY_128_64 // 1: GEOMETRY_128_32 + +#define AS312_PIN 33 + +#define ENABLE_IP5306 + +#elif defined(CAMERA_MODEL_XIAO_ESP32S3) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 10 +#define SIOD_GPIO_NUM 40 +#define SIOC_GPIO_NUM 39 + +#define Y9_GPIO_NUM 48 +#define Y8_GPIO_NUM 11 +#define Y7_GPIO_NUM 12 +#define Y6_GPIO_NUM 14 +#define Y5_GPIO_NUM 16 +#define Y4_GPIO_NUM 18 +#define Y3_GPIO_NUM 17 +#define Y2_GPIO_NUM 15 +#define VSYNC_GPIO_NUM 38 +#define HREF_GPIO_NUM 47 +#define PCLK_GPIO_NUM 13 + +#elif defined(CAMERA_MODEL_ESP32_CAM_BOARD) +// The 18 pin header on the board has Y5 and Y3 swapped +#define USE_BOARD_HEADER 0 +#define PWDN_GPIO_NUM 32 +#define RESET_GPIO_NUM 33 +#define XCLK_GPIO_NUM 4 +#define SIOD_GPIO_NUM 18 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 19 +#define Y7_GPIO_NUM 21 +#define Y6_GPIO_NUM 39 +#if USE_BOARD_HEADER +#define Y5_GPIO_NUM 13 +#else +#define Y5_GPIO_NUM 35 +#endif +#define Y4_GPIO_NUM 14 +#if USE_BOARD_HEADER +#define Y3_GPIO_NUM 35 +#else +#define Y3_GPIO_NUM 13 +#endif +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 + +#elif defined(CAMERA_MODEL_ESP32S3_CAM_LCD) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 40 +#define SIOD_GPIO_NUM 17 +#define SIOC_GPIO_NUM 18 + +#define Y9_GPIO_NUM 39 +#define Y8_GPIO_NUM 41 +#define Y7_GPIO_NUM 42 +#define Y6_GPIO_NUM 12 +#define Y5_GPIO_NUM 3 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 47 +#define Y2_GPIO_NUM 13 +#define VSYNC_GPIO_NUM 21 +#define HREF_GPIO_NUM 38 +#define PCLK_GPIO_NUM 11 + +#elif defined(CAMERA_MODEL_ESP32S2_CAM_BOARD) +// The 18 pin header on the board has Y5 and Y3 swapped +#define USE_BOARD_HEADER 0 +#define PWDN_GPIO_NUM 1 +#define RESET_GPIO_NUM 2 +#define XCLK_GPIO_NUM 42 +#define SIOD_GPIO_NUM 41 +#define SIOC_GPIO_NUM 18 + +#define Y9_GPIO_NUM 16 +#define Y8_GPIO_NUM 39 +#define Y7_GPIO_NUM 40 +#define Y6_GPIO_NUM 15 +#if USE_BOARD_HEADER +#define Y5_GPIO_NUM 12 +#else +#define Y5_GPIO_NUM 13 +#endif +#define Y4_GPIO_NUM 5 +#if USE_BOARD_HEADER +#define Y3_GPIO_NUM 13 +#else +#define Y3_GPIO_NUM 12 +#endif +#define Y2_GPIO_NUM 14 +#define VSYNC_GPIO_NUM 38 +#define HREF_GPIO_NUM 4 +#define PCLK_GPIO_NUM 3 + +#elif defined(CAMERA_MODEL_ESP32S3_EYE) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 15 +#define SIOD_GPIO_NUM 4 +#define SIOC_GPIO_NUM 5 + +#define Y2_GPIO_NUM 11 +#define Y3_GPIO_NUM 9 +#define Y4_GPIO_NUM 8 +#define Y5_GPIO_NUM 10 +#define Y6_GPIO_NUM 12 +#define Y7_GPIO_NUM 18 +#define Y8_GPIO_NUM 17 +#define Y9_GPIO_NUM 16 + +#define VSYNC_GPIO_NUM 6 +#define HREF_GPIO_NUM 7 +#define PCLK_GPIO_NUM 13 + +#elif defined(CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3) || defined(CAMERA_MODEL_DFRobot_Romeo_ESP32S3) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 45 +#define SIOD_GPIO_NUM 1 +#define SIOC_GPIO_NUM 2 + +#define Y9_GPIO_NUM 48 +#define Y8_GPIO_NUM 46 +#define Y7_GPIO_NUM 8 +#define Y6_GPIO_NUM 7 +#define Y5_GPIO_NUM 4 +#define Y4_GPIO_NUM 41 +#define Y3_GPIO_NUM 40 +#define Y2_GPIO_NUM 39 +#define VSYNC_GPIO_NUM 6 +#define HREF_GPIO_NUM 42 +#define PCLK_GPIO_NUM 5 + +#else +#error "Camera model not selected" +#endif \ No newline at end of file diff --git a/examples/Camera/motion-capture/motion-capture.ino b/examples/Camera/motion-capture/motion-capture.ino new file mode 100644 index 0000000..77fc12e --- /dev/null +++ b/examples/Camera/motion-capture/motion-capture.ino @@ -0,0 +1,367 @@ +/* + * Example for ESP32 Camera Motion Detection System: + * - Create a ESP32 Camera device from portal. + * - Copy the secrets below. + * - Update WiFi settings + * + * If you encounter any issues: + * - check the readme.md at https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md + * - ensure all dependent libraries are installed + * - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#arduinoide + * - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#dependencies + * - open serial monitor and check whats happening + * - check full user documentation at https://sinricpro.github.io/esp8266-esp32-sdk + * - visit https://github.com/sinricpro/esp8266-esp32-sdk/issues and check for existing issues or open a new one + */ + +// Uncomment the following line to enable serial debug output +#define ENABLE_DEBUG + +#include +#include +#include +#include +#include +#include +#include "esp_http_client.h" +#include "HTTPClient.h" +#include + +// =================== +// Select camera model +// =================== +// #define CAMERA_MODEL_WROVER_KIT // Has PSRAM + #define CAMERA_MODEL_ESP_EYE // Has PSRAM +// #define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM +// #define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM +// #define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM +// #define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM +// #define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM +// #define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM +// #define CAMERA_MODEL_M5STACK_CAMS3_UNIT // Has PSRAM +// #define CAMERA_MODEL_AI_THINKER // Has PSRAM +// #define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM +// #define CAMERA_MODEL_TTGO_T_V16_VERSION +// #define CAMERA_MODEL_TTGO_T_V05_VERSION +// #define CAMERA_MODEL_TTGO_T_PLUS_VERSION +// #define CAMERA_MODEL_TTGO_T_V162_VERSION +// #define CAMERA_MODEL_TTGO_T_MINI_VERSION +// #define CAMERA_MODEL_TTGO_T_V17_VERSION +// #define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM +// ** Espressif Internal Boards ** +// #define CAMERA_MODEL_ESP32_CAM_BOARD +// #define CAMERA_MODEL_ESP32S2_CAM_BOARD +// #define CAMERA_MODEL_ESP32S3_CAM_LCD +// #define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM +// #define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM +#include "camera_pins.h" + +#define MOTION_SENSOR_PIN 5 // GPIO pin connected to PIR motion sensor +#define FRAME_CAPTURE_COUNT 10 // Number of frames to capture when motion is detected +#define FRAME_CAPTURE_DELAY_MS 200 // Delay between frame captures (milliseconds) +#define MOTION_DEBOUNCE_DELAY 250 // Debounce delay for motion sensor (milliseconds) +#define TEMP_FILE_PATH "/mjpeg.tmp" // Temporary file path in SPIFFS for storing frames + +#define WIFI_SSID "" // Your WiFi network SSID +#define WIFI_PASS "" // Your WiFi network password +#define APP_KEY "" // SinricPro APP_KEY +#define APP_SECRET "" // SinricPro APP_SECRET +#define CAMERA_ID "" // SinricPro CAMERA_ID + +bool lastMotionState = false; // Last recorded state of the motion sensor +unsigned long lastChangeTime = 0; // Timestamp of last motion state change +unsigned long lastSendTime = 0; // Timestamp of last successful motion data send +const unsigned long SEND_COOLDOWN = 60000; // Minimum time between sends (60 seconds) + +/** + * Initializes the SPIFFS file system + */ +bool initFS() { + if (!SPIFFS.begin(true)) { + Serial.println("SPIFFS initialization failed!"); + return false; + } + return true; +} + +/** + * Initializes the camera with the specified configuration + * + * @return bool True if initialization successful, false otherwise + */ +bool initCamera() { + camera_config_t config; + + // Basic pin configuration + 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_sccb_sda = SIOD_GPIO_NUM; + config.pin_sccb_scl = SIOC_GPIO_NUM; + config.pin_pwdn = PWDN_GPIO_NUM; + config.pin_reset = RESET_GPIO_NUM; + + // Camera settings + config.xclk_freq_hz = 20000000; + config.pixel_format = PIXFORMAT_JPEG; + config.frame_size = FRAMESIZE_SVGA; + config.grab_mode = CAMERA_GRAB_LATEST; + config.jpeg_quality = 12; + + // Adjust settings based on PSRAM availability + if (psramFound()) { + config.fb_count = 2; + config.fb_location = CAMERA_FB_IN_PSRAM; + } else { + config.fb_count = 1; + config.frame_size = FRAMESIZE_SVGA; + config.fb_location = CAMERA_FB_IN_DRAM; + } + +#if defined(CAMERA_MODEL_ESP_EYE) + pinMode(13, INPUT_PULLUP); + pinMode(14, INPUT_PULLUP); +#endif + + // camera init + esp_err_t err = esp_camera_init(&config); + if (err != ESP_OK) { + Serial.printf("Camera init failed with error 0x%x", err); + return false; + } + + sensor_t* s = esp_camera_sensor_get(); + // initial sensors are flipped vertically and colors are a bit saturated + if (s->id.PID == OV3660_PID) { + s->set_vflip(s, 1); // flip it back + s->set_brightness(s, 1); // up the brightness just a bit + s->set_saturation(s, -2); // lower the saturation + } + +#if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM) + s->set_vflip(s, 1); + s->set_hmirror(s, 1); +#endif + +#if defined(CAMERA_MODEL_ESP32S3_EYE) + s->set_vflip(s, 1); +#endif + + return true; +} + +/** + * Sets up WiFi connection + */ +void setupWiFi() { + Serial.print("\nConnecting to WiFi"); + + WiFi.begin(WIFI_SSID, WIFI_PASS); + WiFi.setSleep(false); // Disable WiFi sleep mode for better performance + + // Wait for connection + while (WiFi.status() != WL_CONNECTED) { + Serial.print("."); + delay(250); + } + + Serial.printf("\nWiFi connected! IP address: %s\n", + WiFi.localIP().toString().c_str()); +} + +/** + * Sets up SinricPro connection and event handlers + */ +void setupSinricPro() { + SinricProCamera& camera = SinricPro[CAMERA_ID]; + + // Setup power state callback + camera.onPowerState([](const String& deviceId, bool& state) { + return true; + }); + + camera.onSnapshot([](const String& deviceId) { + camera_fb_t *fb = esp_camera_fb_get(); + + if (!fb) { + Serial.println("Failed to grab image"); + return false; + } + + SinricProCamera &myCamera = SinricPro[CAMERA_ID]; + int result = myCamera.sendSnapshot(fb->buf, fb->len); + esp_camera_fb_return(fb); + return result == 200; + }); + + // Setup connection event handlers + SinricPro.onConnected([]() { + Serial.println("Connected to SinricPro"); + }); + + SinricPro.onDisconnected([]() { + Serial.println("Disconnected from SinricPro"); + }); + + // Start SinricPro + //SinricPro.begin(APP_KEY, APP_SECRET); + SinricPro.begin(APP_KEY, APP_SECRET, "testws.sinric.pro"); +} + +/** + * Captures multiple frames from the camera and writes them to file + * + * @param file Reference to opened file for writing frames + * @return size_t Total size of captured frames in bytes + */ +bool captureFrames(File& file) { + size_t totalSize = 0; + unsigned long startTime = millis(); + + for (int i = 0; i < FRAME_CAPTURE_COUNT; i++) { + // Get frame from camera + camera_fb_t* fb = esp_camera_fb_get(); + if (!fb) { + Serial.println("Camera capture failed"); + continue; + } + + // Write frame to file + if (file.write(fb->buf, fb->len)) { + totalSize += fb->len; + Serial.printf("Frame %d saved, size: %d bytes\n", i + 1, fb->len); + } else { + Serial.println("Failed to write frame"); + } + + // Return frame buffer to be reused + esp_camera_fb_return(fb); + delay(FRAME_CAPTURE_DELAY_MS); + } + + Serial.printf("Motion capture completed in %lu ms\n", millis() - startTime); + Serial.printf("Motion file size: %d\n", totalSize); + return totalSize > 0; +} + +/** + * Sends captured motion data to SinricPro server + * Handles different response codes from the server + */ +void sendMotionToServer() { + SinricProCamera& camera = SinricPro[CAMERA_ID]; + int responseCode = camera.sendMotion(SPIFFS, TEMP_FILE_PATH); + + // Handle different response codes + switch (responseCode) { + case 200: + Serial.println("Motion data sent successfully"); + break; + case 413: + Serial.println("Error: File exceeds maximum allowed size"); + break; + case 429: + Serial.println("Error: Rate limit exceeded"); + break; + default: + Serial.printf("Error: Send failed with code %d\n", responseCode); + break; + } +} + +/** + * Captures frames when motion is detected and sends them to server + * Handles temporary file creation and cleanup + */ +void captureAndSendMotion() { + // Check if enough time has passed since last send + unsigned long currentTime = millis(); + if (currentTime - lastSendTime < SEND_COOLDOWN) { + Serial.println("Motion detected but skipping - cooldown period active"); + return; + } + + // Open temporary file for writing frames + File mjpegFile = SPIFFS.open(TEMP_FILE_PATH, FILE_WRITE); + if (!mjpegFile) { + Serial.println("Failed to open temporary file for writing"); + return; + } + + // Capture frames and send if successful + bool captured = captureFrames(mjpegFile); + mjpegFile.close(); + + if (captured) { + sendMotionToServer(); + } + + // Cleanup temporary file + SPIFFS.remove(TEMP_FILE_PATH); +} + +/** + * Handles motion sensor state changes + * Implements debouncing and triggers capture when motion is detected + */ +void handleMotionSensor() { + unsigned long currentTime = millis(); + // Check debounce period + if (currentTime - lastChangeTime < MOTION_DEBOUNCE_DELAY) return; + + // Read current motion state + bool currentMotionState = digitalRead(MOTION_SENSOR_PIN); + if (currentMotionState != lastMotionState) { + Serial.printf("Motion %s\n", currentMotionState ? "detected" : "not detected"); + lastMotionState = currentMotionState; + lastChangeTime = currentTime; + + // Trigger capture on motion detection + if (currentMotionState) { + captureAndSendMotion(); + } + } +} + +bool onPowerState(const String& deviceId, bool& state) { + return true; +} + +/** + * Setup function - initializes all components + */ +void setup() { + Serial.begin(115200); + + // Initialize systems + if (!initFS()) { + Serial.println("File system initialization failed!"); + return; + } + + pinMode(MOTION_SENSOR_PIN, INPUT); + + if (!initCamera()) { + Serial.println("Camera initialization failed!"); + return; + } + + setupWiFi(); + setupSinricPro(); +} + +void loop() { + SinricPro.handle(); + handleMotionSensor(); +} diff --git a/examples/Camera/snapshot-camera/camera_pins.h b/examples/Camera/snapshot-camera/camera_pins.h index a007ffd..dbb01e3 100644 --- a/examples/Camera/snapshot-camera/camera_pins.h +++ b/examples/Camera/snapshot-camera/camera_pins.h @@ -198,6 +198,231 @@ #define HREF_GPIO_NUM 26 #define PCLK_GPIO_NUM 21 +#elif defined(CAMERA_MODEL_TTGO_T_V16_VERSION) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 4 +#define SIOD_GPIO_NUM 18 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 15 +#define Y7_GPIO_NUM 12 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 35 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 13 +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 + +#define AS312_PIN 19 +#define BUTTON_1 0 + +#define I2C_SDA 21 +#define I2C_SCL 22 + +#define SSD130_MODLE_TYPE 0 // 0 : GEOMETRY_128_64 // 1: GEOMETRY_128_32 + +#define IIS_SCK 26 +#define IIS_WS 32 +#define IIS_DOUT 33 + +#elif defined(CAMERA_MODEL_TTGO_T_V05_VERSION) + +#define PWDN_GPIO_NUM 26 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 32 +#define SIOD_GPIO_NUM 13 +#define SIOC_GPIO_NUM 12 + +#define Y9_GPIO_NUM 39 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 23 +#define Y6_GPIO_NUM 18 +#define Y5_GPIO_NUM 15 +#define Y4_GPIO_NUM 4 +#define Y3_GPIO_NUM 14 +#define Y2_GPIO_NUM 5 + +#define VSYNC_GPIO_NUM 27 +#define HREF_GPIO_NUM 25 +#define PCLK_GPIO_NUM 19 + +#define AS312_PIN 33 +#define BUTTON_1 34 + +#define I2C_SDA 21 +#define I2C_SCL 22 + +#define SSD130_MODLE_TYPE 0 // 0 : GEOMETRY_128_64 // 1: GEOMETRY_128_32 + + +#elif defined(CAMERA_MODEL_TTGO_T_JORNAL_VERSION) + +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 17 + +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#define I2C_SDA 14 +#define I2C_SCL 13 + +#define BUTTON_1 32 + +#define SSD130_MODLE_TYPE 1 // 0 : GEOMETRY_128_64 // 1: GEOMETRY_128_32 + +#elif defined(CAMERA_MODEL_TTGO_T_PLUS_VERSION) +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 4 +#define SIOD_GPIO_NUM 18 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 37 +#define Y7_GPIO_NUM 38 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 35 +#define Y4_GPIO_NUM 26 +#define Y3_GPIO_NUM 13 +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 + +#define I2C_SDA 18 +#define I2C_SCL 23 + +#define IIS_SCK 14 +#define IIS_WS 32 +#define IIS_DOUT 33 + +#define TFT_CS_PIN 12 +#define TFT_DC_PIN 15 +#define TFT_MOSI_PIN 19 +#define TFT_MISO_PIN 22 +#define TFT_SCLK_PIN 21 +#define TFT_BL_PIN 2 + +#define SDCARD_CS_PIN 0 + +#define ENABLE_IP5306 +#define ENABLE_TFT + +#elif defined(CAMERA_MODEL_TTGO_T_V162_VERSION) + +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 4 +#define SIOD_GPIO_NUM 18 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 37 +#define Y7_GPIO_NUM 38 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 35 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 13 +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 + +#define I2C_SDA 21 +#define I2C_SCL 22 + +#define BUTTON_1 15 + +#define SSD130_MODLE_TYPE 0 // 0 : GEOMETRY_128_64 // 1: GEOMETRY_128_32 + +#define AS312_PIN 19 //not rtc io ,can't form deepsleep wakeup + +#define IIS_SCK 26 +#define IIS_WS 32 +#define IIS_DOUT 33 + +#define ENABLE_IP5306 + +#elif defined(CAMERA_MODEL_TTGO_T_MINI_VERSION) + +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 32 +#define SIOD_GPIO_NUM 13 +#define SIOC_GPIO_NUM 12 + +#define Y9_GPIO_NUM 39 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 38 +#define Y6_GPIO_NUM 37 +#define Y5_GPIO_NUM 15 +#define Y4_GPIO_NUM 4 +#define Y3_GPIO_NUM 14 +#define Y2_GPIO_NUM 5 + +#define VSYNC_GPIO_NUM 27 +#define HREF_GPIO_NUM 25 +#define PCLK_GPIO_NUM 19 +#define CAMERA_PWR_PIN 26 + +#define I2C_SDA 21 +#define I2C_SCL 22 + +#define BUTTON_1 33 + +#define POWER_CONTROL_PIN 26 + +#define ENABLE_AXP192 + +#elif defined(CAMERA_MODEL_TTGO_T_V17_VERSION) + +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 32 +#define SIOD_GPIO_NUM 13 +#define SIOC_GPIO_NUM 12 + +#define Y9_GPIO_NUM 39 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 23 +#define Y6_GPIO_NUM 18 +#define Y5_GPIO_NUM 15 +#define Y4_GPIO_NUM 4 +#define Y3_GPIO_NUM 14 +#define Y2_GPIO_NUM 5 + +#define VSYNC_GPIO_NUM 27 +#define HREF_GPIO_NUM 25 +#define PCLK_GPIO_NUM 19 + +#define I2C_SDA 21 +#define I2C_SCL 22 + +#define BUTTON_1 34 + +#define SSD130_MODLE_TYPE 0 // 0 : GEOMETRY_128_64 // 1: GEOMETRY_128_32 + +#define AS312_PIN 33 + +#define ENABLE_IP5306 + #elif defined(CAMERA_MODEL_XIAO_ESP32S3) #define PWDN_GPIO_NUM -1 #define RESET_GPIO_NUM -1 diff --git a/examples/Camera/snapshot-camera/snapshot-camera.ino b/examples/Camera/snapshot-camera/snapshot-camera.ino index a146d7a..d457c69 100644 --- a/examples/Camera/snapshot-camera/snapshot-camera.ino +++ b/examples/Camera/snapshot-camera/snapshot-camera.ino @@ -27,7 +27,7 @@ // Select camera model // =================== // #define CAMERA_MODEL_WROVER_KIT // Has PSRAM -// #define CAMERA_MODEL_ESP_EYE // Has PSRAM + #define CAMERA_MODEL_ESP_EYE // Has PSRAM // #define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM // #define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM // #define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM @@ -37,6 +37,12 @@ // #define CAMERA_MODEL_M5STACK_CAMS3_UNIT // Has PSRAM // #define CAMERA_MODEL_AI_THINKER // Has PSRAM // #define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM +// #define CAMERA_MODEL_TTGO_T_V16_VERSION +// #define CAMERA_MODEL_TTGO_T_V05_VERSION +// #define CAMERA_MODEL_TTGO_T_PLUS_VERSION +// #define CAMERA_MODEL_TTGO_T_V162_VERSION +// #define CAMERA_MODEL_TTGO_T_MINI_VERSION +// #define CAMERA_MODEL_TTGO_T_V17_VERSION // #define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM // ** Espressif Internal Boards ** // #define CAMERA_MODEL_ESP32_CAM_BOARD @@ -46,11 +52,12 @@ // #define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM #include "camera_pins.h" -#define WIFI_SSID "YOUR-WIFI-SSID" -#define WIFI_PASS "YOUR-WIFI-PASSWORD" -#define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx" -#define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx" -#define CAMERA_ID "YOUR-ESP32-CAMERA-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx" +#define WIFI_SSID "" // Your WiFi network SSID +#define WIFI_PASS "" // Your WiFi network password + +#define APP_KEY "" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx" +#define APP_SECRET "" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx" +#define CAMERA_ID "" // Should look like "5dc1564130xxxxxxxxxxxxxx" #define BAUD_RATE 115200 // Change baudrate to your need @@ -63,9 +70,25 @@ bool onSnapshot(const String &deviceId) { } SinricProCamera &myCamera = SinricPro[deviceId]; - int result = myCamera.sendSnapshot(fb->buf, fb->len); - esp_camera_fb_return(fb); + int responseCode = myCamera.sendSnapshot(fb->buf, fb->len); + + // Handle different response codes + switch (responseCode) { + case 200: + Serial.println("Snapshot sent successfully"); + break; + case 413: + Serial.println("Error: File exceeds maximum allowed size"); + break; + case 429: + Serial.println("Error: Rate limit exceeded"); + break; + default: + Serial.printf("Error: Send failed with code %d\n", responseCode); + break; + } + esp_camera_fb_return(fb); return result == 200; } @@ -124,7 +147,6 @@ void setupCamera() { config.xclk_freq_hz = 20000000; config.frame_size = FRAMESIZE_XGA; config.pixel_format = PIXFORMAT_JPEG; // do not change! - // config.pixel_format = PIXFORMAT_RGB565; // for face detection/recognition config.grab_mode = CAMERA_GRAB_WHEN_EMPTY; config.fb_location = CAMERA_FB_IN_PSRAM; config.jpeg_quality = 12; @@ -133,7 +155,7 @@ void setupCamera() { if (psramFound()) { config.jpeg_quality = 10; config.fb_count = 2; - config.grab_mode = CAMERA_GRAB_LATEST; + config.grab_mode = CAMERA_GRAB_LATEST; } else { // Limit the frame size when PSRAM is not available config.frame_size = FRAMESIZE_SVGA; @@ -172,9 +194,6 @@ void setupCamera() { void setup() { Serial.begin(BAUD_RATE); - Serial.setDebugOutput(true); - Serial.println(); - delay(1500); setupCamera(); setupWiFi(); diff --git a/src/Capabilities/CameraController.h b/src/Capabilities/CameraController.h index 924a336..050b9bb 100644 --- a/src/Capabilities/CameraController.h +++ b/src/Capabilities/CameraController.h @@ -1,24 +1,27 @@ #pragma once -// Required header includes -#include "../EventLimiter.h" -#include "../SinricProNamespace.h" #include "../SinricProRequest.h" + +#include "../EventLimiter.h" #include "../SinricProStrings.h" -#include +#include "../SinricProNamespace.h" -#if defined(ESP32) +#include + +#if defined(ESP32) + #include #include #endif namespace SINRICPRO_NAMESPACE { FSTR(CAMERA, getSnapshot); // "getSnapshot" +FSTR(CAMERA, POST); // "POST" using SnapshotCallback = std::function; /** - * @brief Camera + * @brief CameraController class for managing camera operations in SinricPro * @ingroup Capabilities **/ template @@ -36,10 +39,19 @@ class CameraController { * @brief Sends a camera snapshot to the SinricPro server * @param buffer Pointer to the image data buffer * @param len Length of the image data in bytes - * @return HTTP response code + * @return error code */ int sendSnapshot(uint8_t* buffer, size_t len); + /** + * @brief Sends motion detection data from file + * @param fs Filesystem containing the motion data + * @param path Path to motion data file + * @return error code + */ + int sendMotion(fs::FS &fs, const char * path); + + protected: /** * @brief Handles incoming camera control requests @@ -49,12 +61,45 @@ class CameraController { bool handleCameraController(SinricProRequest &request); private: - // Callback handler for snapshot requests SnapshotCallback getSnapshotCallback = nullptr; + EventLimiter event_limiter; + +#if defined(ESP32) + std::unique_ptr createClient() { +#ifdef SINRICPRO_NOSSL + auto client = std::make_unique(); +#else + auto client = std::make_unique(); + client->setInsecure(); +#endif + if (client) client->setTimeout(TCP_CONNECTION_TIMEOUT_VALUE); + return client; + } + + bool setupHttpConnection(HTTPClient& http, WiFiClient* client, const char* path) { +#ifdef SINRICPRO_NOSSL + return http.begin(*client, SINRICPRO_CAMERA_URL, 80, path, false); +#else + return http.begin(*client, SINRICPRO_CAMERA_URL, 443, path, true); +#endif + } + + void setupHttpHeaders(HTTPClient& http, T* device) { + const String& deviceId = device->getDeviceId(); + String createdAt = String(device->getTimestamp()); + String signature = device->sign(deviceId + createdAt); + + http.addHeader(FSTR_SINRICPRO_deviceId, deviceId); + http.addHeader(FSTR_SINRICPRO_createdAt, createdAt); + http.addHeader(FSTR_SINRICPRO_signature, signature); + http.setTimeout(HTTP_TIMEOUT_VALUE); + } +#endif }; template -CameraController::CameraController() { +CameraController::CameraController() +: event_limiter (EVENT_LIMIT_STATE) { T *device = static_cast(this); device->registerRequestHandler(std::bind(&CameraController::handleCameraController, this, std::placeholders::_1)); } @@ -66,6 +111,7 @@ void CameraController::onSnapshot(SnapshotCallback cb) { template bool CameraController::handleCameraController(SinricProRequest &request) { + if (event_limiter) return false; T *device = static_cast(this); bool success = false; @@ -80,46 +126,60 @@ bool CameraController::handleCameraController(SinricProRequest &request) { template int CameraController::sendSnapshot(uint8_t* buffer, size_t len) { - int resCode = -1; - + #if defined(ESP32) - T* device = static_cast(this); - - if (!buffer) return resCode; + if (!buffer || len == 0) return -1; + T* device = static_cast(this); HTTPClient http; - bool beginSuccess = false; + auto client = createClient(); + + if (!setupHttpConnection(http, client.get(), SINRICPRO_CAMERA_API_SNAPSHOT_PATH)) { + http.end(); + return -1; + } -#ifdef SINRICPRO_NOSSL - std::unique_ptr client = std::make_unique(); - if (!client) return resCode; - beginSuccess = http.begin(*client, SINRICPRO_CAMERA_URL, 80, SINRICPRO_CAMERA_PATH, false); + setupHttpHeaders(http, device); + + int resCode = http.POST(buffer, len); + http.end(); + + return resCode; #else - std::unique_ptr secureClient = std::make_unique(); - if (!secureClient) return resCode; - secureClient->setInsecure(); - beginSuccess = http.begin(*secureClient, SINRICPRO_CAMERA_URL, 443, SINRICPRO_CAMERA_PATH, true); -#endif + return -1; +#endif +} + +template +int CameraController::sendMotion(fs::FS &fs, const char * path) { + +#if defined(ESP32) + File file = fs.open(path); + if (!file) return -1; - if (!beginSuccess) { + T* device = static_cast(this); + HTTPClient http; + auto client = createClient(); + + if (!setupHttpConnection(http, client.get(), SINRICPRO_CAMERA_API_MOTION_PATH)) { http.end(); - return resCode; + return -1; } - const String& deviceId = device->getDeviceId(); - String createdAt = String(device->getTimestamp()); - String signature = device->sign(deviceId + createdAt); - - http.addHeader(FSTR_SINRICPRO_deviceId, deviceId); - http.addHeader(FSTR_SINRICPRO_createdAt, createdAt); - http.addHeader(FSTR_SINRICPRO_signature, signature); + setupHttpHeaders(http, device); - resCode = http.POST(buffer, len); + int resCode = http.sendRequest(FSTR_CAMERA_POST, &file, file.size()); + + file.close(); http.end(); -#endif return resCode; +#else + return -1; +#endif } +} // namespace SINRICPRO_NAMESPACE -} // namespace SINRICPRO_NAMESPACE \ No newline at end of file +template +using CameraController = SINRICPRO_NAMESPACE::CameraController; \ No newline at end of file diff --git a/src/SinricProCamera.h b/src/SinricProCamera.h index cc85494..cb19a5f 100644 --- a/src/SinricProCamera.h +++ b/src/SinricProCamera.h @@ -18,7 +18,7 @@ namespace SINRICPRO_NAMESPACE { /** * @class SinricProCamera - * @brief Camera suporting basic on / off command + * @brief Camera suporting snapshots, motions and on / off commands * @ingroup Devices **/ class SinricProCamera : public SinricProDevice, diff --git a/src/SinricProConfig.h b/src/SinricProConfig.h index c50d005..2a36d14 100644 --- a/src/SinricProConfig.h +++ b/src/SinricProConfig.h @@ -41,8 +41,12 @@ #define SINRICPRO_CAMERA_URL "camera.sinric.pro" #endif -#ifndef SINRICPRO_CAMERA_PATH -#define SINRICPRO_CAMERA_PATH "/snapshot" +#ifndef SINRICPRO_CAMERA_API_SNAPSHOT_PATH +#define SINRICPRO_CAMERA_API_SNAPSHOT_PATH "/snapshot" +#endif + +#ifndef SINRICPRO_CAMERA_API_MOTION_PATH +#define SINRICPRO_CAMERA_API_MOTION_PATH "/motion-capture" #endif // UDP Configuration @@ -75,3 +79,12 @@ #ifndef EVENT_LIMIT_SENSOR_VALUE #define EVENT_LIMIT_SENSOR_VALUE 60000 #endif + +// Used when making a HTTP request in API +#ifndef TCP_CONNECTION_TIMEOUT_VALUE +#define TCP_CONNECTION_TIMEOUT_VALUE 5000 +#endif + +#ifndef HTTP_TIMEOUT_VALUE +#define HTTP_TIMEOUT_VALUE 10000 +#endif From 87c88ca5fb2b13eeac9165df233e991fce3b4805 Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Sun, 5 Jan 2025 09:11:30 +0700 Subject: [PATCH 07/18] fix: url --- examples/Camera/motion-capture/motion-capture.ino | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/Camera/motion-capture/motion-capture.ino b/examples/Camera/motion-capture/motion-capture.ino index 77fc12e..5cbf761 100644 --- a/examples/Camera/motion-capture/motion-capture.ino +++ b/examples/Camera/motion-capture/motion-capture.ino @@ -215,8 +215,7 @@ void setupSinricPro() { }); // Start SinricPro - //SinricPro.begin(APP_KEY, APP_SECRET); - SinricPro.begin(APP_KEY, APP_SECRET, "testws.sinric.pro"); + SinricPro.begin(APP_KEY, APP_SECRET); } /** From 3651614b634fd6b592c2e9ed58d468465fe43a57 Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Sun, 5 Jan 2025 09:13:10 +0700 Subject: [PATCH 08/18] fix: comment --- src/SinricProConfig.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SinricProConfig.h b/src/SinricProConfig.h index 2a36d14..12fbe08 100644 --- a/src/SinricProConfig.h +++ b/src/SinricProConfig.h @@ -80,7 +80,7 @@ #define EVENT_LIMIT_SENSOR_VALUE 60000 #endif -// Used when making a HTTP request in API +// For HTTP API requests #ifndef TCP_CONNECTION_TIMEOUT_VALUE #define TCP_CONNECTION_TIMEOUT_VALUE 5000 #endif From 44a6c6f50960cd19a00487515c14546543cacfed Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Sun, 5 Jan 2025 09:14:09 +0700 Subject: [PATCH 09/18] fix: remove incorrect example --- .../motion-snapshot-capture/camera_pins.h | 563 ------------------ .../motion-snapshot-capture.ino | 300 ---------- .../motion_detector.cpp | 139 ----- .../motion-snapshot-capture/motion_detector.h | 35 -- 4 files changed, 1037 deletions(-) delete mode 100644 examples/Camera/motion-snapshot-capture/camera_pins.h delete mode 100644 examples/Camera/motion-snapshot-capture/motion-snapshot-capture.ino delete mode 100644 examples/Camera/motion-snapshot-capture/motion_detector.cpp delete mode 100644 examples/Camera/motion-snapshot-capture/motion_detector.h diff --git a/examples/Camera/motion-snapshot-capture/camera_pins.h b/examples/Camera/motion-snapshot-capture/camera_pins.h deleted file mode 100644 index dbb01e3..0000000 --- a/examples/Camera/motion-snapshot-capture/camera_pins.h +++ /dev/null @@ -1,563 +0,0 @@ - -#if defined(CAMERA_MODEL_WROVER_KIT) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 21 -#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 19 -#define Y4_GPIO_NUM 18 -#define Y3_GPIO_NUM 5 -#define Y2_GPIO_NUM 4 -#define VSYNC_GPIO_NUM 25 -#define HREF_GPIO_NUM 23 -#define PCLK_GPIO_NUM 22 - -#elif defined(CAMERA_MODEL_ESP_EYE) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 4 -#define SIOD_GPIO_NUM 18 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 36 -#define Y8_GPIO_NUM 37 -#define Y7_GPIO_NUM 38 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 35 -#define Y4_GPIO_NUM 14 -#define Y3_GPIO_NUM 13 -#define Y2_GPIO_NUM 34 -#define VSYNC_GPIO_NUM 5 -#define HREF_GPIO_NUM 27 -#define PCLK_GPIO_NUM 25 - -#define LED_GPIO_NUM 22 - -#elif defined(CAMERA_MODEL_M5STACK_PSRAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 - -#elif defined(CAMERA_MODEL_M5STACK_V2_PSRAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 22 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 25 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 - -#elif defined(CAMERA_MODEL_M5STACK_WIDE) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 22 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 25 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 - -#define LED_GPIO_NUM 2 - -#elif defined(CAMERA_MODEL_M5STACK_ESP32CAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 17 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 - -#elif defined(CAMERA_MODEL_M5STACK_UNITCAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 - -#elif defined(CAMERA_MODEL_M5STACK_CAMS3_UNIT) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 21 -#define XCLK_GPIO_NUM 11 -#define SIOD_GPIO_NUM 17 -#define SIOC_GPIO_NUM 41 - -#define Y9_GPIO_NUM 13 -#define Y8_GPIO_NUM 4 -#define Y7_GPIO_NUM 10 -#define Y6_GPIO_NUM 5 -#define Y5_GPIO_NUM 7 -#define Y4_GPIO_NUM 16 -#define Y3_GPIO_NUM 15 -#define Y2_GPIO_NUM 6 -#define VSYNC_GPIO_NUM 42 -#define HREF_GPIO_NUM 18 -#define PCLK_GPIO_NUM 12 - -#define LED_GPIO_NUM 14 - -#elif defined(CAMERA_MODEL_AI_THINKER) -#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 - -// 4 for flash led or 33 for normal led -#define LED_GPIO_NUM 4 - -#elif defined(CAMERA_MODEL_TTGO_T_JOURNAL) -#define PWDN_GPIO_NUM 0 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 17 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 - -#elif defined(CAMERA_MODEL_TTGO_T_V16_VERSION) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 4 -#define SIOD_GPIO_NUM 18 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 36 -#define Y8_GPIO_NUM 15 -#define Y7_GPIO_NUM 12 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 35 -#define Y4_GPIO_NUM 14 -#define Y3_GPIO_NUM 13 -#define Y2_GPIO_NUM 34 -#define VSYNC_GPIO_NUM 5 -#define HREF_GPIO_NUM 27 -#define PCLK_GPIO_NUM 25 - -#define AS312_PIN 19 -#define BUTTON_1 0 - -#define I2C_SDA 21 -#define I2C_SCL 22 - -#define SSD130_MODLE_TYPE 0 // 0 : GEOMETRY_128_64 // 1: GEOMETRY_128_32 - -#define IIS_SCK 26 -#define IIS_WS 32 -#define IIS_DOUT 33 - -#elif defined(CAMERA_MODEL_TTGO_T_V05_VERSION) - -#define PWDN_GPIO_NUM 26 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 32 -#define SIOD_GPIO_NUM 13 -#define SIOC_GPIO_NUM 12 - -#define Y9_GPIO_NUM 39 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 23 -#define Y6_GPIO_NUM 18 -#define Y5_GPIO_NUM 15 -#define Y4_GPIO_NUM 4 -#define Y3_GPIO_NUM 14 -#define Y2_GPIO_NUM 5 - -#define VSYNC_GPIO_NUM 27 -#define HREF_GPIO_NUM 25 -#define PCLK_GPIO_NUM 19 - -#define AS312_PIN 33 -#define BUTTON_1 34 - -#define I2C_SDA 21 -#define I2C_SCL 22 - -#define SSD130_MODLE_TYPE 0 // 0 : GEOMETRY_128_64 // 1: GEOMETRY_128_32 - - -#elif defined(CAMERA_MODEL_TTGO_T_JORNAL_VERSION) - -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 17 - -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 - -#define I2C_SDA 14 -#define I2C_SCL 13 - -#define BUTTON_1 32 - -#define SSD130_MODLE_TYPE 1 // 0 : GEOMETRY_128_64 // 1: GEOMETRY_128_32 - -#elif defined(CAMERA_MODEL_TTGO_T_PLUS_VERSION) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 4 -#define SIOD_GPIO_NUM 18 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 36 -#define Y8_GPIO_NUM 37 -#define Y7_GPIO_NUM 38 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 35 -#define Y4_GPIO_NUM 26 -#define Y3_GPIO_NUM 13 -#define Y2_GPIO_NUM 34 -#define VSYNC_GPIO_NUM 5 -#define HREF_GPIO_NUM 27 -#define PCLK_GPIO_NUM 25 - -#define I2C_SDA 18 -#define I2C_SCL 23 - -#define IIS_SCK 14 -#define IIS_WS 32 -#define IIS_DOUT 33 - -#define TFT_CS_PIN 12 -#define TFT_DC_PIN 15 -#define TFT_MOSI_PIN 19 -#define TFT_MISO_PIN 22 -#define TFT_SCLK_PIN 21 -#define TFT_BL_PIN 2 - -#define SDCARD_CS_PIN 0 - -#define ENABLE_IP5306 -#define ENABLE_TFT - -#elif defined(CAMERA_MODEL_TTGO_T_V162_VERSION) - -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 4 -#define SIOD_GPIO_NUM 18 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 36 -#define Y8_GPIO_NUM 37 -#define Y7_GPIO_NUM 38 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 35 -#define Y4_GPIO_NUM 14 -#define Y3_GPIO_NUM 13 -#define Y2_GPIO_NUM 34 -#define VSYNC_GPIO_NUM 5 -#define HREF_GPIO_NUM 27 -#define PCLK_GPIO_NUM 25 - -#define I2C_SDA 21 -#define I2C_SCL 22 - -#define BUTTON_1 15 - -#define SSD130_MODLE_TYPE 0 // 0 : GEOMETRY_128_64 // 1: GEOMETRY_128_32 - -#define AS312_PIN 19 //not rtc io ,can't form deepsleep wakeup - -#define IIS_SCK 26 -#define IIS_WS 32 -#define IIS_DOUT 33 - -#define ENABLE_IP5306 - -#elif defined(CAMERA_MODEL_TTGO_T_MINI_VERSION) - -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 32 -#define SIOD_GPIO_NUM 13 -#define SIOC_GPIO_NUM 12 - -#define Y9_GPIO_NUM 39 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 38 -#define Y6_GPIO_NUM 37 -#define Y5_GPIO_NUM 15 -#define Y4_GPIO_NUM 4 -#define Y3_GPIO_NUM 14 -#define Y2_GPIO_NUM 5 - -#define VSYNC_GPIO_NUM 27 -#define HREF_GPIO_NUM 25 -#define PCLK_GPIO_NUM 19 -#define CAMERA_PWR_PIN 26 - -#define I2C_SDA 21 -#define I2C_SCL 22 - -#define BUTTON_1 33 - -#define POWER_CONTROL_PIN 26 - -#define ENABLE_AXP192 - -#elif defined(CAMERA_MODEL_TTGO_T_V17_VERSION) - -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 32 -#define SIOD_GPIO_NUM 13 -#define SIOC_GPIO_NUM 12 - -#define Y9_GPIO_NUM 39 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 23 -#define Y6_GPIO_NUM 18 -#define Y5_GPIO_NUM 15 -#define Y4_GPIO_NUM 4 -#define Y3_GPIO_NUM 14 -#define Y2_GPIO_NUM 5 - -#define VSYNC_GPIO_NUM 27 -#define HREF_GPIO_NUM 25 -#define PCLK_GPIO_NUM 19 - -#define I2C_SDA 21 -#define I2C_SCL 22 - -#define BUTTON_1 34 - -#define SSD130_MODLE_TYPE 0 // 0 : GEOMETRY_128_64 // 1: GEOMETRY_128_32 - -#define AS312_PIN 33 - -#define ENABLE_IP5306 - -#elif defined(CAMERA_MODEL_XIAO_ESP32S3) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 10 -#define SIOD_GPIO_NUM 40 -#define SIOC_GPIO_NUM 39 - -#define Y9_GPIO_NUM 48 -#define Y8_GPIO_NUM 11 -#define Y7_GPIO_NUM 12 -#define Y6_GPIO_NUM 14 -#define Y5_GPIO_NUM 16 -#define Y4_GPIO_NUM 18 -#define Y3_GPIO_NUM 17 -#define Y2_GPIO_NUM 15 -#define VSYNC_GPIO_NUM 38 -#define HREF_GPIO_NUM 47 -#define PCLK_GPIO_NUM 13 - -#elif defined(CAMERA_MODEL_ESP32_CAM_BOARD) -// The 18 pin header on the board has Y5 and Y3 swapped -#define USE_BOARD_HEADER 0 -#define PWDN_GPIO_NUM 32 -#define RESET_GPIO_NUM 33 -#define XCLK_GPIO_NUM 4 -#define SIOD_GPIO_NUM 18 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 36 -#define Y8_GPIO_NUM 19 -#define Y7_GPIO_NUM 21 -#define Y6_GPIO_NUM 39 -#if USE_BOARD_HEADER -#define Y5_GPIO_NUM 13 -#else -#define Y5_GPIO_NUM 35 -#endif -#define Y4_GPIO_NUM 14 -#if USE_BOARD_HEADER -#define Y3_GPIO_NUM 35 -#else -#define Y3_GPIO_NUM 13 -#endif -#define Y2_GPIO_NUM 34 -#define VSYNC_GPIO_NUM 5 -#define HREF_GPIO_NUM 27 -#define PCLK_GPIO_NUM 25 - -#elif defined(CAMERA_MODEL_ESP32S3_CAM_LCD) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 40 -#define SIOD_GPIO_NUM 17 -#define SIOC_GPIO_NUM 18 - -#define Y9_GPIO_NUM 39 -#define Y8_GPIO_NUM 41 -#define Y7_GPIO_NUM 42 -#define Y6_GPIO_NUM 12 -#define Y5_GPIO_NUM 3 -#define Y4_GPIO_NUM 14 -#define Y3_GPIO_NUM 47 -#define Y2_GPIO_NUM 13 -#define VSYNC_GPIO_NUM 21 -#define HREF_GPIO_NUM 38 -#define PCLK_GPIO_NUM 11 - -#elif defined(CAMERA_MODEL_ESP32S2_CAM_BOARD) -// The 18 pin header on the board has Y5 and Y3 swapped -#define USE_BOARD_HEADER 0 -#define PWDN_GPIO_NUM 1 -#define RESET_GPIO_NUM 2 -#define XCLK_GPIO_NUM 42 -#define SIOD_GPIO_NUM 41 -#define SIOC_GPIO_NUM 18 - -#define Y9_GPIO_NUM 16 -#define Y8_GPIO_NUM 39 -#define Y7_GPIO_NUM 40 -#define Y6_GPIO_NUM 15 -#if USE_BOARD_HEADER -#define Y5_GPIO_NUM 12 -#else -#define Y5_GPIO_NUM 13 -#endif -#define Y4_GPIO_NUM 5 -#if USE_BOARD_HEADER -#define Y3_GPIO_NUM 13 -#else -#define Y3_GPIO_NUM 12 -#endif -#define Y2_GPIO_NUM 14 -#define VSYNC_GPIO_NUM 38 -#define HREF_GPIO_NUM 4 -#define PCLK_GPIO_NUM 3 - -#elif defined(CAMERA_MODEL_ESP32S3_EYE) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 15 -#define SIOD_GPIO_NUM 4 -#define SIOC_GPIO_NUM 5 - -#define Y2_GPIO_NUM 11 -#define Y3_GPIO_NUM 9 -#define Y4_GPIO_NUM 8 -#define Y5_GPIO_NUM 10 -#define Y6_GPIO_NUM 12 -#define Y7_GPIO_NUM 18 -#define Y8_GPIO_NUM 17 -#define Y9_GPIO_NUM 16 - -#define VSYNC_GPIO_NUM 6 -#define HREF_GPIO_NUM 7 -#define PCLK_GPIO_NUM 13 - -#elif defined(CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3) || defined(CAMERA_MODEL_DFRobot_Romeo_ESP32S3) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 45 -#define SIOD_GPIO_NUM 1 -#define SIOC_GPIO_NUM 2 - -#define Y9_GPIO_NUM 48 -#define Y8_GPIO_NUM 46 -#define Y7_GPIO_NUM 8 -#define Y6_GPIO_NUM 7 -#define Y5_GPIO_NUM 4 -#define Y4_GPIO_NUM 41 -#define Y3_GPIO_NUM 40 -#define Y2_GPIO_NUM 39 -#define VSYNC_GPIO_NUM 6 -#define HREF_GPIO_NUM 42 -#define PCLK_GPIO_NUM 5 - -#else -#error "Camera model not selected" -#endif \ No newline at end of file diff --git a/examples/Camera/motion-snapshot-capture/motion-snapshot-capture.ino b/examples/Camera/motion-snapshot-capture/motion-snapshot-capture.ino deleted file mode 100644 index 2b1e52e..0000000 --- a/examples/Camera/motion-snapshot-capture/motion-snapshot-capture.ino +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Example for how to use SinricPro Camera device: - * - Create a ESP32 Camera device from portal. - * - Copy the secrets below. - * - * If you encounter any issues: - * - check the readme.md at https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md - * - ensure all dependent libraries are installed - * - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#arduinoide - * - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#dependencies - * - open serial monitor and check whats happening - * - check full user documentation at https://sinricpro.github.io/esp8266-esp32-sdk - * - visit https://github.com/sinricpro/esp8266-esp32-sdk/issues and check for existing issues or open a new one - */ - -// Uncomment the following line to enable serial debug output -#define ENABLE_DEBUG -#define SINRICPRO_CAMERA_URL "testcamera.sinric.pro" - -#include -#include -#include -#include -#include -#include - -// =================== -// Select camera model -// =================== -// #define CAMERA_MODEL_WROVER_KIT // Has PSRAM -// #define CAMERA_MODEL_ESP_EYE // Has PSRAM -// #define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM -// #define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM -// #define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM -// #define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM -// #define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM -// #define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM -// #define CAMERA_MODEL_M5STACK_CAMS3_UNIT // Has PSRAM -// #define CAMERA_MODEL_AI_THINKER // Has PSRAM -// #define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM -// #define CAMERA_MODEL_TTGO_T_V16_VERSION -// #define CAMERA_MODEL_TTGO_T_V05_VERSION -// #define CAMERA_MODEL_TTGO_T_PLUS_VERSION -// #define CAMERA_MODEL_TTGO_T_V162_VERSION -// #define CAMERA_MODEL_TTGO_T_MINI_VERSION -// #define CAMERA_MODEL_TTGO_T_V17_VERSION - #define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM -// ** Espressif Internal Boards ** -// #define CAMERA_MODEL_ESP32_CAM_BOARD -// #define CAMERA_MODEL_ESP32S2_CAM_BOARD -// #define CAMERA_MODEL_ESP32S3_CAM_LCD -// #define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM -// #define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM -#include "camera_pins.h" -#include "motion_detector.h" - -#define WIFI_SSID "June" -#define WIFI_PASS "wifipassword" - -#define APP_KEY "7c7f0312-502e-4eba-a377-80fd599e79e7" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx" -#define APP_SECRET "4bdc2144-f17b-463a-be32-600e6835b922-63bc1698-7c52-41f0-bcb5-a444528ba781" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx" -#define CAMERA_ID "673bce6823cdb5c141975952" // Should look like "5dc1564130xxxxxxxxxxxxxx" - -// More sensitive to large moving objects -// #define BLOCK_THRESHOLD 40 // Require stronger pixel changes -// #define MOTION_THRESHOLD 15 // Require more blocks to change - -// More sensitive to mid moving objects -#define BLOCK_THRESHOLD 30 // Accept subtler pixel changes -#define MOTION_THRESHOLD 10 // Accept mid changed blocks - -// More sensitive to small moving objects -// #define BLOCK_THRESHOLD 20 // Accept subtler pixel changes -// #define MOTION_THRESHOLD 5 // Accept fewer changed blocks - -MotionDetector *motionDetector = nullptr; -bool motionDetected = false; - -// File to save the MJPEG -const char* motionFileName = "/motion.mjpeg"; -// Number of frames and delay between captures -#define NUM_FRAMES 5 -#define FRAME_DELAY 200 // in milliseconds - -bool onPowerState(const String &deviceId, bool &state) { - return true; -} - -// setup function for WiFi connection -void setupWiFi() { - Serial.printf("\r\n[Wifi]: Connecting"); - - WiFi.begin(WIFI_SSID, WIFI_PASS); - WiFi.setSleep(false); - - while (WiFi.status() != WL_CONNECTED) { - Serial.printf("."); - delay(250); - } - Serial.printf("connected!\r\n[WiFi]: IP-Address is %s\r\n", WiFi.localIP().toString().c_str()); -} - -void setupSinricPro() { - SinricProCamera &myCamera = SinricPro[CAMERA_ID]; - myCamera.onPowerState(onPowerState); - - SinricPro.onConnected([]() { - Serial.printf("Connected to SinricPro\r\n"); - }); - SinricPro.onDisconnected([]() { - Serial.printf("Disconnected from SinricPro\r\n"); - }); - - SinricPro.begin(APP_KEY, APP_SECRET, "testws.sinric.pro"); -} - -void setupCamera() { - Serial.printf("Setup Camera..\r\n"); - - 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_sccb_sda = SIOD_GPIO_NUM; - config.pin_sccb_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_VGA; // https://github.com/espressif/esp32-camera/blob/master/driver/include/sensor.h#L98C5-L98C18 - config.grab_mode = CAMERA_GRAB_WHEN_EMPTY; - config.fb_location = CAMERA_FB_IN_PSRAM; - config.jpeg_quality = 12; - config.fb_count = 1; - - if (psramFound()) { - config.fb_count = 2; - config.grab_mode = CAMERA_GRAB_LATEST; - } else { - Serial.println("Warnning! PSRAM not found!!!!"); - // Limit the frame size when PSRAM is not available - config.frame_size = FRAMESIZE_SVGA; - config.fb_location = CAMERA_FB_IN_DRAM; - } - - esp_err_t err = esp_camera_init(&config); - if (err != ESP_OK) { - Serial.printf("Camera init failed with error 0x%x", err); - return; - } - - Serial.printf("Camera Setup done!..\r\n"); -} - -void setupMotionDetection() { - MotionDetector::Config mdConfig = { - .width = 640, // VGA width - .height = 480, // VGA height - .blockSize = 16, // 16x16 pixel blocks - .blockThreshold = BLOCK_THRESHOLD, // Sensitivity to changes within blocks - .motionThreshold = MOTION_THRESHOLD, // Number of blocks that must change - .jpegQuality = 12 // JPEG quality setting - }; - - motionDetector = new MotionDetector(mdConfig); - if (!motionDetector->init()) { - Serial.println("Motion detector initialization failed!"); - return; - } -} - -void setup() { - Serial.begin(115200); - - // Initialize SPIFFS - if (!SPIFFS.begin(true)) { - Serial.println("Failed to mount SPIFFS"); - return; - } - - setupCamera(); - setupMotionDetection(); - setupWiFi(); - setupSinricPro(); -} - -std::vector createMJPEG(std::vector& frames) { - std::vector mjpegData; - - // MJPEG header - const char* mjpegHeader = "--boundary\r\nContent-Type: image/jpeg\r\n\r\n"; - - for (auto frame : frames) { - // Add boundary and headers - mjpegData.insert(mjpegData.end(), mjpegHeader, mjpegHeader + strlen(mjpegHeader)); - - // Add JPEG data - mjpegData.insert(mjpegData.end(), frame->buf, frame->buf + frame->len); - - Serial.printf("frame->len size: %d\r\n", frame->len); - - // Add newline - mjpegData.push_back('\r'); - mjpegData.push_back('\n'); - } - - return mjpegData; -} - -void captureAndSendFrames() { - std::vector frames; - - // Capture 5 frames - for (int i = 0; i < 5; i++) { - camera_fb_t* fb = esp_camera_fb_get(); - if (!fb) { - Serial.println("Camera capture failed"); - continue; - } - frames.push_back(fb); - delay(200); // Small delay between captures - } - - if (frames.size() > 0) { - // Create MJPEG data - std::vector mjpegData = createMJPEG(frames); - - Serial.printf("mjpegData size: %d\r\n", mjpegData.size()); - - SinricProCamera &myCamera = SinricPro[CAMERA_ID]; - int result = myCamera.sendMotion(mjpegData.data(), mjpegData.size()); - Serial.printf("Snapshot %s\r\n", result == 200 ? "sent!" : "send failed!"); - } - - // Free the frames - for (auto frame : frames) { - esp_camera_fb_return(frame); - } -} - -// void sendMotion() { -// SinricProCamera &myCamera = SinricPro[CAMERA_ID]; -// int result = myCamera.sendMotion(motionFileName); -// // 200 = Success -// // 429 = Too many requests -// // 400 = Format error -// // 500 = internal error -// Serial.printf("Motion %s\r\n", result == 200 ? "sent!" : "send failed!"); -// } - -void sendSnapshot(camera_fb_t *fb) { - SinricProCamera &myCamera = SinricPro[CAMERA_ID]; - int result = myCamera.sendSnapshot(fb->buf, fb->len); - // 200 = Success - // 429 = Too many requests - // 400 = Format error - // 500 = internal error - Serial.printf("Snapshot %s\r\n", result == 200 ? "sent!" : "send failed!"); -} - -void loop() { - SinricPro.handle(); - - camera_fb_t *fb = esp_camera_fb_get(); - if (!fb) { - Serial.println("Camera capture failed"); - return; - } - - if (motionDetector->detectMotion(fb)) { - if (!motionDetected) { - Serial.println("Motion detected!"); - motionDetected = true; - } - } else { - motionDetected = false; - } - - if (motionDetected) { - // sendSnapshot(fb); - - esp_camera_fb_return(fb); - captureAndSendFrames(); - } - - esp_camera_fb_return(fb); - - delay(100); -} \ No newline at end of file diff --git a/examples/Camera/motion-snapshot-capture/motion_detector.cpp b/examples/Camera/motion-snapshot-capture/motion_detector.cpp deleted file mode 100644 index dcd14b4..0000000 --- a/examples/Camera/motion-snapshot-capture/motion_detector.cpp +++ /dev/null @@ -1,139 +0,0 @@ -#include "motion_detector.h" - -MotionDetector::MotionDetector(const Config& config) - : config_(config), - prevFrame_(nullptr), - currentFrame_(nullptr), - isInitialized_(false) { -} - -MotionDetector::~MotionDetector() { - if (isInitialized_) { - freeFrameBuffers(); - } -} - -bool MotionDetector::init() { - if (isInitialized_) { - return true; - } - - if (!allocateFrameBuffers()) { - Serial.println("Failed to allocate frame buffers"); - return false; - } - - isInitialized_ = true; - return true; -} - -void MotionDetector::reset() { - if (!isInitialized_) return; - - size_t frameSize = config_.width * config_.height * 2; // RGB565 = 2 bytes per pixel - if (prevFrame_) { - memset(prevFrame_, 0, frameSize); - } - if (currentFrame_) { - memset(currentFrame_, 0, frameSize); - } -} - -bool MotionDetector::allocateFrameBuffers() { - size_t frameSize = config_.width * config_.height * 2; // RGB565 = 2 bytes per pixel - - // Free any existing buffers first - freeFrameBuffers(); - - // Use MALLOC_CAP_SPIRAM for external RAM if available - prevFrame_ = (uint8_t*)heap_caps_malloc(frameSize, MALLOC_CAP_8BIT); - currentFrame_ = (uint8_t*)heap_caps_malloc(frameSize, MALLOC_CAP_8BIT); - - if (!prevFrame_ || !currentFrame_) { - freeFrameBuffers(); - return false; - } - - memset(prevFrame_, 0, frameSize); - memset(currentFrame_, 0, frameSize); - - return true; -} - -void MotionDetector::freeFrameBuffers() { - if (prevFrame_) { - heap_caps_free(prevFrame_); - prevFrame_ = nullptr; - } - if (currentFrame_) { - heap_caps_free(currentFrame_); - currentFrame_ = nullptr; - } -} - -bool MotionDetector::compareFrames() { - if (!isInitialized_ || !prevFrame_ || !currentFrame_) { - return false; - } - - int changedBlocks = 0; - int bytesPerPixel = 2; // RGB565 uses 2 bytes per pixel - - for (int y = 0; y < config_.height; y += config_.blockSize) { - for (int x = 0; x < config_.width; x += config_.blockSize) { - int diffSum = 0; - - // Compare blocks - for (int by = 0; by < config_.blockSize && (y + by) < config_.height; by++) { - for (int bx = 0; bx < config_.blockSize && (x + bx) < config_.width; bx++) { - int pos = ((y + by) * config_.width + (x + bx)) * bytesPerPixel; - - // Get RGB565 values - uint16_t current = (currentFrame_[pos + 1] << 8) | currentFrame_[pos]; - uint16_t prev = (prevFrame_[pos + 1] << 8) | prevFrame_[pos]; - - // Extract RGB components - uint8_t currentR = (current >> 11) & 0x1F; - uint8_t currentG = (current >> 5) & 0x3F; - uint8_t currentB = current & 0x1F; - - uint8_t prevR = (prev >> 11) & 0x1F; - uint8_t prevG = (prev >> 5) & 0x3F; - uint8_t prevB = prev & 0x1F; - - diffSum += abs(currentR - prevR); - diffSum += abs(currentG - prevG); - diffSum += abs(currentB - prevB); - } - } - - if (diffSum / (config_.blockSize * config_.blockSize) > config_.blockThreshold) { - changedBlocks++; - } - } - } - - if (changedBlocks > 0) { Serial.print(changedBlocks); Serial.println(" blocks changed!"); } - return changedBlocks > config_.motionThreshold; -} - -bool MotionDetector::jpegToRgb565(const uint8_t* jpegData, size_t jpegLen, uint8_t* outBuffer) { - return jpg2rgb565(jpegData, jpegLen, outBuffer, JPG_SCALE_NONE); -} - -bool MotionDetector::detectMotion(camera_fb_t* frame) { - if (!isInitialized_ || !frame || frame->format != PIXFORMAT_JPEG) { - return false; - } - - // Copy current frame to previous frame - memcpy(prevFrame_, currentFrame_, config_.width * config_.height * 2); - - // Convert new frame to RGB565 - if (!jpegToRgb565(frame->buf, frame->len, currentFrame_)) { - Serial.println("Failed to convert JPEG to RGB565"); - return false; - } - - return compareFrames(); -} \ No newline at end of file diff --git a/examples/Camera/motion-snapshot-capture/motion_detector.h b/examples/Camera/motion-snapshot-capture/motion_detector.h deleted file mode 100644 index 24c5c13..0000000 --- a/examples/Camera/motion-snapshot-capture/motion_detector.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include -#include "esp_camera.h" -#include "img_converters.h" - -class MotionDetector { -public: - struct Config { - uint16_t width; - uint16_t height; - uint8_t blockSize; - uint8_t blockThreshold; - uint8_t motionThreshold; - uint8_t jpegQuality; - }; - - MotionDetector(const Config& config); - ~MotionDetector(); - - bool init(); - bool detectMotion(camera_fb_t* frame); - void reset(); - -private: - Config config_; - uint8_t* prevFrame_; // Previous frame in RGB565 format - uint8_t* currentFrame_; // Current frame in RGB565 format - bool isInitialized_; - - bool allocateFrameBuffers(); - void freeFrameBuffers(); - bool compareFrames(); - bool jpegToRgb565(const uint8_t* jpegData, size_t jpegLen, uint8_t* outBuffer); -}; From 2f346a88b0947e892851765b0bf5487b5de6b669 Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Sun, 5 Jan 2025 09:17:07 +0700 Subject: [PATCH 10/18] feat: camera examples --- .github/workflows/build-esp8266-esp32.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-esp8266-esp32.yml b/.github/workflows/build-esp8266-esp32.yml index 354ba0a..2313e98 100644 --- a/.github/workflows/build-esp8266-esp32.yml +++ b/.github/workflows/build-esp8266-esp32.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - example: [examples/ACUnit, examples/AirQualitySensor/AirQualitySensor, examples/Blinds, examples/ContactSensor, examples/DimSwitch, examples/doorbell, examples/Fan, examples/GarageDoor, examples/Light/Light, examples/Lock/Lock, examples/Lock/Lock_with_feedback, examples/MotionSensor, examples/PowerSensor, examples/Relay/MultiRelays_advance, examples/Relay/Relay, examples/Speaker, examples/Switch/MultiSwitch_advance, examples/Switch/MultiSwitch_beginner, examples/Switch/MultiSwitch_intermediate, examples/Switch/Switch, examples/Thermostat, examples/TV, examples/OTAUpdate, examples/Health, examples/Settings/MultiWiFi] + example: [examples/ACUnit, examples/AirQualitySensor/AirQualitySensor, examples/Blinds, examples/ContactSensor, examples/DimSwitch, examples/doorbell, examples/Fan, examples/GarageDoor, examples/Light/Light, examples/Lock/Lock, examples/Lock/Lock_with_feedback, examples/MotionSensor, examples/PowerSensor, examples/Relay/MultiRelays_advance, examples/Relay/Relay, examples/Speaker, examples/Switch/MultiSwitch_advance, examples/Switch/MultiSwitch_beginner, examples/Switch/MultiSwitch_intermediate, examples/Switch/Switch, examples/Thermostat, examples/TV, examples/OTAUpdate, examples/Health, examples/Settings/MultiWiFi, examples/Camera/motion-capture, examples/Camera/snapshot-camera] steps: From fc9e613ef6d26d49c13197940ad6e5736940bedd Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Mon, 6 Jan 2025 00:13:39 +0700 Subject: [PATCH 11/18] fix: workflow for esp32 --- .github/workflows/build-esp8266-esp32.yml | 140 +++++++++++++++++----- 1 file changed, 107 insertions(+), 33 deletions(-) diff --git a/.github/workflows/build-esp8266-esp32.yml b/.github/workflows/build-esp8266-esp32.yml index 2313e98..1d026d6 100644 --- a/.github/workflows/build-esp8266-esp32.yml +++ b/.github/workflows/build-esp8266-esp32.yml @@ -1,46 +1,120 @@ -name: Build for ESP8266 and ESP32 +name: Build for ESP8266 and ESP32 + on: workflow_dispatch: - pull_request: branches: [ master ] paths: - src/** - examples/** - -jobs: - build: +jobs: + build-esp8266: runs-on: ubuntu-latest strategy: matrix: - example: [examples/ACUnit, examples/AirQualitySensor/AirQualitySensor, examples/Blinds, examples/ContactSensor, examples/DimSwitch, examples/doorbell, examples/Fan, examples/GarageDoor, examples/Light/Light, examples/Lock/Lock, examples/Lock/Lock_with_feedback, examples/MotionSensor, examples/PowerSensor, examples/Relay/MultiRelays_advance, examples/Relay/Relay, examples/Speaker, examples/Switch/MultiSwitch_advance, examples/Switch/MultiSwitch_beginner, examples/Switch/MultiSwitch_intermediate, examples/Switch/Switch, examples/Thermostat, examples/TV, examples/OTAUpdate, examples/Health, examples/Settings/MultiWiFi, examples/Camera/motion-capture, examples/Camera/snapshot-camera] - + # Base examples that work on both platforms + example: &base_examples + - examples/ACUnit + - examples/Blinds + - examples/ContactSensor + - examples/DimSwitch + - examples/doorbell + - examples/Fan + - examples/GarageDoor + - examples/Light/Light + - examples/Lock/Lock + - examples/Lock/Lock_with_feedback + - examples/MotionSensor + - examples/PowerSensor + - examples/Relay/MultiRelays_advance + - examples/Relay/Relay + - examples/Speaker + - examples/Switch/MultiSwitch_advance + - examples/Switch/MultiSwitch_beginner + - examples/Switch/MultiSwitch_intermediate + - examples/Switch/Switch + - examples/Thermostat + - examples/TV + - examples/OTAUpdate + - examples/Health + - examples/Settings/MultiWiFi + - examples/AirQualitySensor/AirQualitySensor steps: + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Cache pip + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: ${{ runner.os }}-pip- + + - name: Cache PlatformIO + uses: actions/cache@v3 + with: + path: ~/.platformio + key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + + - name: Set up Python + uses: actions/setup-python@v3 + + - name: Install PlatformIO + run: | + python -m pip install --upgrade pip + pip install --upgrade platformio + + - name: Install library dependencies + run: | + pio pkg install -l "bblanchon/ArduinoJson" -l "links2004/WebSockets" -g + + - name: Run build test using PlatformIO + run: pio ci --lib="." -b esp12e + env: + PLATFORMIO_CI_SRC: ${{ matrix.example }} - - name: Step 1 - Checkout Repo - uses: actions/checkout@v4 - - name: Step 2 - Cache pip - uses: actions/cache@v3 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: ${{ runner.os }}-pip- - - name: Step 3 - Cache PlatformIO - uses: actions/cache@v3 - with: - path: ~/.platformio - key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} - - name: Step 4 - Set up Python - uses: actions/setup-python@v3 - - name: Step 5 - Install PlatformIO - run: | - python -m pip install --upgrade pip - pip install --upgrade platformio - - name: Step 6 - Install library dependencies - run: | - pio pkg install -l "bblanchon/ArduinoJson" -l "links2004/WebSockets" -g - - name: Step 7 - Run build test using PlatformIO - run: pio ci --lib="." -b esp12e -b esp32dev - env: - PLATFORMIO_CI_SRC: ${{ matrix.example }} + build-esp32: + runs-on: ubuntu-latest + strategy: + matrix: + example: + # Include all base examples + - *base_examples + # ESP32-specific examples + - &esp32_examples + - examples/Camera/motion-capture + - examples/Camera/snapshot-camera + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Cache pip + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: ${{ runner.os }}-pip- + + - name: Cache PlatformIO + uses: actions/cache@v3 + with: + path: ~/.platformio + key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + + - name: Set up Python + uses: actions/setup-python@v3 + + - name: Install PlatformIO + run: | + python -m pip install --upgrade pip + pip install --upgrade platformio + + - name: Install library dependencies + run: | + pio pkg install -l "bblanchon/ArduinoJson" -l "links2004/WebSockets" -g + + - name: Run build test using PlatformIO + run: pio ci --lib="." -b esp32dev + env: + PLATFORMIO_CI_SRC: ${{ matrix.example }} \ No newline at end of file From 577300f95548a3baebf2a3ea3f0736e7f38f1ed9 Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Mon, 6 Jan 2025 00:20:55 +0700 Subject: [PATCH 12/18] fix: format and esp32 camera example compliation --- .github/workflows/build-esp8266-esp32.yml | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-esp8266-esp32.yml b/.github/workflows/build-esp8266-esp32.yml index 1d026d6..bb57bb2 100644 --- a/.github/workflows/build-esp8266-esp32.yml +++ b/.github/workflows/build-esp8266-esp32.yml @@ -9,12 +9,11 @@ on: - examples/** jobs: - build-esp8266: + build-esp8266-esp32: runs-on: ubuntu-latest strategy: matrix: - # Base examples that work on both platforms - example: &base_examples + example: - examples/ACUnit - examples/Blinds - examples/ContactSensor @@ -70,21 +69,17 @@ jobs: pio pkg install -l "bblanchon/ArduinoJson" -l "links2004/WebSockets" -g - name: Run build test using PlatformIO - run: pio ci --lib="." -b esp12e + run: pio ci --lib="." -b esp12e -b esp32dev env: PLATFORMIO_CI_SRC: ${{ matrix.example }} - build-esp32: + build-camera-examples: runs-on: ubuntu-latest strategy: matrix: example: - # Include all base examples - - *base_examples - # ESP32-specific examples - - &esp32_examples - - examples/Camera/motion-capture - - examples/Camera/snapshot-camera + - examples/Camera/motion-capture + - examples/Camera/snapshot-camera steps: - name: Checkout Repo uses: actions/checkout@v4 From 0d525be4f0e6094c7dd7139cb81647490e520769 Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Mon, 6 Jan 2025 00:29:25 +0700 Subject: [PATCH 13/18] fix: remove camera examples --- .github/workflows/build-esp8266-esp32.yml | 108 +++++++--------------- 1 file changed, 32 insertions(+), 76 deletions(-) diff --git a/.github/workflows/build-esp8266-esp32.yml b/.github/workflows/build-esp8266-esp32.yml index bb57bb2..ec57be9 100644 --- a/.github/workflows/build-esp8266-esp32.yml +++ b/.github/workflows/build-esp8266-esp32.yml @@ -1,15 +1,16 @@ -name: Build for ESP8266 and ESP32 - +name: Build for ESP8266 and ESP32 on: workflow_dispatch: + pull_request: branches: [ master ] paths: - src/** - examples/** - + jobs: - build-esp8266-esp32: + build: + runs-on: ubuntu-latest strategy: matrix: @@ -39,77 +40,32 @@ jobs: - examples/Health - examples/Settings/MultiWiFi - examples/AirQualitySensor/AirQualitySensor - steps: - - name: Checkout Repo - uses: actions/checkout@v4 - - - name: Cache pip - uses: actions/cache@v3 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: ${{ runner.os }}-pip- - - - name: Cache PlatformIO - uses: actions/cache@v3 - with: - path: ~/.platformio - key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} - - - name: Set up Python - uses: actions/setup-python@v3 - - - name: Install PlatformIO - run: | - python -m pip install --upgrade pip - pip install --upgrade platformio - - - name: Install library dependencies - run: | - pio pkg install -l "bblanchon/ArduinoJson" -l "links2004/WebSockets" -g - - - name: Run build test using PlatformIO - run: pio ci --lib="." -b esp12e -b esp32dev - env: - PLATFORMIO_CI_SRC: ${{ matrix.example }} - build-camera-examples: - runs-on: ubuntu-latest - strategy: - matrix: - example: - - examples/Camera/motion-capture - - examples/Camera/snapshot-camera steps: - - name: Checkout Repo - uses: actions/checkout@v4 - - - name: Cache pip - uses: actions/cache@v3 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: ${{ runner.os }}-pip- - - - name: Cache PlatformIO - uses: actions/cache@v3 - with: - path: ~/.platformio - key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} - - - name: Set up Python - uses: actions/setup-python@v3 - - - name: Install PlatformIO - run: | - python -m pip install --upgrade pip - pip install --upgrade platformio - - - name: Install library dependencies - run: | - pio pkg install -l "bblanchon/ArduinoJson" -l "links2004/WebSockets" -g - - - name: Run build test using PlatformIO - run: pio ci --lib="." -b esp32dev - env: - PLATFORMIO_CI_SRC: ${{ matrix.example }} \ No newline at end of file + + - name: Step 1 - Checkout Repo + uses: actions/checkout@v4 + - name: Step 2 - Cache pip + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: ${{ runner.os }}-pip- + - name: Step 3 - Cache PlatformIO + uses: actions/cache@v3 + with: + path: ~/.platformio + key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + - name: Step 4 - Set up Python + uses: actions/setup-python@v3 + - name: Step 5 - Install PlatformIO + run: | + python -m pip install --upgrade pip + pip install --upgrade platformio + - name: Step 6 - Install library dependencies + run: | + pio pkg install -l "bblanchon/ArduinoJson" -l "links2004/WebSockets" -g + - name: Step 7 - Run build test using PlatformIO + run: pio ci --lib="." -b esp12e -b esp32dev + env: + PLATFORMIO_CI_SRC: ${{ matrix.example }} From 888723372d1b76b636a9ba22763869b520930551 Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Mon, 6 Jan 2025 00:42:25 +0700 Subject: [PATCH 14/18] feat: compile camera examples --- .../build-esp32-camera-examples.yaml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/build-esp32-camera-examples.yaml diff --git a/.github/workflows/build-esp32-camera-examples.yaml b/.github/workflows/build-esp32-camera-examples.yaml new file mode 100644 index 0000000..b3c208e --- /dev/null +++ b/.github/workflows/build-esp32-camera-examples.yaml @@ -0,0 +1,55 @@ +name: Compile Examples + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + env: + # sketch paths to compile (recursive) for all boards + CAMERA_SKETCH_PATHS: | + - examples/Camera/motion-capture + - examples/Camera/snapshot-camera + + strategy: + fail-fast: false + + matrix: + board: + - fqbn: esp32:esp32:esp32 + type: esp32 + + # make board type-specific customizations to the matrix jobs + include: + # ESP32 boards + - board: + type: esp32 + platforms: | + # Install ESP32 platform via Boards Manager + - name: esp32:esp32 + source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json + libraries: | + - source-path: ./ + sketch-paths: + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install ESP32 platform dependencies + if: matrix.board.type == 'esp32' + run: pip3 install pyserial + + - name: Compile examples + uses: arduino/compile-sketches@v1 + with: + platforms: ${{ matrix.platforms }} + fqbn: ${{ matrix.board.fqbn }} + libraries: | + ${{ matrix.libraries }} + sketch-paths: | + ${{ env.CAMERA_SKETCH_PATHS }} + cli-compile-flags: | + - --warnings="none" + # "compiler.cpp.extra_flags=-Werror" \ No newline at end of file From 720750156d473b6026aaf9bc5c91fd390016a3f2 Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Mon, 6 Jan 2025 00:46:23 +0700 Subject: [PATCH 15/18] fix: deps --- .github/workflows/build-esp32-camera-examples.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-esp32-camera-examples.yaml b/.github/workflows/build-esp32-camera-examples.yaml index b3c208e..8f43492 100644 --- a/.github/workflows/build-esp32-camera-examples.yaml +++ b/.github/workflows/build-esp32-camera-examples.yaml @@ -1,4 +1,4 @@ -name: Compile Examples +name: Compile Camera Examples on: [push, pull_request] @@ -31,6 +31,8 @@ jobs: source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json libraries: | - source-path: ./ + - source-url: "https://github.com/Links2004/arduinoWebSockets.git" + - source-url: "https://github.com/bblanchon/ArduinoJson.git" sketch-paths: steps: From f28efda76714f8fbfc7d39dab3d4aae3a99611b8 Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Mon, 6 Jan 2025 00:51:50 +0700 Subject: [PATCH 16/18] fix: compliation error --- examples/Camera/snapshot-camera/snapshot-camera.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Camera/snapshot-camera/snapshot-camera.ino b/examples/Camera/snapshot-camera/snapshot-camera.ino index c63325f..98a2d3e 100644 --- a/examples/Camera/snapshot-camera/snapshot-camera.ino +++ b/examples/Camera/snapshot-camera/snapshot-camera.ino @@ -89,7 +89,7 @@ bool onSnapshot(const String &deviceId) { } esp_camera_fb_return(fb); - return result == 200; + return responseCode == 200; } bool onPowerState(const String &deviceId, bool &state) { From a8abc2e20cd9280adfec143c5cd6db35166e6165 Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Mon, 6 Jan 2025 00:52:09 +0700 Subject: [PATCH 17/18] fix: clean workflow --- .../build-esp32-camera-examples.yaml | 70 ++++++++----------- 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/.github/workflows/build-esp32-camera-examples.yaml b/.github/workflows/build-esp32-camera-examples.yaml index 8f43492..429b273 100644 --- a/.github/workflows/build-esp32-camera-examples.yaml +++ b/.github/workflows/build-esp32-camera-examples.yaml @@ -1,57 +1,45 @@ -name: Compile Camera Examples +name: ESP32 Camera Examples -on: [push, pull_request] +on: + push: + pull_request: + +env: + SKETCHES: | + examples/Camera/motion-capture + examples/Camera/snapshot-camera jobs: - build: + compile-camera-examples: runs-on: ubuntu-latest - - env: - # sketch paths to compile (recursive) for all boards - CAMERA_SKETCH_PATHS: | - - examples/Camera/motion-capture - - examples/Camera/snapshot-camera - + strategy: fail-fast: false - matrix: - board: - - fqbn: esp32:esp32:esp32 - type: esp32 - - # make board type-specific customizations to the matrix jobs include: - # ESP32 boards - - board: - type: esp32 - platforms: | - # Install ESP32 platform via Boards Manager - - name: esp32:esp32 - source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json - libraries: | - - source-path: ./ - - source-url: "https://github.com/Links2004/arduinoWebSockets.git" - - source-url: "https://github.com/bblanchon/ArduinoJson.git" - sketch-paths: + - board: "esp32:esp32:esp32" + platform-url: "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" steps: - - name: Checkout - uses: actions/checkout@v2 + - name: Checkout repository + uses: actions/checkout@v4 - - name: Install ESP32 platform dependencies - if: matrix.board.type == 'esp32' - run: pip3 install pyserial + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + pip install pyserial - - name: Compile examples + - name: Compile ESP32 camera examples uses: arduino/compile-sketches@v1 with: - platforms: ${{ matrix.platforms }} - fqbn: ${{ matrix.board.fqbn }} + fqbn: ${{ matrix.board }} + platforms: | + - name: esp32:esp32 + source-url: ${{ matrix.platform-url }} libraries: | - ${{ matrix.libraries }} - sketch-paths: | - ${{ env.CAMERA_SKETCH_PATHS }} + - source-path: ./ + - source-url: https://github.com/Links2004/arduinoWebSockets.git + - source-url: https://github.com/bblanchon/ArduinoJson.git + sketch-paths: ${{ env.SKETCHES }} cli-compile-flags: | - - --warnings="none" - # "compiler.cpp.extra_flags=-Werror" \ No newline at end of file + - --warnings=none \ No newline at end of file From 4acb10ee79b54d0aa7e0335ce76eed17accae73e Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Tue, 7 Jan 2025 00:35:22 +0700 Subject: [PATCH 18/18] fix: double import --- examples/Camera/mjpeg-camera/mjpeg-camera.ino | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/Camera/mjpeg-camera/mjpeg-camera.ino b/examples/Camera/mjpeg-camera/mjpeg-camera.ino index 8f8e0c5..7f1802d 100644 --- a/examples/Camera/mjpeg-camera/mjpeg-camera.ino +++ b/examples/Camera/mjpeg-camera/mjpeg-camera.ino @@ -27,8 +27,6 @@ //#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM #include "camera_pins.h" -#include "camera_pins.h" - #define WIFI_SSID "YOUR-WIFI-SSID" #define WIFI_PASSWD "YOUR-WIFI-PASSWORD"