Save fingerprint data into database

Hi, I'm using the AS608 fingerprint sensor with the arduino uno and w5100 ethernet shield. The database I use is mysql in phpmyadmin from xampp server . Can I know is it possible to save the fingerprint data into the database instead of just save the fingerprint id into database? Can I know how many fingerprint id does the AS608 can store in the sensor if the fingerprint data cannot save into the database? Thank you.

Is google broken again?

The AS608 is capable of storing up to 127 individual fingerprints... it's written in the documentation (found one here, first google hit)

there is a command to extract fingerprint image from the sensor, so then you have a BLOB you can store in your database. There is a reverse command to upload images to the module.

Normally you'd want the ISO template if it can generate one, a raw image will mean you have to do template extraction yourself to do anything useful. The template is what's used for matching, its a feature-encoded representation of the fingerprint's variant and minuitiae.

Sorry for late reply. So can I know how to extract the fingerprint image from the sensor, because I search on Google, mostly are using the show fingerprint template to convert the fingerprint into hexadecimal, but when I try to save the converted hexadecimal value by sending the hexadecimal value to http request, it cannot save into the database.

post your code

Here is the code that I used:

#include <Adafruit_Fingerprint.h>
#include <SPI.h>
#include <Ethernet.h>
#include <SoftwareSerial.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177); //IP address for your arduino.
char server[] = "192.168.1.100"; //IP address of your computer.

#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
// Set up the serial port to use softwareserial..
EthernetClient client;
SoftwareSerial mySerial(2, 3);

#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1

#endif


Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

int getFingerprintIDez();
const size_t bufferSize = 512; // MAKE SURE IT'S LARGE ENOUGH
char jsonBuffer[bufferSize];

const byte fingerTemplate[] = {0x10, 0x20, 0x30, 0x00, 0x50, 0x60};
const size_t templateSize = sizeof fingerTemplate / sizeof fingerTemplate[0];

void setup()
{
  while (!Serial);
  Serial.begin(9600);
  Serial.println("Fingerprint template extractor");

  // set the data rate for the sensor serial port
  finger.begin(57600);

  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }

  // Try to get the templates for fingers 1 through 10
  for (int finger = 1; finger < 10; finger++) {
    downloadFingerprintTemplate(finger);
  }
}

uint8_t downloadFingerprintTemplate(uint16_t id)
{
  Serial.println("------------------------------------");
  Serial.print("Attempting to load #"); Serial.println(id);
  uint8_t p = finger.loadModel(id);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.print("Template "); Serial.print(id); Serial.println(" loaded");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    default:
      Serial.print("Unknown error "); Serial.println(p);
      return p;
  }

  // OK success!

  Serial.print("Attempting to get #"); Serial.println(id);
  p = finger.getModel();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.print("Template "); Serial.print(id); Serial.println(" transferring:");
      break;
    default:
      Serial.print("Unknown error "); Serial.println(p);
      return p;
  }

  // one data packet is 267 bytes. in one data packet, 11 bytes are 'usesless' :D
  uint8_t bytesReceived[534]; // 2 data packets
  memset(bytesReceived, 0xff, 534);

  uint32_t starttime = millis();
  int i = 0;
  while (i < 534 && (millis() - starttime) < 20000) {
    if (mySerial.available()) {
      bytesReceived[i++] = mySerial.read();
    }
  }
  Serial.print(i); Serial.println(" bytes read.");
  Serial.println("Decoding packet...");

  uint8_t fingerTemplate[512]; // the real template
  
  memset(fingerTemplate, 0xff, 512);

  // filtering only the data packets
  int uindx = 9, index = 0;
  memcpy(fingerTemplate + index, bytesReceived + uindx, 256);   // first 256 bytes
  uindx += 256;       // skip data
  uindx += 2;         // skip checksum
  uindx += 9;         // skip next header
  index += 256;       // advance pointer
  memcpy(fingerTemplate + index, bytesReceived + uindx, 256);   // second 256 bytes

  for (int i = 0; i < 512; ++i) {
    //Serial.print("0x");
    printHex(fingerTemplate[i], 2);
     //double finger = Serial.print(fingerTemplate[i], 2);
     //httpRequest(finger);
    //Serial.print(", ");
  }
  Serial.println("\ndone.");

  return p;
}



void printHex(int num, int precision) {
  char tmp[16];
  char format[128];

  sprintf(format, "%%.%dX", precision);

  sprintf(tmp, format, num);
  double fingerprint = Serial.print(tmp);
  httpRequest(fingerprint);
  
}

void loop()
{}


void httpRequest(double fingerprint)
{// Connect to the server (your computer or web page)  
  if (client.connect(server, 80)) {
    client.print("GET /fingerprint/fingerprint.php?ID_S="); // This
    //client.print("ID_S="); // This
    client.print(fingerprint); // And this is what we did in the testing section above. We are making a GET request just like we would from our browser but now with live data from the sensor
    client.println(" HTTP/1.1"); // Part of the GET request
    client.println("Host: 192.168.1.100"); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie.Host: "www.yourwebpage.com")
    client.println("User-Agent: arduino-ethernet");
    client.println("Content-Transfer-Encoding: binary");
    client.println("Connection: close"); // Part of the GET request telling the server that we are over transmitting the message
    client.println(); // Empty line
    client.println(); // Empty line
    client.stop();    // Closing connection to server

  }

  else {
    // If Arduino can't connect to the server (your computer or web page)
    Serial.println("--> connection failed\n");
  }
}

I tried to modify the example of show_fingerprint_template from adafruit to let the fingerprint which already stored in the fingerprint sensor to save the fingerprint as hexadeximal to the database.

1 Like

what does your httpRequest() do in the printHex() function that is called 512 times !

So it means I cannot just pass the tmp data to http request like this?

do you plan to send 512 GET requests ?

Surely not. You're just passing a double representing the ID to the fingerprint.php page 512 times, not the blob data.

Ok. So is that any way to pass only 1 fingerprint template to the request? because I just want to get 1 fingerprint template and send it to the request to save into the database.

One fingerprint template is likely the 512 bytes blob the example is printing.

you have that in this array

  uint8_t fingerTemplate[512]; // the real template

that's the payload you need to send to your server in some way

And, on the other side, your fingerprint.php has to handle it properly.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.