Arduino Forum

Using Arduino => Programming Questions => Topic started by: nimit393 on Sep 28, 2018, 06:10 am

Title: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Sep 28, 2018, 06:10 am
Hi Guys,

Used the "show_fingerprint_template" function on adafruit library to get the fingerprint templates of fingerprint stored in the module...489byte each. However, i am unable to write these templates on other sensor. Motive is to avoid duplicate enrollmet of fingerprint on multiple sensor. Once I enroll on one device..I want to extract the template and write the same onto other sensors...let me know who this can be done.
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Sep 28, 2018, 11:53 am
have you explored the section 6 of the documentation (https://cdn-shop.adafruit.com/datasheets/ZFM+user+manualV15.pdf)?
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Oct 01, 2018, 07:02 am
Thanks for the documentation.
However for testing purpose...how can i use the serial monitor on arduino to directly type the commands and check weather the sensor responds in the way its intended?
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Oct 01, 2018, 08:49 am
how can i use the serial monitor on arduino to directly type the commands and check weather the sensor responds in the way its intended?
Well, by writing such a program... ;)

(There are many test examples (https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library/tree/master/examples) in the library)
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Oct 07, 2018, 07:15 pm
Well...none of them are helpful in writing template back to device. Neither do i see that library has functions defined to get the part of the code working for writing a template.
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Oct 07, 2018, 07:29 pm
Well...none of them are helpful in writing template back to device. Neither do i see that library has functions defined to get the part of the code working for writing a template.
sure, library might be incomplete but what is not helpful in section 6? you can extend the library...

Quote
6.2.3 Download the image: DownImage
Description: to download image from upper computer to Img_Buffer. Refer to 1.1.1 for more about the image buffer.
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Oct 10, 2018, 03:18 pm
I am not aware how the library is sending out commands in hex...if you can let me know who I can directly type  in commands in hex over serial, then that would be helpful in creating and extending the existing library for writing template.
In short if I can directly type serially, then i can observe how the sensor is reacting and verify weather the commands sent by my is correct or not.
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Oct 10, 2018, 05:30 pm
I am not aware how the library is sending out commands in hex...if you can let me know who I can directly type  in commands in hex over serial, then that would be helpful in creating and extending the existing library for writing template.
It's  in the code of the library (https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library/blob/a0dce93b2e1ee44db42d960dfbb56653a4bb7c1b/Adafruit_Fingerprint.cpp#L39).
Code: [Select]
#if ARDUINO >= 100
  #define SERIAL_WRITE(...) mySerial->write(__VA_ARGS__)
#else
  #define SERIAL_WRITE(...) mySerial->write(__VA_ARGS__, BYTE)
#endif

#define SERIAL_WRITE_U16(v) SERIAL_WRITE((uint8_t)(v>>8)); SERIAL_WRITE((uint8_t)(v & 0xFF));

#define GET_CMD_PACKET(...) \
  uint8_t data[] = {__VA_ARGS__}; \
  Adafruit_Fingerprint_Packet packet(FINGERPRINT_COMMANDPACKET, sizeof(data), data); \
  writeStructuredPacket(packet); \
  if (getStructuredPacket(&packet) != FINGERPRINT_OK) return FINGERPRINT_PACKETRECIEVEERR; \
  if (packet.type != FINGERPRINT_ACKPACKET) return FINGERPRINT_PACKETRECIEVEERR;

#define SEND_CMD_PACKET(...) GET_CMD_PACKET(__VA_ARGS__); return packet.data[0];

And see how SEND_CMD_PACKET is used for various cases.

To send stuff from your computer you need either a terminal app that lets you send binary or write your own small app (using Processing for example)
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Oct 13, 2018, 07:23 pm
I do not completely understand the commands...a bit difficult to understand.

Menawhile, using Coolterm to test weather my commands are correct or not. Sending EF01FFFFFFFF0100041700001C as hex...the sensor is not responding. What might be the issue?
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Oct 13, 2018, 07:58 pm
So you are sending a handshake

- are you sure baud rates are set correctly?
- can you check if your module address is really 0xFFFFFFFF ? (this is the default but can be changed)

Title: Re: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Oct 14, 2018, 07:04 am
Yes..I am sending standard handshake message with blank sketch loaded on arduino uno. Using Coolterm to send Hex data over serial bus.
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Oct 14, 2018, 07:11 am
Baud rate used is 9600 and password  is standard 0xFFFFFFFF.
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Oct 14, 2018, 09:08 am
Baud rate used is 9600 and password  is standard 0xFFFFFFFF.
- default baud rate is 57600 (N=6)
- 0xFFFFFFFF is not a password but the Chip address

How did you wire things? Blank sketch does not do anything

Here is how to proceed if you have a module that looks like mine (otherwise adjust wires):

Wire this way:
(http://forum.arduino.cc/index.php?action=dlattach;topic=570705.0;attach=277845)

Connect Vcc to your Arduino 5V, GND to GND, Sensor Tx to Arduino Rx for Serial3,, Sensor Rx to Arduino Tx for Serial3 - the two other wires don't need to be connected

Upload this code to an Arduino Mega (to have 2 hardware Serial):
Code: [Select]
#define fingerSerial Serial3

void setup() {
  Serial.begin(115200);
  fingerSerial.begin(57600);
  delay(1000);  // one second delay to let the sensor 'boot up'
}

void printHex2Digit(byte b)
{
  if (b <= 0xF) Serial.print("0");
  Serial.print(b, HEX);
}

void loop() {
  static unsigned long tSerial = 0;
  static unsigned long tFinger = 0;

  while (Serial.available()) {
    int r = Serial.read();
    if (millis() - tSerial >= 100) Serial.print(F("\nSending to Sensor: "));
    tSerial = millis();
    printHex2Digit((byte) r);
    if (r != -1) fingerSerial.write((byte) r);
  }

  while (fingerSerial.available()) {
    if (millis() - tFinger >= 100) Serial.print(F("\nReceived from Sensor: "));
    tFinger = millis();
    int r = fingerSerial.read();
    if (r != -1) printHex2Digit((byte) r);
  }
}


Open CoolTerm and connect at 115200 bauds to your Arduino
Open the SendString panel from the Connection menu
paste in that window the EF01FFFFFFFF0100041700001C handshake message
send that HEX message

(http://forum.arduino.cc/index.php?action=dlattach;topic=570705.0;attach=277847)

if all is wired appropriately you will see in the serial terminal
Sending to Sensor: EF01FFFFFFFF0100041700001C
Received from Sensor:EF01FFFFFFFF07000300000A


if you decode the received message: EF01FFFFFFFF07000300000A

EF01 --> Start Header
FFFFFFFF --> Adder
07 --> Acknowledge packet
0003 --> length including command packets, data packets and 2 bytes Checksum
00 --> DATA = Port operation complete
000A --> Checksum 7 + 3 + 10 = 0x0A, all correct

this is indeed the expected confirmation message as per the documentation (chapter 6.1.1) (https://cdn-shop.adafruit.com/datasheets/ZFM+user+manualV15.pdf)
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Oct 14, 2018, 12:39 pm
Hey,

The code posted by you works. Thanks a million for the help.

I was assuming that the default baud must be 9600 which was incorrect.

Also I used blank sketch to pass through the serial commands which did not work...what might be the issue?...because I did not authenticate with password first?

Earlier the connections for Rx and Tx of fingerprint sensor were directly connected to Rx Tx of the board...effectively connecting it to UART of my laptop.

Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Oct 14, 2018, 12:50 pm
Great

 the bank sketch would work by  kinda bypassing Serial and connecting directly to pins 0 and 1... of course need to cross cables TX to RX and RX to TX and the challenge is the default 57600 bauds... a small program such as the one I wrote reads from one side and sends it to the other
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Oct 15, 2018, 08:17 am
Blank sketch with Rx Tx correctly connected to that of fingerprint sensor would not work? The code posted by you does a very similar task, with not directly bypassing the UART commands but relaying it to different serial port.
What might be the reason for this?
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Oct 15, 2018, 08:25 am
Baud rate for Cool Term can be updated to 57600.
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Oct 15, 2018, 10:03 am
I've seen boards behave differently when trying to use pin 0 and 1 and also have usb connected... so I'm always careful on such setup
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Oct 15, 2018, 07:37 pm
I extracted fingerprint template using the standard extract feature in Ada fruit library. Received template as

"FFFFFFFFFFFFFFFFFF0165159200FFFEFFFEFFFEFFFEF80EC00680008000800080000000000000000000000000008000000000000000000000000000000020AB78324242982B0DEF01FFFFFFFF0200825E1F56592A3ED8D9674201F90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000056CEF01FFFFFFFF02008203015E169700FFFEFFFEFFFEFF1EC006C002C0008000000000000000000000000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFF98415E1BA41ADE49A4431E6BA481FE2E26047E60AB033E0AAD845E59B2DC5E45B39ADE0AB604BE09BADC5E1F3D9ABE553F04FE48C29ADE3898031F26AD843F53AF44FF71B81F9F2AF9EF01FFFFFFFF08008239C306376297D71C659B2C7C2E394416000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000618FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"

However, I can find 3 header message within the templates. I tried other fingerprint in the same device...all 3 have 3 header section embedded into it and long series of 0 and F. Which part of the message is actually the template which I can use and write it on to other fingerprint sensor.

Motive is to extract template and store in a central repository...which can be transmitted on to multiple sensors as the network get expanded.
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Oct 17, 2018, 04:34 pm
Any updates?
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Oct 17, 2018, 06:38 pm
Post the full true output of the example - not just an extract of what you think is meaningful

Are you running this on a UNO or MEGA ?

The  stray FFFFFFFFFFF you see are just there because buffer is initialized with plenty of FF (https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library/blob/a0dce93b2e1ee44db42d960dfbb56653a4bb7c1b/examples/show_fingerprint_templates/show_fingerprint_templates.ino#L79) in the library

They seem to use data packets of 256 bytes but seems what you get back is actually the 128 bytes version

having multiple data packet is not impossible as you might not be able to fit all the data in one frame, so you should expect when you send a command to get many answer and at some point the last frame will include a End of Data packet command so that you know it's the last one

there is  plenty of garbage so would need to see exactly the output on the Serial console...

The 3 frames you see are



FFFFFFFFFFFFFFFFFF0165159200FFFEFFFEFFFEFFFEF80EC00680008000800080000000000000000000000000008000000000000000000000000000000020AB78324242982B0D


EF01
FFFFFFFF
02      Data packet
0082      length of package = command packets + data packets + CKSUM --> 128 bytes + 2 for checksum
5E1F56592A3ED8D9674201F90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
056C      CKSUM (this one is OK)

EF01
FFFFFFFF
02      Data packet
0082      length of package = command packets + data packets + CKSUM --> 128 bytes + 2 for checksum
03015E169700FFFEFFFEFFFEFF1EC006C002C0008000000000000000000000000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFF98415E1BA41ADE49A4431E6BA481FE2E26047E60AB033E0AAD845E59B2DC5E45B39ADE0AB604BE09BADC5E1F3D9ABE553F04FE48C29ADE3898031F26AD843F53AF44FF71B81F9F
2AF9      CKSUM (this one seems wrong)

EF01
FFFFFFFF
08      End of Data packet
0082      length of package = command packets + data packets + CKSUM --> 128 bytes + 2 for checksum
39C306376297D71C659B2C7C2E39441600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0618      CKSUM (this one is OK)


FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF






Title: Re: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Oct 18, 2018, 04:30 pm
The attachment shows template read for 2 different fingerprints.

However when I am trying to write the same template on other location...the serial trace does not show garbage values but cool term shows. And after sending the 4 chunks of template...finally when store command is used...reply is 01 ...error when receiving data.
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Oct 18, 2018, 04:54 pm
Issue resolved...I am now able to write template from external source. You can ignore the above post.
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Oct 18, 2018, 05:11 pm
Would be fair to explain what you did and how you solved it for everyone having the same question in the future
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Oct 18, 2018, 06:34 pm
1. First step to extract fingerprint from sensor is to load the desired template number to either buffer 1 or 2.
2. Once the template is loaded into buffer, read the template from buffer.
3. Template size might vary, hence, the whole template might be broken down into multiple bits and part.
4. This template can now be stored onto other device and can be reused to write the same template into similar sensor.
5. Commands for all the above functions are standard and can be viewed in the document shared in this blog post above.
6. Example of template extracted can also be viewed in the text files shared in the previous post.
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Oct 19, 2018, 08:44 am
Thx - makes sense :-)
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Oct 30, 2018, 03:40 pm
Hi,

Trying to send data over serial. The data is getting transmitted as ASCII equivalent when read over the other arduino with code shared by you in earlier post(one which displays the HEX values of the data received over serial). However, correct HEX value get displayed on the serial monitor of the arduino on which this code is runing.

Code: [Select]
/*
  SD card read/write

 This example shows how to read and write data to and from an SD card file
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)

 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 */
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
#include <SPI.h>
#include <SD.h>
int i;
String s;
char a[1]={16};
int b=20;
File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  mySerial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("ABCDEF.txt", FILE_WRITE);

  // re-open the file for reading:
  myFile = SD.open("ABCDEF.txt");
  if (myFile) {
    Serial.println("ABCDEF.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      i=myFile.read();
     
      if (isDigit(i)) {
      // convert the incoming byte to a char and add it to the string:
      s += (char)i;
    }

    if (i == '\n') {
      int p = s.toInt();
      Serial.print(p,HEX);
      mySerial.print(p,HEX);
      p=atoi(p);
      mySerial.print(p,HEX);
      s = "";
      p = "";
      //mySerial.print(32,HEX);
    }
   
      //Serial.write(r);
      //mySerial.write(r);
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening ABCDEF.txt");
  }
}

void loop() {
  // nothing happens after setup
  //mySerial.write("1");
}

Title: Re: Write template on Fingerprint sensor R305/R307
Post by: nimit393 on Oct 30, 2018, 06:18 pm
Understood my mistake...should had used Serial.write instead of Serial.print
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Oct 30, 2018, 06:41 pm
 :)  :)
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: marcoas on Nov 08, 2018, 09:27 pm
@nimit393,  Can you show us, the code for write template on sensor, please?


1. First step to extract fingerprint from sensor is to load the desired template number to either buffer 1 or 2.
2. Once the template is loaded into buffer, read the template from buffer.
3. Template size might vary, hence, the whole template might be broken down into multiple bits and part.
4. This template can now be stored onto other device and can be reused to write the same template into similar sensor.
5. Commands for all the above functions are standard and can be viewed in the document shared in this blog post above.
6. Example of template extracted can also be viewed in the text files shared in the previous post.
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: dhananjayaggarwal on Mar 12, 2019, 10:59 am
Post the full true output of the example - not just an extract of what you think is meaningful

Are you running this on a UNO or MEGA ?

The  stray FFFFFFFFFFF you see are just there because buffer is initialized with plenty of FF (https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library/blob/a0dce93b2e1ee44db42d960dfbb56653a4bb7c1b/examples/show_fingerprint_templates/show_fingerprint_templates.ino#L79) in the library

They seem to use data packets of 256 bytes but seems what you get back is actually the 128 bytes version

having multiple data packet is not impossible as you might not be able to fit all the data in one frame, so you should expect when you send a command to get many answer and at some point the last frame will include a End of Data packet command so that you know it's the last one

there is  plenty of garbage so would need to see exactly the output on the Serial console...

The 3 frames you see are



FFFFFFFFFFFFFFFFFF0165159200FFFEFFFEFFFEFFFEF80EC00680008000800080000000000000000000000000008000000000000000000000000000000020AB78324242982B0D


EF01
FFFFFFFF
02 Data packet
0082 length of package = command packets + data packets + CKSUM --> 128 bytes + 2 for checksum
5E1F56592A3ED8D9674201F90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
056C CKSUM (this one is OK)

EF01
FFFFFFFF
02 Data packet
0082 length of package = command packets + data packets + CKSUM --> 128 bytes + 2 for checksum
03015E169700FFFEFFFEFFFEFF1EC006C002C0008000000000000000000000000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFF98415E1BA41ADE49A4431E6BA481FE2E26047E60AB033E0AAD845E59B2DC5E45B39ADE0AB604BE09BADC5E1F3D9ABE553F04FE48C29ADE3898031F26AD843F53AF44FF71B81F9F
2AF9 CKSUM (this one seems wrong)

EF01
FFFFFFFF
08 End of Data packet
0082 length of package = command packets + data packets + CKSUM --> 128 bytes + 2 for checksum
39C306376297D71C659B2C7C2E39441600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0618 CKSUM (this one is OK)


FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF







This is my first comment so please forgive if I do some mistake.
I'm using Adafruit Fingerprint sensor library with Arduino Uno and I'm getting the same output of show_fingerprint_templates example code i.e. the 3 frames you've pointed to.

Now I want to know that

Firstly : how did you came to conclusion about which one is ( OK) and which one is (WRONG). Like in the manual/datasheet it is stated that CKSUM  is equal to 'the arithmetic sum of package identifier, package length and
all package contents. Overflowing bits are omitted. high byte is
transferred first'.

Secondly : What will be the final correct template if we consider the above example?

Please help me I'm struggling with this problem of identifying the correct template (from past few weeks) so that I can store it and later upload back the correct template to the sensor.

Thank You
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Mar 13, 2019, 10:16 am
this was what the OP posted

Code: [Select]
FFFFFFFFFFFFFFFFFF0165159200FFFEFFFEFFFEFFFEF80EC00680008000800080000000000000000000000000
008000000000000000000000000000000020AB78324242982B0DEF01FFFFFFFF0200825E1F56592A3ED8D9674201F900000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000056CEF01FFFFFFFF0200820
3015E169700FFFEFFFEFFFEFF1EC006C002C0008000000000000000000000000000000000000000000000000
000FFFFFFFFFFFFFFFFFFFFFF98415E1BA41ADE49A4431E6BA481FE2E26047E60AB033E0AAD845E59B2DC5E4
5B39ADE0AB604BE09BADC5E1F3D9ABE553F04FE48C29ADE3898031F26AD843F53AF44FF71B81F9F2AF9EF0
1FFFFFFFF08008239C306376297D71C659B2C7C2E3944160000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000618FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


as the output of his request.  in that blurb or data we can recognize 3 frames starting with EF01

I color coded the format of a frame as:
data to be ignored
EF01
ADDER --> Default value is 0xFFFFFFFF
package identifier --> describe what type of information is in the package
length  --> length of package
The actual data
check sum


FFFFFFFFFFFFFFFFFF0165159200FFFEFFFEFFFEFFFEF80EC006800080008000800000000000000
00000000000008000000000000000000000000000000020AB78324242982B0D
EF01FFFFFFFF020082
5E1F56592A3ED8D9674201F9000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
056C
EF01FFFFFFFF020082
03015E169700FFFEFFFEFFFEFF1EC006C002C000800000000000000000000000000000000000000
0000000000000FFFFFFFFFFFFFFFFFFFFFF98415E1BA41ADE49A4431E6BA481FE2E26047E60AB033E0AAD845
E59B2DC5E45B39ADE0AB604BE09BADC5E1F3D9ABE553F04FE48C29ADE3898031F26AD843F53AF44FF71B81F9F
2AF9
EF01FFFFFFFF080082
39C306376297D71C659B2C7C2E394416000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000
0618
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF



so we see we have 3 frames, the first two are of type 02, meaning 'Data packet' and the last one is of type 08 which means 'End of Data packet'. (01 would be a "Command packet", 07 would be an "Acknowledge packet")

we then see that the length of package is 0x0082(hex) which is 130 in decimal
The length of the packet is composed of the length of the data + the 2 bytes for the checksum --> 128 bytes + 2 for checksum = 130 --> so we have 128 bytes of data, which will be represented as 256 ASCII symbols for the data and 2 bytes for the checksum represented by 4 ASCII symbols (theoretical Max length is 256 bytes so the library creates large buffers just in case but here we get the 128 byte frames).

we then have the data followed by the checksum on 16 bits

To calculate the checksum the documentation states it's the arithmetic sum of package identifier, package length and all package content with Overflowing bits being omitted

package ID = 1 byte
package length = 2 bytes
package content = we have seen above it's 128 bytes

so to run the checksum we need 128+2+1 = 131 bytes, or 262 characters starting at the package ID

So you need to take the package ID, length and content and sum all the numeric value represented by each byte, so you need to read 2 ASCII symbols, high side first, build a byte value and add to the sum in a 16 bit unsigned variable ignoring overflow.

In the first example above this would be the stream of data
Code: [Select]
0200825E1F56592A3ED8D9674201F90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

if you dump that into this test code
Code: [Select]
void getHexBufferCKSum()
{
  uint16_t cksum = 0;
  uint16_t lsb = 0, hsb = 0;
  boolean waitingForHigh = true;
  Serial.println(F("Enter HexBuffer (0..9 or A..F all caps):"));
  unsigned int nbBytes = 0;
  unsigned int nbCars = 0;
  while (1) {
    if (Serial.available()) {
      int r = Serial.read();
      if ((r != -1) && (r != '\n')) { // ignore and terminates on '\n'
        if ((r != '\r') && (((r >= '0') && (r <= '9')) || ((r >= 'A') && (r <= 'F')))) { // ignore '\r', handle only 0 to 9 and A to F
          uint8_t v;
          if ((r >= '0') && (r <= '9')) v = r - '0';
          else v = r - 'A' + 10;
          if (waitingForHigh) {
            hsb =  v;
          } else {
            lsb = v;
            cksum += 16 * hsb + lsb;
            nbBytes++; // got a full byte
          }
          waitingForHigh = !waitingForHigh;
          nbCars++;
        }
      } else break;
    }
  }

  Serial.print(F("received "));  Serial.print(nbCars);
  Serial.print(F(" characters ("));  Serial.print(nbBytes);
  Serial.print(F(" bytes), cksum is ")); Serial.println(cksum, HEX);
  if (nbCars != 2 * nbBytes)   Serial.println(F("*** received weird number of characters, check input ***"));
  Serial.println(F("-------------------"));

}

void setup() {
  Serial.begin(115200);
}

void loop() {
  getHexBufferCKSum();
}

you will see in your Serial console (set at 115200 bauds / sending NL to terminate)

Enter HexBuffer (0..9 or A..F all caps):
received 262 characters (131 bytes), cksum is 56C


So you can see that there is ineed 262 characters received and 56C(hex) is indeed the check sum 056C we had received for the first package

if you run the data for the third package you will see in your Serial console

Enter HexBuffer (0..9 or A..F all caps):
received 262 characters (131 bytes), cksum is 618


So you can see that there is ineed 262 characters received and 618(hex) is indeed the check sum 0618 we had received for the third package

but if you run that for the second package, you will see in your Serial console

Enter HexBuffer (0..9 or A..F all caps):
received 262 characters (131 bytes), cksum is 359D


So you can see that there is ineed 262 characters received BUT 359D(hex) is NOT the check sum 2AF9 we had received for the third package.. So something weird  there...
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: dhananjayaggarwal on Mar 13, 2019, 10:27 am
Thank You so much. You've helped me a lot
in understanding the dynamics and now I can work  with peace as now I know that I'm headed in the right direction.

Thank You
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: dhananjayaggarwal on Mar 13, 2019, 10:46 am
One final thing I want to ask that if I'm writing template back to the sensor, I will be following the steps below. Can you point out if any mistake you think these points have:-


These are the steps I will be following.
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Mar 13, 2019, 11:01 am
Since total size of template is 512 bytes, create two data frames containing 128 bytes of data each.
hum... 2 x 128 is not 512....

you can see above that extracting one profile actually required 3 frames

so you probably need to build the right number of frames based on what was actually received from the command to upload to the computer, and play that back the other way.

I'm on the go and don't have the device available so can't test anything - but that's how I would explore that
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: dhananjayaggarwal on Mar 13, 2019, 11:13 am
you can see above that extracting one profile actually required 3 frames

This point is where all I got confused. The Adafruit library of show_fingerprint_templates extracts the total of final 512 bytes out of which one frame is received as faulty always.

Also these 512 bytes of data contains other parts of frame like header, package identifier, package length, content, cksm.

Whereas the specification of sensor states that size of each template is 512 bytes. So should I keep the lower bytes as 0x00 to complete the 512 bytes of template size? Or I should just upload the 256 bytes which are OK out of three frames received.

I am really feeling stupid to ask these questions and really sorry for it. But I've went through manual multiple times and unable to find details about this.
Thank you for giving time.
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Mar 13, 2019, 11:18 am
I haven't done it as I did not have the need, just looking at the spec like you.

@nimit393 seems to say it has done it, but seems missing in action and refused to post his code... so up to you to reinvent the wheel

would need to explore
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: dhananjayaggarwal on Mar 13, 2019, 11:22 am
Still you've helped me a lot. I would definitely share if I got a success in it.
Thank you  :)
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Mar 13, 2019, 12:43 pm
I would definitely share if I got a success in it.
would be good for the community! thx +1 karma as encouragement
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: GVS on Aug 22, 2019, 02:55 pm
Hello.
Need help with this issue.
Is the topic still active?
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Aug 22, 2019, 07:07 pm
Seems @dhananjayaggarwal did not succeed or decided not to share...
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: GVS on Aug 23, 2019, 08:02 am
This is upsetting.
Maybe you can help find the right direction.
Sorry for my English, I'm from Ukraine ...
My experience in programming arduino is not great, so many problems and questions arise. The challenge now is to clone the fingerprint database from one scanner to another. Having studied this topic, I managed to get a response from the scanner with the data packet, but they do not look like they showed here. The method of receipt as in message #24.
I use Arduino Nano + R307 fingerprint scanner. To send messages, your sketch from message # 12 and CoolTerm. The result is in the attached file. I can't understand how to extract the data necessary for cloning from it (((
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: J-M-L on Aug 23, 2019, 10:04 am
I never did use have access to the same doc as you, as highlighted above... sorry can't help
Title: Re: Write template on Fingerprint sensor R305/R307
Post by: GVS on Aug 29, 2019, 01:32 pm
I'm at a standstill, maybe someone will point the right direction.
I do a fingerprint scan, convert it to a template with the RegModel command. The documentation says - "generate a template which is stroed back in both CharBuffer1 and CharBuffer2". As I understand it, the contents of the buffers should be the same. Having executed the comparison command - Match, I get confirmation of this. But if I try to output the contents of the buffers to the console with the command - UpChar, I see completely different data. Moreover, if I ask several times in a row to display the contents of the buffer neither doing anything else with the scanner, I get different values ...
In the attached file, data output from buffer No. 1 and several conclusions in a row from buffer No. 2.