0

您好,我的问题是,当我将指纹传感器与 esp8266 连接时,它不起作用!我正在使用 adafruit 指纹传感器 R305 和 esp 模块 esp8266 cp2102。我已将 vcc 引脚连接到 3.3v 引脚,将接地引脚连接到 groung,然后将 rx 连接到 rx 引脚,将 tx 连接到 tx 引脚。我使用 adafruit 传感器库,但当我连接指纹时它会做任何事情。我打算用这两个组件创建一个简单的指纹考勤系统,我用 IFTTT 应用程序创建了一个数据库。有代码。

#include <BearSSLHelpers.h>
#include <CertStoreBearSSL.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiGeneric.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiSTA.h>
#include <ESP8266WiFiType.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WiFiClientSecureAxTLS.h>
#include <WiFiClientSecureBearSSL.h>
#include <WiFiServer.h>
#include <WiFiServerSecure.h>
#include <WiFiServerSecureAxTLS.h>
#include <WiFiServerSecureBearSSL.h>
#include <WiFiUdp.h>



#include <SoftwareSerial.h>

#include <Adafruit_Fingerprint.h>

#define rxPin 2
#define txPin 3

const char* NAME; // the name will be gievn in the code for each ID saved
const char* ID; // the ID that are save into the fingerprint sensor


String Event_Name = "FINGERPRINT "; // this is the name of the file of the database

String Key = "beStaVRpfye6wtonedU"; // this is my unique key for the database created

// Replace with your unique IFTTT URL resource
String resource = "/trigger/" + Event_Name + "/with/key/" + Key;

// Maker Webhooks IFTTT
const char* server = "maker.ifttt.com"; // here database is store

// Replace with your SSID and Password
char* ssid     = "Telecom-2"; //wifi name
char* pass = "X5NVY53V236k"; // wifi password
SoftwareSerial mySerial (rxPin, txPin);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); // communcation with the IoT and fingerprint sensor

void setup()
{
  Serial.begin(57600);
  mySerial.begin(57600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit finger detect test");

  // set the data rate for the sensor serial port
  finger.begin(57600);
  delay(5);
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) {
      delay(1);
    }
  }
// the fingerpprint sensor will first starts
  finger.getTemplateCount();
  Serial.print("Sensor contains ");
  Serial.print(finger.templateCount);
  Serial.println(" templates");
  Serial.println("Waiting for valid finger...");

// meanwhile the esp8266 wifi module will start and conect to the wifi data given
  Serial.print("Connecting to: "); // connecting to a wifi avaible
  Serial.print(ssid);             // connecting to the given wifi name  
  WiFi.begin(ssid, pass);    // connection in progress 

  int timeout = 10 * 4; // 10 seconds
  while (WiFi.status() != WL_CONNECTED  && (timeout-- > 0)) {
    delay(250);
    Serial.print("Attempting to connect to SSID");
  }
  Serial.println("Connected");

  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Failed to connect");
  }

  Serial.print("WiFi connected in: ");
  Serial.print(millis());
  Serial.print(", IP address: ");
  Serial.println(WiFi.localIP());
}

void loop()                     // run over and over again
{ // now the finger print sensor will wait for a register ID
  getFingerprintIDez();
  if (finger.fingerID == 1) //mean if the ID correspond to ID 1
  {

    Serial.print("!!--");
    Serial.println(finger.fingerID);
    NAME = "Sailen"; //therefore the name of sailen will appear as ID 1
    ID = "1";
    if (finger.confidence >= 60) // fingerprint test must over 60% of confidence
    {
      Serial.print("Attendace Marked for ");
      Serial.println(NAME);
      makeIFTTTRequest();
      // digital write - open the attendance
    }

  }

  if (finger.fingerID == 2 ) {
    Serial.print("!!--");
    Serial.println(finger.fingerID);
    digitalWrite(5, LOW);
    NAME = "Bob"; // therefore the name of bob will appear for ID 2
    ID = "2";
    if (finger.confidence >= 60) // fingerprint test must over 60% of confidence
    {
      Serial.print("Attendace Marked for ");
      Serial.println(NAME);
      makeIFTTTRequest();
      // digital write - open the door
    }      //don't ned to run this at full speed.

  }

}

uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK success!

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);

  return finger.fingerID;
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.image2Tz();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  return -1;

  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  return finger.fingerID;
}

// Make an HTTP request to the IFTTT web service
void makeIFTTTRequest() {
  Serial.print("Connecting to "); // means connecting to my google database
  Serial.print(server);

  WiFiClient client;
  int retries = 5;
  while (!!!client.connect(server, 80) && (retries-- > 0)) {
    Serial.print(".");
  }
  Serial.println();
  if (!!!client.connected()) {
    Serial.println("Failed to connect...");
  }

  Serial.print("Request resource: ");
  Serial.println(resource);

// now that the IoT has access to the data base
// value 1 will be use for name and value 2 for which ID it is

  String jsonObject = String("{\"value1\":\"") + NAME + "\",\"value2\":\"" + ID
                      + "\"}"; // name and id is registered in the database

  client.println(String("POST ") + resource + " HTTP/1.1");
  client.println(String("Host: ") + server);
  client.println("Connection: close\r\nContent-Type: application/json");
  client.print("Content-Length: ");
  client.println(jsonObject.length());
  client.println();
  client.println(jsonObject);

  int timeout = 5 * 10; // 5 seconds
  while (!!!client.available() && (timeout-- > 0)) {
    delay(100);
  }
  if (!!!client.available()) {
    Serial.println("No response...");
  }
  while (client.available()) {
    Serial.write(client.read());
  }

  Serial.println("\nclosing connection");
  client.stop();
}`

有什么不对?我在 youtube 上观看了这样的视频,但我的有点不同 https://techiesms.com/iot-projects/iot-attendance-system-without-website/

4

2 回答 2

0

先生,我将 thr 指纹连接到 5V 上,并将 tx 引脚连接到 esp 的 tx 引脚,并将 rxpin 连接到 esp rx 引脚,但它不起作用

于 2020-05-13T05:31:50.660 回答
0

正如传感器的数据表所述:

电源电压:3.6 - 6.0VDC
工作电流:最大 120mA
峰值电流:最大 150mA

因此,您必须使用合适的电源或带升压转换器的电池组,我建议您使用最低 4.5 V 和最低 0.5 A 以获得可靠的性能。

于 2020-05-11T11:08:49.347 回答