IoT-based access control and attendance system_Alibaba Cloud_2022

1 Introduction

Today's society is an information age in which science and technology are changing rapidly and developing rapidly. People are feeling the great convenience and benefits brought by high technology, and at the same time, people have higher and higher requirements for high technology to serve life. But with the development of technology, it also brings many unsafe aspects. For example, the use of high-tech means to commit crimes such as theft, robbery and espionage is increasing day by day. How can people's safety precautions keep up with the development of science and technology and prevent the violation of these criminal acts more effectively? It is not enough to rely only on ordinary door locks, anti-theft doors or monitoring and alarm systems. Therefore, the intelligent access control attendance check-in system based on the Internet of Things came into being in the long-awaited.

The traditional door lock is just a simple fit mechanism, no matter how complex and sturdy its structure is, a key that can be prepared on the street can be opened without leaving traces. If the key is lost, the door lock should also be replaced together. In order to make up for these shortcomings, a magnetic card access control system has been produced. Using the magnetic card to control the lock, various performances have been improved, but due to the small amount of information stored by the magnetic stripe, mechanical wear is likely to occur between the magnetic card and the card reader, and the card reader's swipe port is easily damaged. performance and reliability are limited. With the development of modern economic construction and management, all kinds of hotels, guesthouses, office buildings, intelligent buildings, government agencies, enterprises and institutions, and senior property management departments are undergoing major changes in the demand for access control systems. The lock and its opening and closing realize intelligent management.

After in-depth analysis of the development status and social needs of the domestic security access control check-in system, and under the spring breeze of the Internet of Things, starting from low cost and low power consumption, using the STM32 chip to build an Internet of Things-based access control and check-in management system to help People quickly solve the problems of access control unlocking and sign-in identity records in the life of cherishing time.

image-20220510103809030

image-20220510103817063

image-20220510103824461

image-20220510103846498

image-20220510103904657

image-20220510103919244

image-20220511091108397

image-20220511091124386

image-20220511091141418

image-20220511091157086

If you need project information, you can download it here:
https://download.csdn.net/download/xiaolong1126626497/85898161

2. Function Summary

This topic designs an access control and attendance management system based on the Internet of Things, which has two aspects: access control and attendance.

1. Realize fingerprint, radio frequency card, password to open door, and data can be reported to the cloud at the same time

2. Remotely check the information when opening the door through WeChat, and record the entry and exit of the access control

3. The applet can also remotely control the door

4. Environmental detection, display environmental information such as temperature and humidity of the access control position

5. Realize the check-in function, and the WeChat terminal displays the check-in information

Technical implementation ideas and function summary:

The MCU selects the STM32F103RCT6 minimum system board. The whole system supports 4 unlocking methods: fingerprint unlocking, IC card swiping card unlocking, matrix keyboard inputting password unlocking, and web page remote button unlocking. . In order to facilitate remote access to the access control, the Alibaba Cloud IoT platform is used as the cloud platform server, and the local device uploads the collected temperature and humidity information and the ID of the access control to the Alibaba Cloud webpage through the ESP8266 for real-time display.

Required hardware:

(1) STM32F103RCT6 minimum system board + an LCD display

(2) AS608 photoelectric fingerprint module

(3) Relay module

(4) Matrix keyboard

(5) DHT11 temperature and humidity module

(6) ESP8266 serial port WIFI

(7) RC522 credit card module

3. Hardware selection

3.1 Capacitive keyboard

image-20220430220134160

3.2 STM32 development board

The core specification of STM32F103RCT6 is 32 bits, the speed is 72MHz, the program memory capacity is 256KB, the program memory type is FLASH, and the RAM capacity is 48K.

3.3 PCB hole board

image-20220411155607391

3.4 Female to Female Dupont Wire

image-20220508144610296

3.5 ESP8266 WIFI

image-20220427093036646

ESP8266 is an IoT WiFi chip. Based on ESP8266, IoT serial port WiFi module can be developed. Like SKYLAB's WG219/WG229, it is specially designed for mobile devices and IoT applications. It can connect the user's physical device to the WiFi wireless network for Internet access. Or LAN communication to achieve networking functions.

ESP8266,专为移动设备、可穿戴电子产品和物联网应用而设计,通过多项专有技术实现了超低功耗。ESP8266EX 具有的省电模式适用于各种低功耗应用场景。

ESP8266内置超低功耗 Tensilica L106 32 位 RISC 处理器,CPU 时钟速度最高可达 160 MHz,支持实时操作系统 (RTOS) 和 Wi-Fi 协议栈,可将高达 80% 的处理能力留给应用编程和开发。

3.6 Relay Module

image-20220510104241809

3.7 DHT11 temperature and humidity module

image-20220414200340347

3.8 AS608 Fingerprint Module

This fingerprint module has colorful breathing lights, the interface is SH1.0-6P, and there are 3 types of fingerprint capacity, namely 50 pieces, 100 pieces and 300 pieces. Different capacities have different prices.

It has the characteristics of small size, low power consumption, simple interface, high reliability, fast recognition speed, good adaptability to wet and dry fingers, and fast fingerprint search speed. When the fingerprint image is read, it has a sensitive response and judgment to dry and wet fingers, and obtains the best image quality, which is suitable for a wide range of people. The self-learning and adaptive function can also be customized to automatically adjust parameters according to changes in the user's habits and climate to achieve a better match. It has the function of self-learning. During the fingerprint identification process, the new fingerprint feature value is extracted and fused into the previous fingerprint feature after successful identification. The more it is used, the better it is used in actual use. The module also has the function of sensing the finger. When the finger is pressed on the fingerprint collection surface, the touch pin of the module outputs a high level. The communication interface of the module is a UART communication interface. As a slave device, the module is controlled by the master device by sending relevant commands. The module has adjustable security level function, fingerprint feature data read/write function.

image-20220429114402319

image-20220429114504045

image-20220429114610307

**Note: **Fingerprint module has two power inputs, Vsen is to supply power to the sensor, VDD is to supply power to the main control chip DSP, that is, the fingerprint module is mainly composed of the fingerprint sensor Sensor and the main control chip DSP. At the beginning of powering on the whole system (such as battery power supply), the two power supplies must be powered at the same time, let the DSP initialize the Sensor for at least 200ms, and then turn off the main control chip power supply VDD. The initialization has a main step, which is to initialize the touch sensing function of the sensor, so that the touch signal Touch can be output normally.

4. Create an Alibaba Cloud device

4.1 Create a product

Official website address: https://iot.console.aliyun.com/lk/summary/new

If you do not have an account, you need to register an account first, and log in after real-name authentication.

Open a public instance first.

image-20220509131438331

image-20220509131626536

image-20220509131936096

4.2 Defining the Object Model

Address: https://iot.console.aliyun.com/product/createProduct

image-20220509132031783

The object model is the type of data uploaded by the device, and you can add the attributes that need to be uploaded on your own device.

image-20220509132127690

Click Add custom function to add the properties you need.

image-20220509132258560

**At present, there are 4 data uploaded by the device: **Ambient temperature, ambient humidity, fingerprint ID of the person who signed in or opened the door, and swipe ID of the person who signed in or opened the door.

image-20220509132705918

image-20220509132933917

image-20220509133052862

image-20220509133218874

image-20220509133250886

image-20220509145226825

image-20220509145238154

Finally, click Publish.

image-20220509135537270

image-20220509135606795

image-20220509135648171

Object model:

{
    
    
  "properties": [
    {
    
    
      "identifier": "DHT11_T",
      "dataType": {
    
    
        "type": "int"
      }
    },
    {
    
    
      "identifier": "DHT11_H",
      "dataType": {
    
    
        "type": "int"
      }
    },
    {
    
    
      "identifier": "TOUCH_ID",
      "dataType": {
    
    
        "type": "int"
      }
    },
    {
    
    
      "identifier": "CARD_ID",
      "dataType": {
    
    
        "type": "text"
      }
    },
    {
    
    
      "identifier": "motor",
      "dataType": {
    
    
        "type": "int"
      }
    }
  ]
}

4.3 Create device

image-20220509133503732

image-20220509133516883

Save the device information, and then use it to generate MQTT login parameters.

{
    
    
  "ProductKey": "h7s8JDdEcH3",
  "DeviceName": "133K0VSu2G9y6XEFBlUb",
  "DeviceSecret": "b2449f7fbc02c92fbbf7f86d7bac84cd"
}

image-20220509133627282

4.4 MQTT client reporting data

Official documentation on the parameters required for MQTT protocol login: https://help.aliyun.com/document_detail/140507.html?spm=a2c4g.11186623.6.571.1e417544OGPj2y

image-20220430121334790

(1) MQTT login address

MQTT登录域名的格式:
${
    
    YourProductKey}.iot-as-mqtt.${
    
    YourRegionId}.aliyuncs.com

其中:
${
    
    YourProductKey}:请替换为设备所属产品的ProductKey
${
    
    YourRegionId}:请替换为物联网平台设备所在地域代码。

下面是阿里云国内的服务器地域和可用区详情:

 
地域名称	所在城市	Region ID	可用区数量
华北 1	青岛	cn-qingdao	    2
华北 2	北京	cn-beijing	    10
华北 3	张家口	cn-zhangjiakou	3
华北 5	呼和浩特	cn-huhehaote	2
华北 6	乌兰察布	cn-wulanchabu	3
华东 1	杭州	cn-hangzhou	    8
华东 2	上海	cn-shanghai  	8
华南 1	深圳	cn-shenzhen   	6
华南 2	河源	cn-heyuan	    2
华南 3	广州	cn-guangzhou	2
西南 1	成都	cn-chengdu	    2

端口号是:1883

经过上面的格式解释,我的阿里云服务器登录的域名就是(选择的是上海服务器):h7s8JDdEcH3.iotas-mqtt.cn-shanghai.aliyuncs.com

域名对应的IP地址(动态解析出来的):  101.133.196.97

在线解析域名网站:https://site.ip138.com/a1cMlEwEwjg.iot-as-mqtt.cn-shanghai.aliyuncs.com/

image-20220325131621769

(2) MQTT login parameters

(1) MQTT_ClientID
固定格式:${
    
    ClientID}|securemode=${
    
    Mode},signmethod=${
    
    SignMethod}|

参数说明:
${
    
    ClientId}:  设备ID,一般填设备的硬件编号。我这里就直接填当前的设备名称,后面的密码里也要填这个ID,必须一样就行。(设备名称就是创建设备的时候复制出来3个参数里的设备名称)
securemode=3:TCP直连模式,无需设置SSL/TLS信息。
securemode=2:TLS直连模式,需要设置SSL/TLS信息。
${
    
    SignMethod}:算法类型,支持hmacmd5和hmacsha1。

示例:
当前我的设备名称是:133K0VSu2G9y6XEFBlUb ,选择TCP直连模式,选择hmacsha1算法类型。

那么我的ClientID就是:
133K0VSu2G9y6XEFBlUb|securemode=3,signmethod=hmacsha1|

(2) MQTT_UserName
固定格式:${
    
    DeviceName}&${
    
    ProductKey}
参数解释:
${
    
    DeviceName} 是设备的名称(就是创建设备的时候复制出来3个参数里的设备名称)
${
    
    ProductKey} 是设备的ProductKey(就是创建设备的时候复制出来3个参数里的ProductKey)

示例:
当前我的设备名称是:133K0VSu2G9y6XEFBlUb ,我的ProductKey是:h7s8JDdEcH3

那么我的UserName就是:
133K0VSu2G9y6XEFBlUb&h7s8JDdEcH3

(3) MQTT_PassWord
下载密码生成小工具:https://help.aliyun.com/document_detail/140507.html?spm=a2c4g.11186623.6.571.1e417544OGPj2y#section-dai-o6u-deh

image-20220325132240837

Calculate MQTT signature-password: https://help.aliyun.com/document_detail/292635.htm?spm=a2c4g.11186623.0.0.5aaf3686v36VUs#section-jx3-u57-pmm

image-20220325132253301

image-20220325132405260

According to the device certificate information, fill in the parameters, and then generate the MQTT login key.

image-20220509134205017

The generated information is as follows: These three data are the key information used for MQTT login next.

填入设备信息:
productKey:  h7s8JDdEcH3

deviceName:  133K0VSu2G9y6XEFBlUb

deviceSecret:  b2449f7fbc02c92fbbf7f86d7bac84cd

timestamp:  1652074854015

clientId:  133K0VSu2G9y6XEFBlUb

计算结果:
mqttClientId: 
133K0VSu2G9y6XEFBlUb|securemode=2,signmethod=hmacsha1,timestamp=1652074854015|

username: 
133K0VSu2G9y6XEFBlUb&h7s8JDdEcH3

password: 
CB182C6AE45CF2529AD91ADE2C5886EA7A67FC7E

(3) Log in using the MQTT client

Fill in the parameters as prompted by the software, and click Login.

Software download address: https://download.csdn.net/download/xiaolong1126626497/18784012

image-20220509134700693

Log in to Alibaba Cloud and you can see that the device is online.

image-20220509134822311

(4) Topic subscription and publishing test

You can see the theme format on the product page: https://iot.console.aliyun.com/product/productDetail/a1cMlEwEwjg/func?current=2

image-20220509134929737

发布主题:
/sys/h7s8JDdEcH3/133K0VSu2G9y6XEFBlUb/thing/event/property/post

上报属性消息的格式:  
{
    
    "method":"thing.event.property.post","params":{
    
    "DHT11_T":28,"DHT11_H":80,"TOUCH_ID":1,"CARD_ID":"1234567890","motor":1}}

订阅主题:
/sys/h7s8JDdEcH3/133K0VSu2G9y6XEFBlUb/thing/service/property/set

image-20220509141411909

The web page receives the published message:

image-20220509141447561

4.5 Summary of MQTT server information

MQTT服务器登录的信息:

mqttClientId: 
nSK7cPjbnPPBFsLch47U|securemode=2,signmethod=hmacsha1,timestamp=1652076448733|

username: 
nSK7cPjbnPPBFsLch47U&h7s8SDIY078

password: 
B2F31FA2AB991E98881FABDA45E01E0291014400


发布主题:
/sys/h7s8SDIY078/nSK7cPjbnPPBFsLch47U/thing/event/property/post

上报属性消息的格式:  
{
    
    "method":"thing.event.property.post","params":{
    
    "DHT11_T":28,"DHT11_H":80,"TOUCH_ID":1,"CARD_ID":"1234567890"}}


订阅主题:
/sys/h7s8SDIY078/nSK7cPjbnPPBFsLch47U/thing/service/property/set

4.6 Create a visualization project

Address: https://iot.console.aliyun.com/lk/related-services

image-20220430115334260

image-20220430115407200

image-20220430115423122

image-20220509141639658

image-20220509141734104

image-20220509141834432

image-20220509141843546

image-20220509141917108

Enter the page editing area.

image-20220509142026029

4.7 Associated Products and Equipment

Link: https://studio.iot.aliyun.com/project/a123UfKp0N6Xy62b/device

image-20220509142209334

image-20220509142241709

image-20220509142118276

image-20220509142305247

4.8 Design UI interface

Link: https://studio.iot.aliyun.com/p/a123UfKp0N6Xy62b/project/detail

image-20220509142445292

image-20220509142550237

Configure the data source for the dashboard

image-20220509142617655

image-20220509142702691

image-20220509143713932

After designing the page, click Publish.

image-20220509143737545

image-20220509143749412

The final display effect:

image-20220509143841830

To facilitate remote control of the door lock switch, add a button:

image-20220509145641008

image-20220509150116699

After the device is logged in, click the button switch on the webpage, and the data will be automatically delivered:

len:161,Data:@/sys/h7s8SDIY078/nSK7cPjbnPPBFsLch47U/thing/service/property/set{
    
    "method":"thing.service.property.set","id":"1426170453","params":{
    
    "motor":1},"version":"1.0.0"}
len:161,Data:@/sys/h7s8SDIY078/nSK7cPjbnPPBFsLch47U/thing/service/property/set{
    
    "method":"thing.service.property.set","id":"1431295144","params":{
    
    "motor":0},"version":"1.0.0"}

5. STM32 programming

image-20220509173554427

The development board used has 3 programmable buttons and 1 reset button.

These three buttons are used in the program to complete the operation of the display screen + fingerprint module, and complete the operation of fingerprint entry and deletion.

There are 2 LED lights on the board, which can be used as status indicators.

The LCD screen socket on the board can be directly inserted into a 0.96-inch OLED display or a 1.44-inch TFT display. The pit is: the backlight pin of this LCD display slot is actually PB10. In general, PB10 must be used as a serial port. Therefore, the LCD screen is currently driven by connecting it to other pins through the DuPont line.

In this design, ESP8266-WIFI is used. This serial port protocol WIFI has a built-in complete TCP/IP protocol stack and also supports AP+STA mode. In the current design, ESP8266 is configured into STA mode through code, and the connection can be specified to access the Internet. The router and the MQTT protocol encapsulated in the code are used to log in to the Alibaba Cloud IoT server to complete data interaction.

Fingerprint recognition adopts AS608 photoelectric fingerprint module. This fingerprint module has built-in storage space for 50~300 fingerprints, and completes fingerprint comparison, entry, deletion and other operations through serial port protocol.

DHT11 is a digital temperature and humidity sensor, which uses a single bus protocol to complete the data reading of temperature and humidity.

The relay module is a switch module with optocoupler isolation that supports high and low level triggering, and can be used to control 220V home appliances.

5.1 Hardware Wiring

1)AS608指纹模块接线
VCC---3.3v(1号线)
PA6---触摸感应线-高电平有效(2号线)
VCC---3.3V(3号线)
PA3(RX)---指纹模块的TX(4号线)
PA2(TX)---指纹模块的RX(5号线)
GND---GND(6号线)
2)ATK-ESP8266 WIFI接线
PB10(TX)--RXD 模块接收脚
PB11(RX)--TXD 模块发送脚
GND---GND 地
VCC---VCC 电源(3.3V~5.0V)
3)温湿度传感器: DHT11
VCC--VCC
GND---GND
DAT---PA5 
4)继电器--模拟门禁锁的开关
DAT: PB12 
+  : 5V
-  : GND
5)OLED显示屏接线:
GND   电源地
VCC   接 5V或3.3v电源
SCL   接 PC8(SCL)
SDA   接 PC9(SDA)
RST   接 PC10
DC    接 PB7
CS    接 PB8
BL	  接 PB4

6)板载LED灯接线
LED1---PA8
LED2---PD2
7)板载按键接线
K0---PA0 
K1---PC5 
K2---PA15
8)触摸按键使用TTP229型号的驱动芯片
SCL接----------->PC1--修改
SDA-OUT接------->PC2--修改
电源接---------->VCC-3.3
GND接----------->GND

9)RC522射频模块外部的接口:    
*1--SDA <----->PC14--片选脚
*2--SCK <----->PC15--时钟线
*3--MOSI<----->PA12--输出
*4--MISO<----->PA11--输入
*5--悬空
*6--GND <----->GND
*7--RST <----->PA4--复位脚
*8--VCC <----->VCC

5.2 Schematic diagram of development board

image-20220509173432957

5.3 Available IO ports

STM32F103RCT6开发板可以使用的引脚:
PC13
PC14
PC15
PD0--OSCIN-----特殊
PD1--OSCOUT----特殊
PC0
PC1
PC2
PC3
PA0----K0
PA1
PA2--串口2
PA3--串口2
PA4
PA5---SPI1_SCK
PA6---SPI1_MISO
PA7---SPI1_MOSI
PC4
PC5----K1
PB0
PB1
PB2---BOOT1--特殊
PB10--串口3
PB11--串口3
PB8
PB9
PB7
PB6
PB5
PB4
PB3
PD2------LED2
PC12----IIC_SCL
PC11----IIC_SDA
PC10
PA15---K2
PA14---SWCLK
PA13---SWDIO
PA12
PA11
PA10---串口1
PA9----串口1
PA8----LED1
PC9
PC8
PC7
PC6
PB15
PB14
PB13
PB12

5.4 Chinese characters modulo

image-20220510103430759

image-20220510103442550

5.5 Program Download

image-20220510103550708

5.6 Keil Engineering

image-20220510103610936

image-20220510115023704

5.7 Code Analysis

(1) MQTT parameters and WIFI parameter configuration

image-20220510115135482

At the top of the main.c file is the parameter configuration of the Alibaba Cloud MQTT protocol, mainly the information configuration of this router in line 93.

(2) WIFI initialization configuration

The whole device is connected to the network through ESP8266, and the process of ESP8266 connecting to the network is printed out through the serial port. Under normal circumstances, the serial port will print, and a prompt like WIFI: 0 indicates that the router network connection is successful.

For the specific code location, see the circled location in the figure below:

image-20220510131153155

Code to connect to Alibaba Cloud server and subscribe topic:

 printf("正在初始化ESP8266..\r\n");  
    for(i=0;i<5;i++)
    {
    
    
        if(ESP8266_Init()==0)
        {
    
    
            esp8266_state=1;
            break;
        }
        else
        {
    
    
            esp8266_state=0;
            printf("ESP8266硬件检测错误.\n");  
        }
    }
  
   if(esp8266_state)
   {
    
    
        printf("准备连接服务器....\r\n");
        //非加密端口
        printf("WIFI:%d\n",ESP8266_STA_TCP_Client_Mode(CONNECT_WIFI,CONNECT_PASS,CONNECT_SERVER_IP,CONNECT_SERVER_PORT,1));
         
        //2. MQTT协议初始化	
        MQTT_Init(); 

        //3. 连接服务器  
        for(i=0;i<5;i++)
        {
    
    
            if(MQTT_Connect(MQTT_ClientID,MQTT_UserName,MQTT_PassWord)==0)
            {
    
    
                esp8266_state=1;
                break;
            }
            esp8266_state=0;
            printf("服务器连接失败,正在重试...\n");
            delay_ms(500);
        }
        printf("服务器连接成功.\n");

        //3. 订阅主题
        if(MQTT_SubscribeTopic(SET_TOPIC,0,1))
        {
    
    
           printf("主题订阅失败.\n");
        }
        else
        {
    
    
           printf("主题订阅成功.\n");
        } 
   }
   
   printf("进入系统主循环...\r\n");

(3) Data reading of temperature and humidity module

In the while loop, the temperature, humidity, IC card number, fingerprint ID, and lock status information in the current system will be uploaded to the Alibaba Cloud server every 1 second. The upload data call is MQTT_PublishDatacomplete. This upload function will also take time, and the code in other places will also take time. Therefore, the upload data is set to 1 second and the time consumed by other places is actually added. The frequency of uploading data to Alibaba Cloud is about 3 to 5 seconds.

The specific implementation code is marked in the following figure:

image-20220510131414403

Specific implementation code:

if(wifi_TimeCnt>=100) //1000毫秒一次
        {
    
    
            wifi_TimeCnt=0;
            LED1=!LED1;
            
            //读取温湿度
            if(DHT11_Read_Data(&dht11_temp,&dht11_humidity))
            {
    
    
                printf("温度读取失败.\r\n");
            }
                        
            printf("环境温度:%d\r\n环境湿度:%d\r\n",dht11_temp,dht11_humidity);

             //环境温度
            sprintf(data_buff,"%d",dht11_temp);
            Gui_DrawFont_GBK16(72,16*0,RED,0,(u8*)data_buff);
            
            //环境湿度
            sprintf(data_buff,"%d",dht11_humidity);
            Gui_DrawFont_GBK16(72,16*1,RED,0,(u8*)"       ");
            Gui_DrawFont_GBK16(72,16*1,RED,0,(u8*)data_buff);
            
            //MQTT上报数据
            sprintf(mqtt_message,"{\"method\":\"thing.event.property.post\",\"id\":\"1234567890\",\"params\":{\"DHT11_T\":%d,\"DHT11_H\":%d,\"TOUCH_ID\":%d,\"motor\":%d,\"CARD_ID\":\"%s\"},\"version\":\"1.1.1\"}",
            dht11_temp,dht11_humidity,TOUCH_ID,MOTOR_A,CARD_ID);
            MQTT_PublishData(POST_TOPIC,mqtt_message,0);
            printf("%s\r\n",mqtt_message);
            
        }

(4) Matrix keyboard detection

Read the key value of the matrix keyboard, enter the password, display it in real time on the LCD screen, and complete the password verification to unlock.

image-20220510131903488

Specific implementation code:

   //触摸按键检测
        key=Touch_KeyScan();
        if(key)
        {
    
    
            printf("触摸按键=%d\r\n",key);
            time_cnt3=0;
            
            //密码输入
            if(key==1)my_strcat("1");
            if(key==2)my_strcat("2");
            if(key==3)my_strcat("3");
            if(key==5)my_strcat("4");
            if(key==6)my_strcat("5");
            if(key==7)my_strcat("6");
            if(key==9)my_strcat("7"); 
            if(key==10)my_strcat("8"); 
            if(key==11)my_strcat("9"); 
            if(key==14)my_strcat("0");             
            
            //按下*号键,清除所有密码
            if(key==13)
            {
    
    
                pass_show_buff[0]='\0';
                pass_show_temp_buff[0]='\0';
                pass_show_cnt=0;
                Gui_DrawFont_GBK16(0,16*4,WHITE,0,(u8*)"          ");
            }
            
            //按下D号按键,清除密码最后一位
            if(key==16)
            {
    
    
                delete_ending_char(pass_show_buff);
                delete_ending_char(pass_show_temp_buff);
                Gui_DrawFont_GBK16(0,16*4,WHITE,0,(u8*)"          ");
            }
            

            
            //按下#号键
            if(key==15)
            {
    
    
                printf("密码:%s\r\n",pass_show_temp_buff);
                //比较密码是否输入正确
                if(strcmp(pass_show_temp_buff,"123456")==0)
                {
    
    
                    MOTOR_A=1;
                    printf("输入密码->开锁成功.\r\n");
                }
                else
                {
    
    
                   MOTOR_A=0; //失败就关锁
                }
            }
            
            //显示密码*号
            Gui_DrawFont_GBK16(0,16*4,WHITE,0,(u8*)pass_show_buff);
        }
     

(5) Fingerprint module entry and deletion

In the while loop, the button detection function is continuously polled. If you press the independent button that comes with the board, it will enter the fingerprint entry mode and the fingerprint deletion mode.

After entering the fingerprint entry mode, it will be displayed on the screen 正在录入指纹, and the ID value can be set by pressing the remaining two buttons. The same goes for removing fingerprint patterns.

[External link image transfer failed, the source site may have anti-leech mechanism, it is recommended to save the image and upload it directly (img-zn45r9uE-1661737905114) (C:\Users\11266\AppData\Roaming\Typora\typora-user-images\ image-20220510131945211.png)]

Specific implementation code:

 //板载的按键检测
       key_val2=KEY_Scan();
       if(key_val2)
       {
    
    
           printf("按键按下:%d\r\n",key_val2);
       }

        //录入指纹
        if(key_val2==1)
        {
    
    
            printf("录入指纹.\r\n");
            
            Gui_DrawFont_GBK16(0,16*6,WHITE,0,(u8*)"             ");
            LCD_ShowChineseFont(16*0,16*6,16,HZ_FONT_16[15],WHITE,0);
            LCD_ShowChineseFont(16*1,16*6,16,HZ_FONT_16[16],WHITE,0);
            LCD_ShowChineseFont(16*2,16*6,16,HZ_FONT_16[17],WHITE,0);
            LCD_ShowChineseFont(16*3,16*6,16,HZ_FONT_16[18],WHITE,0);
            LCD_ShowChineseFont(16*4,16*6,16,HZ_FONT_16[19],WHITE,0);
            LCD_ShowChineseFont(16*5,16*6,16,HZ_FONT_16[20],WHITE,0);
        
            //置位
            input_touch_id=Touch_id_Num;
            
            while(1)
            {
    
    
               
               //外接按键检测
               key_val2=KEY_Scan();
               if(key_val2)
               {
    
    
                   printf("按键按下:%d\r\n",key_val2);
               }
               
               //录入指纹
                if(key_val2==1)
                {
    
    
                    printf("录入指纹,选择的ID:%d\r\n",input_touch_id);
                    Add_FR(input_touch_id);
                    
                    break;
                }  
                //ID++
                else if(key_val2==2)
                {
    
    
                    input_touch_id++;
                    if(input_touch_id>49)input_touch_id=49;
                    printf("input_touch_id:%d\r\n",input_touch_id);
                }  
                //ID--
                else if(key_val2==3)
                {
    
    
                    input_touch_id--;
                    if(input_touch_id<0)input_touch_id=0;
                    printf("input_touch_id:%d\r\n",input_touch_id);
                } 
                
                sprintf(data_buff,"ID:%d",input_touch_id);
                Gui_DrawFont_GBK16(0,16*7,WHITE,0,(u8*)data_buff);   
            }

           Gui_DrawFont_GBK16(0,16*6,WHITE,0,(u8*)"             ");
           Gui_DrawFont_GBK16(0,16*7,WHITE,0,(u8*)"             ");             
        }
        //删除指纹
        else if(key_val2==2)
        {
    
    
             printf("删除指纹.\r\n");
            
            Gui_DrawFont_GBK16(0,16*6,WHITE,0,(u8*)"             ");
            LCD_ShowChineseFont(16*0,16*6,16,HZ_FONT_16[15],WHITE,0);
            LCD_ShowChineseFont(16*1,16*6,16,HZ_FONT_16[16],WHITE,0);
            LCD_ShowChineseFont(16*2,16*6,16,HZ_FONT_16[21],WHITE,0);
            LCD_ShowChineseFont(16*3,16*6,16,HZ_FONT_16[22],WHITE,0);
            LCD_ShowChineseFont(16*4,16*6,16,HZ_FONT_16[19],WHITE,0);
            LCD_ShowChineseFont(16*5,16*6,16,HZ_FONT_16[20],WHITE,0);
          
            //置位
            input_touch_id=Touch_id_Num;
            
            while(1)
            {
    
    
                //外接按键检测
               key_val2=KEY_Scan();
               if(key_val2)
               {
    
    
                   printf("按键按下:%d\r\n",key_val2);
               }
               
             
               //删除指纹
                if(key_val2==1)
                {
    
    
                    printf("删除指纹,选择的ID:%d\r\n",input_touch_id);
                    Del_FR(input_touch_id);
                    
                    break;
                }  
                //ID++
                else if(key_val2==2)
                {
    
    
                    input_touch_id++;
                    if(input_touch_id>49)input_touch_id=49;
                    printf("input_touch_id:%d\r\n",input_touch_id);
                }  
                //ID--
                else if(key_val2==3)
                {
    
    
                    input_touch_id--;
                    if(input_touch_id<0)input_touch_id=0;
                    printf("input_touch_id:%d\r\n",input_touch_id);
                } 
                
                sprintf(data_buff,"ID:%d",input_touch_id);
                Gui_DrawFont_GBK16(0,16*7,WHITE,0,(u8*)data_buff);   ; 
            }
           
          Gui_DrawFont_GBK16(0,16*6,WHITE,0,(u8*)"             "); 
          Gui_DrawFont_GBK16(0,16*7,WHITE,0,(u8*)"             ");               
        }   
        
        time_cnt3++;
        wifi_TimeCnt++;
        DelayMs(10);
         //输入密码超时清除密码输入框
        if(time_cnt3>=300)
        {
    
    
            time_cnt3=0;
            delete_ending_char(pass_show_buff);
            delete_ending_char(pass_show_temp_buff);
            Gui_DrawFont_GBK16(0,16*4,WHITE,0,(u8*)"          ");
            Gui_DrawFont_GBK16(0,16*6,WHITE,0,(u8*)"           ");
        }

(6) IC card swiping

The current system also supports IC card swiping, reading the card number to determine unlocking.

image-20220510132258813

The specific implementation code is as follows:

  //刷卡
      if(search_card(Card_IC)==MI_OK)
      {
    
    
          printf("卡号:%X%X%X%X\r\n",Card_IC[0],Card_IC[1],Card_IC[2],Card_IC[3]);
          
          //比较卡号是否相等
          //卡号:F39A471B
          if(Card_IC[0]==0xF3 &&
              Card_IC[1]==0x9A &&
              Card_IC[2]==0x47 &&
              Card_IC[3]==0x1B)
          {
    
    
              MOTOR_A=1;
              printf("开锁成功-卡1.\r\n");
             //相等就保存到CARD_ID数组里上传到云端
            sprintf((char*)CARD_ID,"%X%X%X%X",Card_IC[0],Card_IC[1],Card_IC[2],Card_IC[3]);
          }
  
          else  //比较卡号是否相等
          //卡号:BCA5CB34
          if(Card_IC[0]==0xBC &&
              Card_IC[1]==0xA5 &&
              Card_IC[2]==0xCB &&
              Card_IC[3]==0x34)
          {
    
    
              MOTOR_A=1;
              printf("开锁成功-卡2.\r\n");
              //相等就保存到CARD_ID数组里上传到云端
              sprintf((char*)CARD_ID,"%X%X%X%X",Card_IC[0],Card_IC[1],Card_IC[2],Card_IC[3]);
          }  
      }

(7) Fingerprint judgment

The fingerprint module has a status line. If there is a fingerprint pressed, it will output a high level. When the finger is pressed, the fingerprint search will be performed, and the search is successfully completed to unlock.

image-20220510132549383

Specific implementation code:

//函数功能: 搜索指纹
//函数返回值: -1表示搜索失败  >=0 表示搜索到的指纹ID
int press_FR(void)
{
    
    
	SearchResult seach;
	u8 ensure;
	char *str;
	ensure=PS_GetImage();
	if(ensure==0x00)//获取图像成功 
	{
    
    	
		ensure=PS_GenChar(CharBuffer1);
		if(ensure==0x00) //生成特征成功
		{
    
    		
			ensure=PS_HighSpeedSearch(CharBuffer1,0,300,&seach);
			if(ensure==0x00)//搜索成功
			{
    
    		
				printf("搜索指纹成功	.\r\n");
				printf("Match ID:%d  Match score:%d",seach.pageID,seach.mathscore);//显示匹配指纹的ID和分数
                
                //保存指纹ID
                TOUCH_ID=seach.pageID;
                
                MOTOR_A=1;
                return seach.pageID;
            }
			else 
				ShowErrMessage(ensure);					
	  }
		else
			ShowErrMessage(ensure);
	 delay_ms(1000);//延时后清除显示
	}
    return -1;
}

おすすめ

転載: blog.csdn.net/xiaolong1126626497/article/details/126578898