指纹门禁

指纹门禁的详细介绍

创作者:damahua | 更新日期:2021-04-11 | 在线时长:655天
指纹解锁

功能介绍

指纹解锁 手机解锁

硬件组成

esp8266 12f 

代码说明

库:ArduinoBIGIOT

#if defined ESP32
#elif defined ESP8266
#include
#include
#else
#error "Only support espressif esp32/8266 chip"
#endif
#include "bigiot.h"
#define PIN 5
#define data_ID "8888"
#define MAX_PACKETSIZE 128 //自定义的缓冲buff长度
ESP8266WiFiMulti wifiMulti;

const char *id = "123";
const char *apikey = "123";
const char *usrkey = "123";
unsigned char AutoSearch[17]  = {0xEF, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x08, 0x55, 0x3E, 0x00, 0x00, 0x00, 0x3C, 0x00, 0xD8};
unsigned char AutoLogin[17]   = {0xEF, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x08, 0x54, 0x3E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x9D};
unsigned char TemplateNum[12] = {0xEF, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x03, 0x1D, 0x00, 0x21};
unsigned char Empty[12]       = {0xEF, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x03, 0x0D, 0x00, 0x11};
unsigned char DeleteChar[16]  = {0xEF, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x07, 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x15};
unsigned char OpenLed[12]     = {0xEF, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x03, 0x50, 0x00, 0x54};
int m = 0; //0 开锁 1添加 2删除 3清空
int buttonState = 0;
char uart_Receive_Buff [ MAX_PACKETSIZE ]; //定义缓冲buff
unsigned int uart_Receive_Index = 0; //收到的字节实际长度
unsigned long preUartTime = 0; //记录读取最好一个字节的时间点
unsigned long iotime = 0;
BIGIOT bigiot;
void eventCallback(const int devid, const int comid, const char *comstr)
{ if (!strcmp(comstr, "play")) {
    m = 0;
    digitalWrite(PIN, HIGH);
    bigiot.upload(data_ID, "已开锁");
    delay(1000);
    digitalWrite(PIN, LOW);
  } else if (!strcmp(comstr, "up")) {
    m = 1;
     } else if (comid == 13) { //是数字就执行 comid==13
    m = 2;
    long pid;
    pid = atol(comstr);
    DeleteChar[11] = pid;
    DeleteChar[15] = pid + 0x15;
  } else if (!strcmp(comstr, "down")) {
    m = 3;
  }
}

void disconnectCallback(BIGIOT &obj)
{ // 断开连接
  // Serial.print(obj.deviceName());
  // Serial.println("  disconnect");
}

void connectCallback(BIGIOT &obj)
{ // Serial.print(obj.deviceName());
  //  Serial.println("  connect");
}
void parseUartPackage(char *p , int len) {
  if (p[0] == 0x55)
  { //unsigned long interval = 500 ;
    switch (m) {
      case 0:
        Serial.write(AutoSearch, 17);
        break;
      case 1:
        Serial.write(TemplateNum, 12);
        break;
      case 2:
        Serial.write(DeleteChar, 16);
        break;
      case 3:
        // Serial.write(Empty, 12);
        Serial.write(TemplateNum, 12);
        break;
    }
    delay(1);
  }
  if (p[9] == 0x00 && p[0] == 0xEF) //确认码
  {
    if (p[8] == 0x07)
    { if (p[11] == 0x01)
      { m = 1;
        bigiot.upload(data_ID, "添加指纹");
      }
      digitalWrite(PIN, HIGH);
       delay(800);
      digitalWrite(PIN, LOW);
      Serial.write(p[11]);
   
      bigiot.upload(data_ID, String(int(p[11])));
    } else   if (p[8] == 0x05 )//取模板数
    { AutoLogin[13] =  p[11] + 0x01;
      AutoLogin[16] =  AutoLogin[13] + 0x9D;
      Serial.write(AutoLogin[13]);
      bigiot.upload(data_ID, String(int(AutoLogin[13])));
      Serial.write(AutoLogin, 17);
    } else    if (p[8] == 0x03 )
    { m = 0;
      bigiot.upload(data_ID, "OK");
      Serial.write(OpenLed, 12);
      delay(500);

    }

  } else {
    m = 0;
    bigiot.upload(data_ID, "err");
  
  }

}
void doUartTick()
{

  if (Serial.available() > 0)
  {
    uart_Receive_Buff [ uart_Receive_Index ++ ] = Serial.read();
    preUartTime = millis();
    if (uart_Receive_Index >= MAX_PACKETSIZE - 1) {
      uart_Receive_Index = MAX_PACKETSIZE - 2;
      preUartTime = preUartTime - 200;
    }
  }

  if (uart_Receive_Index > 0 && (millis() - preUartTime >= 100))
  { // uart_Receive_Buff [ uart_Receive_Index ] = 0x00;
    Serial.flush();
    parseUartPackage(uart_Receive_Buff, uart_Receive_Index);
    uart_Receive_Index = 0;
  }

}


void setup() {
  Serial.begin(57600);//, SERIAL_8N1
  delay(100);

  pinMode(PIN, OUTPUT);

  digitalWrite(PIN, LOW);
  WiFi.mode(WIFI_STA);
  wifiMulti.addAP("12", "88888888");
  wifiMulti.addAP("chen", "88888888");
  wifiMulti.addAP("ChinaNet-jluI", "888888p");
  if (wifiMulti.run() == WL_CONNECTED) {
    //Serial.println(".");
    // Serial.println(WiFi.localIP());
  }
  bigiot.eventAttach(eventCallback);
  bigiot.disconnectAttack(disconnectCallback);
  bigiot.connectAttack(connectCallback);
if (!bigiot.login(id, apikey, usrkey)) {
//    // Serial.println("Login fail");
//    // while (1);
  }
  wifi_set_sleep_type(MODEM_SLEEP_T);
 
}


void loop() {
  doUartTick();
  if (wifiMulti.run() == WL_CONNECTED) {
    bigiot.handle();
  }


评论:共0条

评论支持使用[code][/code]标签添加代码