如何通过低成本手搓一个监控摄像头呢?本文为大家介绍,基于
ESP32
模组的ESP32-CAM
开发板提供了一种低成本的无线摄像头实现方式。
关于ESP32-CAM
我们常用的模块为ESP8266
,相信大家都很熟悉了。但ESP32比8266强多了。具体信息如下:
设备清单
-
ESP32-CAM -
OV2640摄像头 -
USB转UART烧录器,或者直接购买转接板。
配置环境
安装esp32
开发板环境。(强烈建议挂代理)
选择开发板
选择示例代码
修改部分代码
-
修改代码中的WiFi相关信息 -
修改 define CAMERA_MODEL_AI_THINKER
删掉前面的注释,将默认的注释掉。
完整代码
#include "esp_camera.h"
#include <WiFi.h>
#define CAMERA_MODEL_AI_THINKER // Has PSRAM
#include "camera_pins.h"
const char* ssid = "PDCN";
const char* password = "1234567890";
void startCameraServer();
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
Serial.println();
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
config.pin_href = HREF_GPIO_NUM;
config.pin_sscb_sda = SIOD_GPIO_NUM;
config.pin_sscb_scl = SIOC_GPIO_NUM;
config.pin_pwdn = PWDN_GPIO_NUM;
config.pin_reset = RESET_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
// if PSRAM IC present, init with UXGA resolution and higher JPEG quality
// for larger pre-allocated frame buffer.
if(psramFound()){
config.frame_size = FRAMESIZE_UXGA;
config.jpeg_quality = 10;
config.fb_count = 2;
} else {
config.frame_size = FRAMESIZE_SVGA;
config.jpeg_quality = 12;
config.fb_count = 1;
}
#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
}
// drop down frame size for higher initial frame rate
s->set_framesize(s, FRAMESIZE_QVGA);
#if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM)
s->set_vflip(s, 1);
s->set_hmirror(s, 1);
#endif
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
startCameraServer();
Serial.print("Camera Ready! Use 'http://");
Serial.print(WiFi.localIP());
Serial.println("' to connect");
}
void loop() {
// put your main code here, to run repeatedly:
delay(10000);
}
烧录完成后,打开串口,或者在路由器中,查看IP地址。
访问IP如下
接入HA
如果esp32和你的HA主机在同一个局域网,直接访问即可。如果不在同一个局域网,需要用FRP做映射。 通过,审查元素,我们发现是stream
流。
<img id="stream" src="http://192.168.123.78:81/stream">
因此,直接上链接! 打开HA,添加图片实体。
设置图片的地址:
最终效果
总结
优点:价格亲民,上手即用!
不足:实测要靠近路由器,传输效果较好。离路由器较远,传输能力弱。比较卡顿!
原文始发于微信公众号(kali笔记):手搓监控摄像头 并接入HA
- 左青龙
- 微信扫一扫
- 右白虎
- 微信扫一扫
评论