随着各大城市早晚高峰拥挤越来越严重,电动自行车(助力车)(以下统一简称电动车)也越来越备受人们喜爱。近年来,我国电动车年销量超过3000万辆,社会保有量接近3亿辆。
然后,近年来电动车火灾也成为火灾重灾区。2021年1月至10月,全国发生电动车及其电池故障引发的火灾共1.4万余起,死亡41人,受伤157人。2022年全国共接报电动车火灾1.8万起,同比去年上升23.4%。
1 项目背景
通过查阅资料与调研,我们了解到电动车火灾具有火势发展迅猛、火焰火场温度高、有毒烟气大、烟气传播快、火情发现难、救灾难度大、火灾危害性大等特点。
电动车着火30秒,大量浓烟和有毒烟气会以1米 / 秒的速度迅速充斥整个房间。3分钟后,火焰温度可达1200℃。人一旦吸入3至5口高温毒气就会昏迷。一台电动车燃烧产生的毒气足以杀死成百上千人。
2 功能介绍
本系统主要功能包括:电动车电池充电、独立防火分区功能、火灾报警、消防联动、自动灭火。
充电功能:对电动车电池的自动充电,可显示电量信息。
独立防火分区功能:每块电动车电池都使用独立防火分区,材质采用不燃材料。
火灾报警功能:是通过烟雾传感器、温湿度传感器、摄像头对电动车火灾进行探测,并通过现场
声光报警器进行声光报警,同时将火警信号传至控制中心。
消防联动功能:实现在接到火警信号后,切除充电电源、照明电源的强电功能。
自动灭火功能:实现在接到火警后,自动喷水灭火。
联网功能:实现连接互联网,可实现充电远程监管,远程监控火警,查看火情等功能。
无线视频监控功能:ESP32-S3采集柜内视频,无线传输至行空板、SIOT,并在可视化平台显示。
3 硬件
4 设计图
5 接线图
6 实物接线图
行空板、SCI及传感器
FireBeetle 2 Board ESP32-S3与摄像头
7 SIOT
8 流程图
9 行空板端程序——图形化
10 行空板端程序——Python代码
#include "esp_camera.h"
#include <WiFi.h>
//
// WARNING!!! PSRAM IC required for UXGA resolution and high JPEG quality
// Ensure ESP32 Wrover Module or other board with PSRAM is selected
// Partial images will be transmitted if image exceeds buffer size
//
// You must select partition scheme from the board menu that has at least 3MB APP space.
// Face Recognition is DISABLED for ESP32 and ESP32-S2, because it takes up from 15
// seconds to process single frame. Face Detection is ENABLED if PSRAM is enabled as well
// ===================
// 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_AI_THINKER // Has PSRAM
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
//#define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM
#define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAN
// ** Espressif Internal Boards **
//#define CAMERA_MODEL_ESP32_CAM_BOARD
//#define CAMERA_MODEL_ESP32S2_CAM_BOARD
//#define CAMERA_MODEL_ESP32S3_CAM_LCD
#include "camera_pins.h"
#include "DFRobot_AXP313A.h"
DFRobot_AXP313A axp;
// ===========================
// Enter your WiFi credentials
// ===========================
const char* ssid = "xiaogui";
const char* password = "88888888";
void startCameraServer();
void setupLedFlash(int pin);
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
Serial.println();
while(axp.begin() != 0){
Serial.println("init error");
delay(1000);
}
axp.enableCameraPower(axp.eOV2640);//设置摄像头供电
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_UXGA;
config.pixel_format = PIXFORMAT_JPEG; // for streaming
//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 PSRAM IC present, init with UXGA resolution and higher JPEG quality
// for larger pre-allocated frame buffer.
if(config.pixel_format == PIXFORMAT_JPEG){
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;
}
} else {
// Best option for face detection/recognition
config.frame_size = FRAMESIZE_240X240;
#if CONFIG_IDF_TARGET_ESP32S3
config.fb_count = 2;
#endif
}
#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
if(config.pixel_format == PIXFORMAT_JPEG){
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
#if defined(CAMERA_MODEL_ESP32S3_EYE)
s->set_vflip(s, 1);
#endif
// Setup LED FLash if LED pin is defined in camera_pins.h
#if defined(LED_GPIO_NUM)
setupLedFlash(LED_GPIO_NUM);
#endif
Serial.println("Connect to WiFi");
WiFi.begin(ssid, password);
WiFi.setSleep(false);
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() {
// Do nothing. Everything is done in another task by the web server
delay(10000);
}
11 FireBeetle 2 Board ESP32-S3端Arduino程序
# -*- coding: UTF-8 -*-
# MindPlus
# Python
import sys
sys.path.append("/root/mindplus/.lib/thirdExtension/liliang-gravitysci-thirdex")
from dfrobot_rp2040_sci import *
import base64
from io import BytesIO
from PIL import Image
from pinpong.libs.dfrobot_pn532 import PN532_I2C
from pinpong.extension.unihiker import *
from pinpong.board import Board,Pin
from pinpong.board import Board
import siot
import time
import cv2
# 自定义函数
def ShengGuangBaoJing():
buzzer.play(buzzer.RINGTONE,buzzer.Once)
def HuoJingTanCe():
mq2 = p_p21_analog.read_analog()
temp = SCI1.get_valueFloat1(SCI1.ePort3,"Temp_Air")
siot.publish_save(topic="siot/temp", data=temp)
siot.publish_save(topic="siot/mq2", data=mq2)
if ((mq2 <= mq2_fire) or (temp >= temp_fire)):
is_fire = 'Ture'
ShengGuangBaoJing()
siot.publish_save(topic="siot/fire", data="火警")
else:
siot.publish_save(topic="siot/fire", data="正常")
def NFCShuaKaJianCe():
if p_nfc.scan():
print(p_nfc.read_uid())
siot.publish_save(topic="siot/nfc_time", data=time.time())
if p_nfc.scan("4978ef9c"):
siot.publish_save(topic="siot/allow", data=p_nfc.scan("4978ef9c"))
buzzer.play(buzzer.POWER_UP,buzzer.Once)
KaiDianCiSuo()
else:
siot.publish_save(topic="siot/forbid", data=p_nfc.scan("4978ef9c"))
buzzer.play(buzzer.POWER_DOWN,buzzer.Once)
def KaiDianCiSuo():
if (p_p24_in.read_digital()==True):
p_p22_out=Pin(Pin.P22, Pin.OUT)
p_p22_out.write_digital(1)
time.sleep(3)
p_p22_out=Pin(Pin.P22, Pin.OUT)
p_p22_out.write_digital(0)
siot.publish_save(topic="siot/lock", data="已打开")
else:
siot.publish_save(topic="siot/lock", data="已关闭")
def ChongDian():
if (is_charge == 'Ture'):
p_p23_out=Pin(Pin.P23, Pin.OUT)
p_p23_out.write_digital(1)
else:
p_p23_out=Pin(Pin.P23, Pin.OUT)
p_p23_out.write_digital(0)
def CCTV01Gui():
if vd.isOpened():
while not (False):
ret, img = vd.read()
cv2.imshow("Press ESC to exit", img)
siot.publish_save(topic="siot/CCTV01", data=base642base64(img))
if cv2.waitKey(10) & 0xff== 27:
break
vd.release()
cv2.destroyAllWindows()
# 事件回调函数
def on_message_callback(client, userdata, msg):
if (msg.topic == (str("siot/light01"))):
if (msg.payload.decode() == (str("on"))):
p_p25_out=Pin(Pin.P25, Pin.OUT)
p_p25_out.write_digital(1)
else:
p_p25_out=Pin(Pin.P25, Pin.OUT)
p_p25_out.write_digital(0)
Board().begin()
siot.init(client_id="654528767695614",server="10.1.2.3",port=1883,user="siot",password="dfrobot")
p_p21_analog=Pin(Pin.P21, Pin.ANALOG)
p_p24_in=Pin(Pin.P24, Pin.IN)
siot.connect()
siot.loop()
siot.set_callback(on_message_callback)
mq2 = (str("http://192.168.2.234:81/stream"))
mq2_fire = 100
temp_fire = 50
is_fire = 'Flase'
is_charge = 'Flase'
siot.getsubscribe(topic="siot/light01")
SCI1 = DFRobot_RP2040_SCI_IIC(addr=0x21)
while SCI1.begin() != 0:
print("Initialization Sensor Universal Adapter Board failed.")
time.sleep(1)
print("Initialization Sensor Universal Adapter Board done.")
p_nfc = PN532_I2C()
p_nfc.begin()
def frame2base64(frame):
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
img = Image.fromarray(frame) #将每一帧转为Image
output_buffer = BytesIO() #创建一个BytesIO
img.save(output_buffer, format='JPEG') #写入output_buffer
byte_data = output_buffer.getvalue() #在内存中读取
base64_data = base64.b64encode(byte_data) #转为BASE64
return base64_data #转码成功 返回base64编码
def base642base64(frame):
data=str('data:image/png;base64,')
base64data = str(frame2base64(frame))
framedata = base64data[2:(len(base64data)-1)]
base642base64_data = data + str(framedata)
return base642base64_data
vd = cv2.VideoCapture()
vd.open(mq2)
while True:
NFCShuaKaJianCe()
HuoJingTanCe()
ChongDian()
CCTV01Gui()
12 可视化界面
孙洪尧19852024.07.26
电池失火能用水灭火吗?
hacker_2023.08.28
666