9122浏览
查看: 9122|回复: 2

[项目] ESP EYE + 行空板 智能门禁轻松实现

[复制链接]
ESP EYE + 行空板 智能门禁轻松实现图1

【项目背景】
在DF商城看到一个ESP开发板,ESP-EYE 智能摄像头开发板 板载ESP32芯片,集成200万像素摄像头,支持Wi-Fi图像传输。很小巧,正好这段时间正在学习如何使用ESP32开发板,就用这个ESP-EYE开发板与行空板结合做一个小项目,数字“猫眼”。
【ESP EYE】
1.ESP-EYE是一款专注于图像识别与语音处理的开发板,板载ESP32芯片,集成200万像素摄像头、数字麦克风,拥有8 MByte PSRAM和4 MByte flash的丰富存储,支持Wi-Fi图像传输与Micro USB调试与供电,可广泛应用于智能物联网领域的应用开发。
ESP EYE + 行空板 智能门禁轻松实现图4


ESP EYE + 行空板 智能门禁轻松实现图5

2.Arduino IDE 编程
主控板要选择“AI Thinker ESP32-CAM”
ESP EYE + 行空板 智能门禁轻松实现图6

3.利用示例“CameraWebServer”测试图传
ESP EYE + 行空板 智能门禁轻松实现图7

  1. #include "esp_camera.h"
  2. #include <WiFi.h>
  3. // ===================
  4. // Select camera model
  5. // ===================
  6. #define CAMERA_MODEL_ESP_EYE // Has PSRAM
  7. #include "camera_pins.h"
  8. // ===========================
  9. //输入你的wifi凭据
  10. // ===========================
  11. const char* ssid = "**********";
  12. const char* password = "**********";
  13. void startCameraServer();
  14. void setupLedFlash(int pin);
  15. void setup() {
  16.   Serial.begin(115200);
  17.   Serial.setDebugOutput(true);
  18.   Serial.println();
  19.   camera_config_t config;
  20.   config.ledc_channel = LEDC_CHANNEL_0;
  21.   config.ledc_timer = LEDC_TIMER_0;
  22.   config.pin_d0 = Y2_GPIO_NUM;
  23.   config.pin_d1 = Y3_GPIO_NUM;
  24.   config.pin_d2 = Y4_GPIO_NUM;
  25.   config.pin_d3 = Y5_GPIO_NUM;
  26.   config.pin_d4 = Y6_GPIO_NUM;
  27.   config.pin_d5 = Y7_GPIO_NUM;
  28.   config.pin_d6 = Y8_GPIO_NUM;
  29.   config.pin_d7 = Y9_GPIO_NUM;
  30.   config.pin_xclk = XCLK_GPIO_NUM;
  31.   config.pin_pclk = PCLK_GPIO_NUM;
  32.   config.pin_vsync = VSYNC_GPIO_NUM;
  33.   config.pin_href = HREF_GPIO_NUM;
  34.   config.pin_sccb_sda = SIOD_GPIO_NUM;
  35.   config.pin_sccb_scl = SIOC_GPIO_NUM;
  36.   config.pin_pwdn = PWDN_GPIO_NUM;
  37.   config.pin_reset = RESET_GPIO_NUM;
  38.   config.xclk_freq_hz = 20000000;
  39.   config.frame_size = FRAMESIZE_UXGA;
  40.   config.pixel_format = PIXFORMAT_JPEG; // for streaming
  41.   //config.pixel_format = PIXFORMAT_RGB565; // for face detection/recognition
  42.   config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
  43.   config.fb_location = CAMERA_FB_IN_PSRAM;
  44.   config.jpeg_quality = 12;
  45.   config.fb_count = 1;
  46.   
  47.   // if PSRAM IC present, init with UXGA resolution and higher JPEG quality
  48.   //                      for larger pre-allocated frame buffer.
  49.   if(config.pixel_format == PIXFORMAT_JPEG){
  50.     if(psramFound()){
  51.       config.jpeg_quality = 10;
  52.       config.fb_count = 2;
  53.       config.grab_mode = CAMERA_GRAB_LATEST;
  54.     } else {
  55.       // Limit the frame size when PSRAM is not available
  56.       config.frame_size = FRAMESIZE_SVGA;
  57.       config.fb_location = CAMERA_FB_IN_DRAM;
  58.     }
  59.   } else {
  60.     // Best option for face detection/recognition
  61.     config.frame_size = FRAMESIZE_240X240;
  62. #if CONFIG_IDF_TARGET_ESP32S3
  63.     config.fb_count = 2;
  64. #endif
  65.   }
  66. #if defined(CAMERA_MODEL_ESP_EYE)
  67.   pinMode(13, INPUT_PULLUP);
  68.   pinMode(14, INPUT_PULLUP);
  69. #endif
  70.   // camera init
  71.   esp_err_t err = esp_camera_init(&config);
  72.   if (err != ESP_OK) {
  73.     Serial.printf("Camera init failed with error 0x%x", err);
  74.     return;
  75.   }
  76.   sensor_t * s = esp_camera_sensor_get();
  77.   // initial sensors are flipped vertically and colors are a bit saturated
  78.   if (s->id.PID == OV3660_PID) {
  79.     s->set_vflip(s, 1); // flip it back
  80.     s->set_brightness(s, 1); // up the brightness just a bit
  81.     s->set_saturation(s, -2); // lower the saturation
  82.   }
  83.   // drop down frame size for higher initial frame rate
  84.   if(config.pixel_format == PIXFORMAT_JPEG){
  85.     s->set_framesize(s, FRAMESIZE_QVGA);
  86.   }
  87. #if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM)
  88.   s->set_vflip(s, 1);
  89.   s->set_hmirror(s, 1);
  90. #endif
  91. #if defined(CAMERA_MODEL_ESP32S3_EYE)
  92.   s->set_vflip(s, 1);
  93. #endif
  94. // Setup LED FLash if LED pin is defined in camera_pins.h
  95. #if defined(LED_GPIO_NUM)
  96.   setupLedFlash(LED_GPIO_NUM);
  97. #endif
  98.   WiFi.begin(ssid, password);
  99.   WiFi.setSleep(false);
  100.   while (WiFi.status() != WL_CONNECTED) {
  101.     delay(500);
  102.     Serial.print(".");
  103.   }
  104.   Serial.println("");
  105.   Serial.println("WiFi connected");
  106.   startCameraServer();
  107.   Serial.print("Camera Ready! Use 'http://");
  108.   Serial.print(WiFi.localIP());
  109.   Serial.println("' to connect");
  110. }
  111. void loop() {
  112.   // Do nothing. Everything is done in another task by the web server
  113.   delay(10000);
  114. }
复制代码
4.测试演示视频

【TCP图传】
1.ESP EYE使用“HTTPClient”库向行空板传送摄像头拍摄的图像。
  1. #include "esp_camera.h"
  2. #include <WiFi.h>
  3. #include <HTTPClient.h>
  4. // 用于上传照片的服务器地址,行空板IP地址
  5. const char *serverName = "http://192.168.31.71:9000/upload";
  6. // ===================
  7. // Select camera model
  8. #define CAMERA_MODEL_ESP_EYE // Has PSRAM
  9. #include "camera_pins.h"
  10. // ===========================
  11. // Enter your WiFi credentials
  12. // ===========================
  13. const char* ssid = "**********";
  14. const char* password = "***********";
  15. void setup() {
  16.   Serial.begin(115200);
  17.   Serial.setDebugOutput(true);
  18.   Serial.println();
  19.   camera_config_t config;
  20.   config.ledc_channel = LEDC_CHANNEL_0;
  21.   config.ledc_timer = LEDC_TIMER_0;
  22.   config.pin_d0 = Y2_GPIO_NUM;
  23.   config.pin_d1 = Y3_GPIO_NUM;
  24.   config.pin_d2 = Y4_GPIO_NUM;
  25.   config.pin_d3 = Y5_GPIO_NUM;
  26.   config.pin_d4 = Y6_GPIO_NUM;
  27.   config.pin_d5 = Y7_GPIO_NUM;
  28.   config.pin_d6 = Y8_GPIO_NUM;
  29.   config.pin_d7 = Y9_GPIO_NUM;
  30.   config.pin_xclk = XCLK_GPIO_NUM;
  31.   config.pin_pclk = PCLK_GPIO_NUM;
  32.   config.pin_vsync = VSYNC_GPIO_NUM;
  33.   config.pin_href = HREF_GPIO_NUM;
  34.   config.pin_sccb_sda = SIOD_GPIO_NUM;
  35.   config.pin_sccb_scl = SIOC_GPIO_NUM;
  36.   config.pin_pwdn = PWDN_GPIO_NUM;
  37.   config.pin_reset = RESET_GPIO_NUM;
  38.   config.xclk_freq_hz = 20000000;
  39.   config.frame_size = FRAMESIZE_UXGA;
  40.   config.pixel_format = PIXFORMAT_JPEG; // for streaming
  41.   //config.pixel_format = PIXFORMAT_RGB565; // for face detection/recognition
  42.   config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
  43.   config.fb_location = CAMERA_FB_IN_PSRAM;
  44.   config.jpeg_quality = 12;
  45.   config.fb_count = 1;
  46.   
  47.   // if PSRAM IC present, init with UXGA resolution and higher JPEG quality
  48.   //                      for larger pre-allocated frame buffer.
  49.   if(config.pixel_format == PIXFORMAT_JPEG){
  50.     if(psramFound()){
  51.       config.jpeg_quality = 10;
  52.       config.fb_count = 2;
  53.       config.grab_mode = CAMERA_GRAB_LATEST;
  54.     } else {
  55.       // Limit the frame size when PSRAM is not available
  56.       config.frame_size = FRAMESIZE_SVGA;
  57.       config.fb_location = CAMERA_FB_IN_DRAM;
  58.     }
  59.   } else {
  60.     // Best option for face detection/recognition
  61.     config.frame_size = FRAMESIZE_240X240;
  62. #if CONFIG_IDF_TARGET_ESP32S3
  63.     config.fb_count = 2;
  64. #endif
  65.   }
  66. #if defined(CAMERA_MODEL_ESP_EYE)
  67.   pinMode(13, INPUT_PULLUP);
  68.   pinMode(14, INPUT_PULLUP);
  69. #endif
  70.   // camera init
  71.   esp_err_t err = esp_camera_init(&config);
  72.   if (err != ESP_OK) {
  73.     Serial.printf("Camera init failed with error 0x%x", err);
  74.     return;
  75.   }
  76.   sensor_t * s = esp_camera_sensor_get();
  77.   // initial sensors are flipped vertically and colors are a bit saturated
  78.   if (s->id.PID == OV3660_PID) {
  79.     s->set_vflip(s, 1); // flip it back
  80.     s->set_brightness(s, 1); // up the brightness just a bit
  81.     s->set_saturation(s, -2); // lower the saturation
  82.   }
  83.   // drop down frame size for higher initial frame rate
  84.   if(config.pixel_format == PIXFORMAT_JPEG){
  85.     s->set_framesize(s, FRAMESIZE_QVGA);
  86.   }
  87. #if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM)
  88.   s->set_vflip(s, 1);
  89.   s->set_hmirror(s, 1);
  90. #endif
  91. #if defined(CAMERA_MODEL_ESP32S3_EYE)
  92.   s->set_vflip(s, 1);
  93. #endif
  94.   WiFi.begin(ssid, password);
  95.   WiFi.setSleep(false);
  96.   while (WiFi.status() != WL_CONNECTED) {
  97.     delay(500);
  98.     Serial.print(".");
  99.   }
  100.   Serial.println("");
  101.   Serial.println("WiFi connected");
  102. }
  103. void loop() {
  104. // 拍摄照片
  105.     camera_fb_t *fb = esp_camera_fb_get();
  106.     if (!fb)
  107.     {
  108.       Serial.println("获取摄像头帧缓冲失败");
  109.       return;
  110.     }
  111.     // 建立HTTP客户端
  112.     HTTPClient http;
  113.     // 将照片上传到服务器
  114.     http.begin(serverName);
  115.     http.addHeader("Content-Type", "image/jpeg");
  116.     int httpResponseCode = http.POST(fb->buf, fb->len);
  117.     if (httpResponseCode > 0)
  118.     {
  119.       Serial.printf("照片上传成功,服务器返回代码:%d\n", httpResponseCode);
  120.       // 再闪一下提示上传成功
  121.   
  122.     }
  123.     else
  124.     {
  125.       Serial.printf("照片上传失败,错误代码:%s\n", http.errorToString(httpResponseCode).c_str());
  126.     }
  127.     http.end();
  128.     // 释放帧缓冲
  129.     esp_camera_fb_return(fb);
  130. }
复制代码


2.行空板使用“flask”库,接收图像并在屏幕上显示

  1. from flask import Flask, request
  2. from unihiker import GUI
  3. u_gui=GUI()
  4. 显图=u_gui.draw_image(image="base.png",h=320,x=0,y=0)
  5. app = Flask(__name__)
  6. @app.route('/upload', methods=['POST'])
  7. def upload():
  8.     try:
  9.         image = request.data
  10.         # 保存照片到指定目录
  11.       
  12.         with open('base.png', 'wb') as f:
  13.             f.write(image)
  14.             f.close()
  15.         
  16.         显图.config(image="base.png")
  17.         
  18.         return "照片上传成功", 200
  19.     except Exception as e:
  20.         print("照片上传失败:", str(e))
  21.         return "照片上传失败", 500
  22. if __name__ == '__main__':
  23.     app.run(host='192.168.31.71', port=9000)
复制代码


【物联网开关】
使用行空板A、B键,利用Easy IOT物联网平台向ESP EYE发送开启或关闭发送图像的指令。

1.ESP EYE 物联网测试程序

  1. /*
  2.   SimpleMQTTClient.ino
  3.   The purpose of this exemple is to illustrate a simple handling of MQTT and Wifi connection.
  4.   Once it connects successfully to a Wifi network and a MQTT broker, it subscribe to a topic and send a message to it.
  5.   It will also send a message delayed 5 seconds later.
  6. */
  7. #include "EspMQTTClient.h"
  8. EspMQTTClient client(
  9.   "sxs",
  10.   "smj080823",
  11.   "182.254.130.180",  // MQTT Broker server ip
  12.   "X8jykxFnR",   // Can be omitted if not needed
  13.   "u8jskbFngz",   // Can be omitted if not needed
  14.   "yuntian365",     // Client name that uniquely identify your device
  15.   1883              // The MQTT port, default to 1883. this line can be omitted
  16. );
  17. void setup()
  18. {
  19.   Serial.begin(115200);
  20.   // Optional functionalities of EspMQTTClient
  21.   client.enableDebuggingMessages(); // Enable debugging messages sent to serial output
  22.   client.enableHTTPWebUpdater(); // Enable the web updater. User and password default to values of MQTTUsername and MQTTPassword. These can be overridded with enableHTTPWebUpdater("user", "password").
  23.   client.enableOTA(); // Enable OTA (Over The Air) updates. Password defaults to MQTTPassword. Port is the default OTA port. Can be overridden with enableOTA("password", port).
  24.   client.enableLastWillMessage("MNpA1p_4R", "I am going offline");  // You can activate the retain flag by setting the third parameter to true
  25. }
  26. // This function is called once everything is connected (Wifi and MQTT)
  27. // WARNING : YOU MUST IMPLEMENT IT IF YOU USE EspMQTTClient
  28. void onConnectionEstablished()
  29. {
  30.   // Subscribe to "mytopic/wildcardtest/#" and display received message to Serial
  31.   client.subscribe("1DXAmWJ4g", [](const String & topic, const String & payload) {
  32.     Serial.println("(From wildcard) topic: " + topic + ", payload: " + payload);
  33.   });
  34.   // Publish a message to "mytopic/test"
  35.   client.publish("k_eT7HUVR", "This is a message"); // You can activate the retain flag by setting the third parameter to true
  36.   // Execute delayed instructions
  37.   client.executeDelayed(5 * 1000, []() {
  38.     client.publish("k_eT7HUVR", "This is a message sent 5 seconds later");
  39.   });
  40. }
  41. void loop()
  42. {
  43.   client.loop();
  44. }
复制代码

【行空板完整程序】
行空板连接物联网及接收图传完整程序
  1. from flask import Flask, request
  2. from unihiker import GUI
  3. import siot
  4. import time
  5. u_gui=GUI()
  6. i=0
  7. 显图=u_gui.draw_image(image="base.png",h=320,x=0,y=0)
  8. app = Flask(__name__)
  9. @app.route('/upload', methods=['POST'])
  10. def upload():
  11.     try:
  12.         image = request.data
  13.         # 保存照片到指定目录
  14.       
  15.         with open('base.png', 'wb') as f:
  16.             f.write(image)
  17.             f.close()
  18.         
  19.         显图.config(image="base.png")
  20.         
  21.         return "照片上传成功", 200
  22.     except Exception as e:
  23.         print("照片上传失败:", str(e))
  24.         return "照片上传失败", 500
  25. # 事件回调函数
  26. def on_buttona_click_callback():
  27.     global i
  28.     if i==0:
  29.        i=1
  30.        siot.publish(topic="1DXAmWJ4g", data="a")
  31. # 事件回调函数
  32. def on_buttonb_click_callback():
  33.     global i
  34.     if i==1:
  35.        i=0
  36.        siot.publish(topic="1DXAmWJ4g", data="b")
  37. if __name__ == '__main__':
  38.     siot.init(client_id="yuntian367",server="iot.dfrobot.com.cn",port=1883,user="X8jykxFnR",password="u8jskbFngz")
  39.     siot.connect()
  40.     siot.loop()
  41.    
  42.     u_gui.on_a_click(on_buttona_click_callback)
  43.     u_gui.on_b_click(on_buttonb_click_callback)
  44.     app.run(host='192.168.31.71', port=9000)
  45.    
复制代码


【ESP EYE完整程序】
接收物联网指令,向行空板图传。
  1. #include "esp_camera.h"
  2. #include <WiFi.h>
  3. #include <HTTPClient.h>
  4. // 用于上传照片的服务器地址,行空板IP地址
  5. const char *serverName = "http://192.168.31.71:9000/upload";
  6. // ===================
  7. // Select camera model
  8. #define CAMERA_MODEL_ESP_EYE // Has PSRAM
  9. #include "camera_pins.h"
  10. #include "EspMQTTClient.h"
  11. EspMQTTClient client(
  12.   "sxs",
  13.   "smj080823",
  14.   "182.254.130.180",  // MQTT Broker server ip
  15.   "X8jykxFnR",   // Can be omitted if not needed
  16.   "u8jskbFngz",   // Can be omitted if not needed
  17.   "yuntian365",     // Client name that uniquely identify your device
  18.   1883              // The MQTT port, default to 1883. this line can be omitted
  19. );
  20. // ===========================
  21. // Enter your WiFi credentials
  22. // ===========================
  23. const char* ssid = "sxs";
  24. const char* password = "smj080823";
  25. int bs;
  26. void setup() {
  27.   Serial.begin(115200);
  28.   Serial.setDebugOutput(true);
  29.   Serial.println();
  30.   camera_config_t config;
  31.   config.ledc_channel = LEDC_CHANNEL_0;
  32.   config.ledc_timer = LEDC_TIMER_0;
  33.   config.pin_d0 = Y2_GPIO_NUM;
  34.   config.pin_d1 = Y3_GPIO_NUM;
  35.   config.pin_d2 = Y4_GPIO_NUM;
  36.   config.pin_d3 = Y5_GPIO_NUM;
  37.   config.pin_d4 = Y6_GPIO_NUM;
  38.   config.pin_d5 = Y7_GPIO_NUM;
  39.   config.pin_d6 = Y8_GPIO_NUM;
  40.   config.pin_d7 = Y9_GPIO_NUM;
  41.   config.pin_xclk = XCLK_GPIO_NUM;
  42.   config.pin_pclk = PCLK_GPIO_NUM;
  43.   config.pin_vsync = VSYNC_GPIO_NUM;
  44.   config.pin_href = HREF_GPIO_NUM;
  45.   config.pin_sccb_sda = SIOD_GPIO_NUM;
  46.   config.pin_sccb_scl = SIOC_GPIO_NUM;
  47.   config.pin_pwdn = PWDN_GPIO_NUM;
  48.   config.pin_reset = RESET_GPIO_NUM;
  49.   config.xclk_freq_hz = 20000000;
  50.   config.frame_size = FRAMESIZE_UXGA;
  51.   config.pixel_format = PIXFORMAT_JPEG; // for streaming
  52.   //config.pixel_format = PIXFORMAT_RGB565; // for face detection/recognition
  53.   config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
  54.   config.fb_location = CAMERA_FB_IN_PSRAM;
  55.   config.jpeg_quality = 12;
  56.   config.fb_count = 1;
  57.   
  58.   // if PSRAM IC present, init with UXGA resolution and higher JPEG quality
  59.   //                      for larger pre-allocated frame buffer.
  60.   if(config.pixel_format == PIXFORMAT_JPEG){
  61.     if(psramFound()){
  62.       config.jpeg_quality = 10;
  63.       config.fb_count = 2;
  64.       config.grab_mode = CAMERA_GRAB_LATEST;
  65.     } else {
  66.       // Limit the frame size when PSRAM is not available
  67.       config.frame_size = FRAMESIZE_SVGA;
  68.       config.fb_location = CAMERA_FB_IN_DRAM;
  69.     }
  70.   } else {
  71.     // Best option for face detection/recognition
  72.     config.frame_size = FRAMESIZE_240X240;
  73. #if CONFIG_IDF_TARGET_ESP32S3
  74.     config.fb_count = 2;
  75. #endif
  76.   }
  77. #if defined(CAMERA_MODEL_ESP_EYE)
  78.   pinMode(13, INPUT_PULLUP);
  79.   pinMode(14, INPUT_PULLUP);
  80. #endif
  81.   // camera init
  82.   esp_err_t err = esp_camera_init(&config);
  83.   if (err != ESP_OK) {
  84.     Serial.printf("Camera init failed with error 0x%x", err);
  85.     return;
  86.   }
  87.   sensor_t * s = esp_camera_sensor_get();
  88.   // initial sensors are flipped vertically and colors are a bit saturated
  89.   if (s->id.PID == OV3660_PID) {
  90.     s->set_vflip(s, 1); // flip it back
  91.     s->set_brightness(s, 1); // up the brightness just a bit
  92.     s->set_saturation(s, -2); // lower the saturation
  93.   }
  94.   // drop down frame size for higher initial frame rate
  95.   if(config.pixel_format == PIXFORMAT_JPEG){
  96.     s->set_framesize(s, FRAMESIZE_QVGA);
  97.   }
  98. #if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM)
  99.   s->set_vflip(s, 1);
  100.   s->set_hmirror(s, 1);
  101. #endif
  102. #if defined(CAMERA_MODEL_ESP32S3_EYE)
  103.   s->set_vflip(s, 1);
  104. #endif
  105.   WiFi.begin(ssid, password);
  106.   WiFi.setSleep(false);
  107.   while (WiFi.status() != WL_CONNECTED) {
  108.     delay(500);
  109.     Serial.print(".");
  110.   }
  111.   Serial.println("");
  112.   Serial.println("WiFi connected");
  113.   bs=0;
  114.   client.enableDebuggingMessages(); // Enable debugging messages sent to serial output
  115.   client.enableHTTPWebUpdater(); // Enable the web updater. User and password default to values of MQTTUsername and MQTTPassword. These can be overridded with enableHTTPWebUpdater("user", "password").
  116.   client.enableOTA(); // Enable OTA (Over The Air) updates. Password defaults to MQTTPassword. Port is the default OTA port. Can be overridden with enableOTA("password", port).
  117.   client.enableLastWillMessage("MNpA1p_4R", "I am going offline");  // You can activate the retain flag by setting the third parameter to true
  118. }
  119. void onConnectionEstablished()
  120. {
  121.   // Subscribe to "mytopic/wildcardtest/#" and display received message to Serial
  122.   client.subscribe("1DXAmWJ4g", [](const String & topic, const String & payload) {
  123.     Serial.println("(From wildcard) topic: " + topic + ", payload: " + payload);
  124.     if(payload=="a"){
  125.       bs=1;
  126.     }
  127.     if(payload=="b"){
  128.       bs=0;
  129.     }
  130.   });
  131.   // Publish a message to "mytopic/test"
  132.   client.publish("k_eT7HUVR", "This is a message"); // You can activate the retain flag by setting the third parameter to true
  133.   // Execute delayed instructions
  134.   client.executeDelayed(5 * 1000, []() {
  135.     client.publish("k_eT7HUVR", "This is a message sent 5 seconds later");
  136.   });
  137. }
  138. void loop() {
  139.   if(bs==1){
  140. // 拍摄照片
  141.     camera_fb_t *fb = esp_camera_fb_get();
  142.     if (!fb)
  143.     {
  144.       Serial.println("获取摄像头帧缓冲失败");
  145.       return;
  146.     }
  147.     // 建立HTTP客户端
  148.     HTTPClient http;
  149.     // 将照片上传到服务器
  150.     http.begin(serverName);
  151.     http.addHeader("Content-Type", "image/jpeg");
  152.     int httpResponseCode = http.POST(fb->buf, fb->len);
  153.     if (httpResponseCode > 0)
  154.     {
  155.       Serial.printf("照片上传成功,服务器返回代码:%d\n", httpResponseCode);
  156.       // 再闪一下提示上传成功
  157.    
  158.     }
  159.     else
  160.     {
  161.       Serial.printf("照片上传失败,错误代码:%s\n", http.errorToString(httpResponseCode).c_str());
  162.     }
  163.     http.end();
  164.     // 释放帧缓冲
  165.     esp_camera_fb_return(fb);
  166.   }
  167.    client.loop();
  168. }
复制代码
【数字“猫眼”】利用充电宝为行空板及ESP EYE供电,ESP EYE放置在门外摄像,行空板放置在门内查看视频图像。
ESP EYE + 行空板 智能门禁轻松实现图3



ESP EYE + 行空板 智能门禁轻松实现图2

【演示视频】


花生编程  中级技匠

发表于 2023-8-29 17:10:39

厉害厉害!大神又更新了!
回复

使用道具 举报

花生编程  中级技匠

发表于 2023-8-29 17:11:53

好棒啊!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail