rfid 125-networking guide

Upload: tran-van-canh

Post on 01-Jun-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 Rfid 125-Networking Guide

    1/24

    RFID 125KHz

    Networking Guide

  • 8/9/2019 Rfid 125-Networking Guide

    2/24-2- v0.2

    Index

    Document version: v0.2 - 06/2012

    Libelium Comunicaciones Distribuidas S.L.

    INDEX1. Introduction ......................................................................................................................................... 3

    2. Hardware .............................................................................................................................................. 5

    3. Dual Radio with the Expansion Board ............................................................................................... 7

    3.1. Expansion Radio Board ..............................................................................................................................................................7

    3.2. Setting ON ......................................................................................................................................................................................8

    3.3. Setting OFF .....................................................................................................................................................................................8

    4. RFID Tags .............................................................................................................................................. 9

    5. Usage .................................................................................................................................................. 11

    6. Security with RFID at 125 KHz .......................................................................................................... 13

    7. RFID: 13.56 MHz or 125 KHz? ............................................................................................................ 14

    8. Libeliums API .................................................................................................................................... 15

    8.1. Switching the module on.......................................................................................................................................................16

    8.2. Switching the module off ......................................................................................................................................................16

    8.3. Resetting the module ..............................................................................................................................................................16

    8.4. Going to sleep ............................................................................................................................................................................16

    8.5. Reading the serial number of an EM4100/02 card........................................................................................................16

    8.6. Requesting to read a T5557 card .........................................................................................................................................17

    8.7. Requesting to read a T5557 card with password...........................................................................................................17

    8.8. Getting data from a T5557 card ...........................................................................................................................................17

    8.9. Printing the content of a T5557 card .................................................................................................................................18

    8.10. Writing data in a block of a T5557 card ...........................................................................................................................188.11. Writing data with password in a block of a T5557 card ............................................................................................18

    8.12. Writing data in a block of a T5557 card and checking it ...........................................................................................19

    8.13. Writing data with password in a block of a T5557 card and checking it ............................................................19

    8.14. Setting and enabling Password Mode into a T5557 card .........................................................................................20

    8.15. Disabling Password Mode into a T5557 card ................................................................................................................20

    9. Time of execution of the functions ................................................................................................... 22

    10. Code example .................................................................................................................................. 22

    11. Code examples and extended information ................................................................................... 24

  • 8/9/2019 Rfid 125-Networking Guide

    3/24-3- v0.2

    Introduction

    1. IntroductionRFID (Radio Frequency Identification) is a technology that uses electromagnetic fields to identify objects in a contactless way; it

    is also called proximity identification. There are 2 elements in RFID communications: the RFID module (or reader/writer device)

    and an RFID card (or tag). The RFID module acts as the master and the card acts as the slave; this means the module queries the

    card and sends instructions to it. In a normal RFID communication, the RFID module is fixed and the user takes his card near itwhen he needs to start the interaction.

    Figure 1: Waspmote with RFID at 125 KHz module on socket 0 and WiFi module on socket 1

    An RFID card can be understood as a remote storage unit where we can read and write information without contact. Most of the

    RFID tags are passive, which implies that the RFID module must create an electromagnetic field in order to power the tag. The

    RFID cards antenna (in fact it is an inductive coupler) gets the power from this field. Also, an RFID card has a very basic micro-

    controller which manages the communications and memory access.

    Many RFID standards have been released by the industry. Most of them have as operating frequency 125 KHz or 13.56 MHz.

    Libelium has integrated one module for each frequency. Besides, the module for 13.56 MHz is compliant with the Near Field

    Communication (NFC) technology; for more information read chapter RFID: 13.56 MHz or 125 KHz?. In the present document wewill be explaining the RFID module which works at 125 KHz, and any reference to RFID must be understood as RFID for 125 KHz.

    In particular, Libelium has created a module which is compliant with two 125 KHz RFID protocols, among others: EM4100/

    EM4102 and T5557. These 2 protocols are very popular and accepted in many applications.

    Waspmote communicates with the RFID module through one of its 2 UARTs. Basically, Waspmote sends commands or instruction

    packets to the RFID module and then waits for the response packets from the module.

    There is just one way to interact with an EM4100/02 card: reading its serial number, 4-byte long (anf the check byte). Note the

    card does not stores any password and the data (the serial data) cannot be protected.

    Regarding a T5557 card, there are 2 possible operations because this protocol performs writing too:

    1. the module reads the cards internal memory (from 4 to 28 bytes each time (from 1 to 7 blocks, depending on configuration))

    2. the module writes in the cards internal memory (4 bytes each time (1 block))

    The API developed by Libelium allows an easy management of all the possible actions with the cards, becasue the API permits

    the Waspmote user to perform a higher level programming.

  • 8/9/2019 Rfid 125-Networking Guide

    4/24-4- v0.2

    Introduction

    Among the RFID applications, the most common are:

    access control/security

    events ticketing

    public transport

    equipment and personnel tracking logistics

    real-time inventories

    marketing information (kiosks)

  • 8/9/2019 Rfid 125-Networking Guide

    5/24-5- v0.2

    Hardware

    2. HardwareLibeliums RFID module integrates an SM125 RFID-reader/writer integrated circuit.

    Figure 2: RFID module for 125 KHz and antenna

    Features:

    Compatibility: Reader/writer mode supporting ISO cadrs - T5557 / EM4102

    Distance: 5cm

    Max capacity:20B

    Tags available:cards, keyrings

    Among several 125 KHz RFID standards; Libeliums module is compliant with EM4100/02 and T5557, which are very successful

    international standards in RFID technology. This technologies operate at the 125 KHz LF frequency band, so it can be deployed

    anywhere without authorization or license.

    The SM125 implements the RF, analog and digital tasks in transmission and reception, while Waspmotes role is to control these

    operations. The RFID module is connected to Waspmote through one of its 2 UART interfaces ([1] XBee socket or [2] GPRS socket,

    enabled by the Expansion Board). Waspmote sends command frames to the module and receives response frames.

    A command frame has the following structure:

    header (1 byte): It indicates the beginning of a new frame. It is always 0xFF.

    reserved (1 byte): Always 0x01.

    length (1 byte): It indicates the length of the payload data (command + data bytes).

    command (1 byte): It indicates which command the module must perform.

    data (N bytes): It contains the parameters needed for the selected command.

    checksum (1 byte): It is the addition of all the bytes in the frame, with the exception of the header.

    And a response frame has an equivalent structure:

    header (1 byte): It indicates the beginning of a new frame. It is always 0xFF.

    reserved (1 byte): Always 0x01.

    length (1 byte): It indicates the length of the payload data (command + response bytes).

    command (1 byte): It indicates which command (previously sent by Waspmote) is being replied by the module.

    response (N bytes): It contains the reponse bytes from the module.

    checksum (1 byte): It is the addition of all the bytes in the frame, with the exception of the header.

  • 8/9/2019 Rfid 125-Networking Guide

    6/24-6- v0.2

    Hardware

    For both types of card, there are different mechanisms (checksum, parity, bit encoding, ACK, etc) to ensure the data integrity.

    Besides, the T5557 standard offers the possibility of using a password to access data.

    Regardless the type of card, the module replies with a standard response when a command was successfully executed:

    0xFF 0x01 0x01 0x99 0x9B.

    This response can be seen as an ACK, confirming that the module received the command and executed it. After this ACK,

    and depending on the command, another reply can be sent by the module. Note that maybe the whole operation was not

    completed even if the ACK is received, it just means the module received and executed the command internally. For example,

    data could not be written in the card if it was not present; the user should check the writting was successful by reading the block

    manually.

    The RFID antenna is 43x20x5 mm and is made of thin wire, so it must be handled with care.

  • 8/9/2019 Rfid 125-Networking Guide

    7/24-7- v0.2

    Dual Radio with the Expansion Board

    3. Dual Radio with the Expansion BoardBefore starting to use a module, it needs to be initialized. During this process, configuration parameters are sent to the module.

    USB and SD card are also initialized.

    3.1. Expansion Radio Board

    The RFID module can use the Expansion Radio Board. The new Expansion Board allows connecting two radios at the same

    time in the Waspmote sensor platform. This means a lot of different combinations are now possible using any of the 10 radios

    available for Waspmote: 802.15.4, ZigBee, 868 MHz, 900 MHz, XSC, Bluetooth, RFID, RFID/NFC, Wifi and 3G/GPRS.

    Some of the possible combinations are:

    ZigBee - Bluetooth

    ZigBee - RFID

    RFID/NFC - Wifi

    ZigBee 3G/GPRS Wifi - RFID

    Wifi - 3G/GPRS

    Wifi Bluetooth

    etc.

    Next image shows the sockets available along with the UART assigned. On one hand, SOCKET0 allows to plug any kind of radio

    module through the UART0. On the other hand, SOCKET1 permits to connect a radio module through the UART1.

    Figure 3: Waspmote with XBee radio on socket 0 and Bluetooth module on socket 1

    This API provides a function in order to initialize the RFID module module called RFID.ON(socket). This function supports a newparameter which permits to select the socket. It is possible to choose between socket0 or socket1.

  • 8/9/2019 Rfid 125-Networking Guide

    8/24-8- v0.2

    Dual Radio with the Expansion Board

    An example of use the initialization function is the following:

    Selecting socket0: RFID125.ON(socket0);

    Selecting socket1: RFID125.ON(socket1);

    The rest of functions are used the same way as they are used with older API versions. In order to understand them we recommendto read this guide.

    WARNING:

    Avoid to use DIGITAL7 pin when working with Expansion Board. This pin is used for setting the XBee into sleep.

    Avoid to use DIGITAL6 pin when working with Expansion Board. This pin is used as power supply for the Expansion Board

    Incompatibility with Sensor Boards:

    Gases Board: Incompatible with SOCKET4 and NO2/O3 sensor.

    Agriculture Board: Incompatible with Sensirion and the atmospheric pressure sensor.

    Smart Metering Board: Incompatible with SOCKET11 and SOCKET13

    Smart Cities Board: Incompatible with microphone and the CLK of the interruption shift register.

    Events Board: Incompatible with interruption shift register.

    3.2. Setting ON

    With the function ON() module is powered and the UART is opened to communicate with the module. It also enters in command

    mode and sets some default configurations.

    // switches ON the RFID module using expansion boardRFID.ON(socket1);

    3.3. Setting OFF

    The RFID API function OFF() exits from the radio RFID command-mode securely, closes the UART and switches the module off.

    // closes the UART and powers off the moduleRFID.OFF();

  • 8/9/2019 Rfid 125-Networking Guide

    9/24-9- v0.2

    RFID Tags

    4. RFID TagsLibelium offers EM4100/02 cards and tags and T5557 cards and tags. An RFID card has a thin form factor (81x54x1 mm), like a

    driving license or identification card, and can be kept in the users wallet. However, an RFID tag is smaller and thicker (around

    20x20x5 mm) but can be kept in the users keyring.

    It is important to note that a card always has a longer range than a tag because its antenna has more surface.

    Figure 4: RFID cards

    Figure 5: RFID tags

    The EM4100/EM4102 cards are read-only, they cannot be written. They just store a serial number of 4 bytes and the check byte.

    The protocol involved is pretty simple, and was created by EM Microelectronic. The EM4100/02 cards have a header composed

    of 9 1s. After this, the RFID module takes care of the Manchester bit modulation.

    On the other hand, the T5557 cards can be read and written. The card is divided into 8 blocks, where each block stores 4 bytes.

    Among these 8 blocks, there are 5 blocks available for the user to store data, while 2 bytes are used for configuration issues and

    1 block for storing the password. Blocks can be protected with a password of 4 bytes.

  • 8/9/2019 Rfid 125-Networking Guide

    10/24-10- v0.2

    RFID Tags

    Regarding a T5557 card, the memory structure of a card is as follows:

    block 0x00: Configuration block. When the card is powered by the field, the first thing the card does is to configure itself

    with the info contained in block 0x00 (enconding protocol, max read blocks, data rate, password mode, protective lock).

    This block should not be written with arbitrary values; otherwise the tag may not be accessed again.

    block 0x01: This block is used for Byte Track method. The 4 bytes programmed in this block are a known pattern that shouldbe traced by the module in order to synchronize the incoming data stream. Its content typically is 0x52 0x58 0x8B 0x45.

    block 0x02: Data block, available for the user.

    block 0x03: Data block, available for the user.

    block 0x04: Data block, available for the user.

    block 0x05: Data block, available for the user.

    block 0x06: Data block, available for the user.

    block 0x07: Password block (or data block like blocks 0x02-0x06 if password mode is not enabled). If password is enabled,

    access to the tag requires the password that matches block 0x07 content. Bear in mind that once password is enabled then

    it is impossible to access the tag again unless we provide the correct 4-byte password.

    It is not advised to write block 0x00, 0x01 or 0x07 if you are not an advanced user. You could leave your card unaccessible.

    To sum up, the total storage capacity is 20 bytes, or 24 bytes if the Password Mode is not enabled and we use the block 0x07.

  • 8/9/2019 Rfid 125-Networking Guide

    11/24-11- v0.2

    Usage

    5. UsageThe maximum operational range is about 6 cm from the antenna. A card beyond this distance will not be detected, or the

    communications with it will be full of errors. Card writing distance can be a little shorter.

    Notice the antenna can also operate with cards at 90 from its surface, but the range is around 40%.

    Besides, the minimum range are a few mm. A card which is closer than this to the RFID modules antenna could not be detected.

    Optimal results are obtained when the card is placed parallel to the surface of the antenna, still and at a distance of 1 cm.

    As shown in the examples, it is good to use ifs to control which functions are executed. For example, if the getCard() function

    was not successful, it does not make sense to execute one writeBlock() after that. Note there are functions should deliver 0

    when executed correctly.

    When any of the functions does not deliver a successful execution, it is advised to end the loop and start the RFID process from

    the beginning.

    A typical read or write process can take more than one second. Make sure the card remains within the field until the wholeprocess is completed.

    Figure 6: Typical RFID operation

    Some kind of indicator is strongly advised to let the user know that data exchange was successful. Waspmote can control a LED

    (built-in or external) or a buzzer for this goal.

    After a successful operation, it is advised to execute a short delay (e.g. 2 seconds) to let the user take his card away. This way we

    avoid to execute the same operation more than one time.

    The RFID antenna should be located in an accessible and comfortable place for the user.

    The RFID antenna, the RFID module, the battery or Waspmote are not waterproof, so an enclosure is mandatory when the

    system is going to work outdoors. The antenna should be fixed really close to the wall of the enclosure. Metallic enclosures are

    not advised.

  • 8/9/2019 Rfid 125-Networking Guide

    12/24-12- v0.2

    Usage

    In general, avoid placing the RFID antenna near metallic objects, since the communication range could decrese.

    It can be a good idea to place the antenna near the top of the enclosure, in parallel with the ground. This way the user can just

    let the card lie still on top of the case for a while. Wherever the antenna is, do not forget to indicate in your enclosure where it is.

    Use the Waspmotes Expansion Board to enable another communication module to transmit certain (or all) RFID operations to

    another device or to a data center.

    Use a micro SD card to store certain (or all) RFID operations. This can be a security back up.

    Add one Meshlium device to your ecosystem for advanced features such as Linux OS tools, local MySQL data base storing

    system, WiFi and Ethernet connectivity, remote web server or higher computing speed.

  • 8/9/2019 Rfid 125-Networking Guide

    13/24-13- v0.2

    Security with RFID at 125 KHz

    6. Security with RFID at 125 KHzEM4100/02 cards have an serial number with a length of 4 bytes, so there are 4,200 millions of different serial numbers.

    On the other hand, the password of a T5557 card has a length of 4 bytes. That means there are 4,200 different possible passwords.

    Remember read/write access can also be permitted without any password if the Password Mode remains disabled. Kindly noticethat T5557 cards do not have a serial number, but the user could use the data blocks in the card to write the serial number he likes.

    These numbers, along with the data integrity mechanisms, demonstrate that 125 KHz RFID is a pretty secure technology.

    FAQs

    Q: Can I change the serial number in a given card?

    A: In a T5557 card, there is not a serial number, and all the memory has read and write access (with the appropriate password).

    In an EM4100/02 card, there is a serial number and it cannot be changed since the memory has read-only access. There are

    security reasons to do so: if an EM4100/02 card could be written, it would be possible to duplicate or forge cards.

    Q: Can I consider an EM4100/02 cards 4-byte serial number card as unique or not?

    A: No, but there is just one possibility among thousands of millions that you find another card like yours.

    Q: Can I order or select a specific serial number for my EM4100/02 card?

    A: No, the cards serial numbers are set in a random way.

    Q: I do not know/remember the password for a T5557 card, can I read or write this card?

    A: No, if the Password Mode is enabled then it is not possible to access a T5557 cards block unless we have provided thepassword before. All cards are provided with the Password Mode disabled. If the user enables the Password Mode, he must

    remember the content of the block 0x07 in that moment, because this will be the password for all the blocks.

    Q: Are the EM4100/02 or T5557 standards 100% secure systems?

    A: No. Any security system has bugs that can be hacked. The 13.56 MHz RFID technology is probably a better choice if security

    is an important issue. Waspmotes 13.56 MHz RFID module performs advanced security methods, like encrypted wireless

    communications between the card and the module, three-pass authentication or improved data integrity systems.

    Q: Does Libelium recommend its RFID module for electronic money exchange?

    A: No. The RFID module by Libelium is not intended for payment applications but for control of usage.

    Q: Should I change the password to the cards?

    A: EM4100/02 cards do not have password and the serial number cannot be protected.

    Regarding T5557 cards, yes, you should change the password if it is possible that someone is interested in reading or

    changing the stored information. Setting a new password is a quick process and will ensure only the authorized agents can

    read or write the data. Avoid sharing or losing this information.

    We advise to set a random password. As a tip, it would be an even more secure system if each card has its own password.

  • 8/9/2019 Rfid 125-Networking Guide

    14/24-14- v0.2

    RFID: 13.56 MHz or 125 KHz?

    7. RFID: 13.56 MHz or 125 KHz?Libelium has developed 2 different RFID modules: 13.56 MHz and 125 KHz. They are not compatible because they comply with

    different standards. As a result their working frequencies are very different, and the communication protocols are not the same.

    So:

    13.56 MHz RFID cards cannot work with the 125 KHz RFID module

    125 KHz RFID cards cannot work with the 13.56 MHz RFID module

    Everything said here about 13.56 MHz RFID technology is also applicable to the NFC technology.

    The decision to adopt one system or the other depends on several points. First of all, if you are purchasing Libeliums RFID

    solution to fit an existing system you will want to to keep the compatibility.

    Both frequency bands are suitable to be used in any country. 125 KHz (LF) is unregulated and 13.56 MHz (HF) is an ISM band.

    In general, the industry has used the 125 KHz RFID technology in projects that identify and track objects (like in a supply chain),

    while the 13.56 MHz RFID technology is used in applications that identify objects or people and store information.

    A 125 KHz RFID card, T5557 type, has a memory of just 20 bytes, while a 13.56 MHz RFID Mifare card, 1k type, has up to 752

    available bytes. This seems a great difference, but bear in mind 20 bytes are enough to store information such a long ID code.

    Regarding maximum ranges, a 125 KHz RFID card has a longer read range (about 6 cm) than a 13.56 MHz RFID card (3 cm).

    However, when the operation includes writing, the range of a 125 KHz RFID card is smaller (1 cm).

    The 13.56 MHz RFID module and its cards implement more secure communications, which includes advanced methods for safer

    authentication, counterfeiting prevention, encryption and data integrity. Besides, a 13.56 MHz RFID key is longer and safer than

    a 125 KHz RFID password. Therefore, 13.56 MHz RFID is the best option if security is important.

    As said before, it is not advised to place the RFID system near metallic objects; however the 125 KHz RFID technology seems to

    be the most adaptive to a metal environment. However, in industrial environments, the 125 KHz RFID communications could be

    affected by the noise generated by motors, while the 13.56 MHz technology would not.

    The 13.56 MHz RFID module has faster data rates in read or write operations.

  • 8/9/2019 Rfid 125-Networking Guide

    15/24-15- v0.2

    Libeliums API

    8. Libeliums APIWaspmotes API RFID files:

    RFID125.cpp

    RFID125.h

    APIs functions

    Function Brief description

    OFF() switches the module off

    ON(socket) switches the module on in one of the 2 UARTs

    reset() resets the module via software

    goToSleep(secs) go to sleep mode for 'secs' seconds

    readSerialNumber(secs,

    snB0, snB1, snB2, snB3)

    sends to the module the command to read the serial number of an

    EM4100/02 card. Waits for secs seconds for a card to be read.

    requestReadCard(modeRead, blocks) sends to the module the command for reading a card's blocks

    requestReadCardWithPass(modeRead, blocks, pass0, pass1, pass2, pass3)

    sends to the module the command for reading a cards blocks with

    password

    getCard(mData) reads the response of the module to a requestReadCard() command

    printCard(matrix) prints the content of a T5557 card via the serial port

    writeBlock(block,data0, data1, data2, data3)

    sends to the module the command for writing data in one block of

    one T5557 card

    writeBlockWithPass(block,data0, data1, data2, data3,

    pass0, pass1, pass2, pass3)

    sends to the module the command for writing data in one block of

    one T5557 card which is protected with password

    writeBlockAndCheck(block, sends to the module the command for writing data in one block of

    one T5557 card and checks that

    writeBlockWithPassAndCheck(block,data0, data1, data2, data3,

    pass0, pass1, pass2, pass3)

    sends to the module the command for writing data in one block of

    one T5557 card which is protected with password and checks that

    passwordOn(pass0, pass1, pass2, pass3) sends the command for writing the new password in the 0x07 block

    and writes in the 0x00 block for setting the Password Mode on

    passwordOff(pass0, pass1, pass2, pass3) sends the command for writing in the 0x00 block and set the

    Password Mode off

    writeByte(data) writes a byte (hex) in ASCII via the serial port

    blinkLED() blinks the LED to signal something

  • 8/9/2019 Rfid 125-Networking Guide

    16/24-16- v0.2

    Libeliums API

    8.1. Switching the module on

    It switches the RFID module on.

    Example of use

    {RFID125.ON(SOCKET0); // switches the module on in socket 0}

    8.2. Switching the module off

    It switches the RFID module off.

    Example of use

    {RFID125.OFF(); // switches the module off}

    8.3. Resetting the module

    It resets the RFID module in a software way. All the registers are set to the reset values, but all the variables remain the same.

    This is a function only intended for advanced users: if a reset is needed, it is advised to execute the init() function, not reset().

    The init() function not only executes the reset() function internally, but it also sets the registers back to the correct configuration

    for Waspmote.

    Example of use

    {RFID125.reset(); // (soft) resets the module. Be sure to set the registers afterwards}

    8.4. Going to sleep

    It sends the module to a low-power mode. After a certain amount of seconds a hardware reset is sent to the module in order to

    wake it up.

    Example of use

    {RFID125.goToSleep(10); // sends the module to sleep mode for 10 seconds}

    8.5. Reading the serial number of an EM4100/02 card

    It sends to the module the command for reading a EM4100/02 cards serial number. Then the function waits for a card during a

    certain amount of seconds.

    Example of use

    {uint8_t serNum0 = 0x00; // stores the rst byte of the EM4100/02 cards serial numberuint8_t serNum1 = 0x00;

  • 8/9/2019 Rfid 125-Networking Guide

    17/24-17- v0.2

    Libeliums API

    uint8_t serNum2 = 0x00;uint8_t serNum3 = 0x00;uint8_t time = 0x03; // the seconds we want to wait for a carduint8_t state = 1; // stores the status of the executed command (0 = success)...// sends to the module the command to read the serial number of an EM4100/02 type card.

    // Waits time seconds for a card to be read and then returns 0 if a card was detected// and 1 elsewhere. The serial number would be stored in the serNum0.. serNum3 variables.state = RFID125.readSerialNumber(seconds, serNum0, serNum1, serNum2, serNum3);}

    8.6. Requesting to read a T5557 card

    It sends to the module the command for reading a T5557 cards blocks.

    Example of use

    {RFID125.requestReadCard(1, 7); // sends to the module the command to read the 7 blocks of a// a T5557 type card, Byte Track mode

    }

    8.7. Requesting to read a T5557 card with password

    It sends to the module the command for reading a cards blocks when the card is protected with a 4-byte password.

    Example of use

    {RFID125.requestReadCardWithPass(1, 7, 0x01, 0x02, 0x03, 0x04); // sends to the module the

    // command to read the 7 blocks of a T5557 type card which is// protected by the password 0x01 0x02 0x03 0x04

    }

    8.8. Getting data from a T5557 card

    It receives and parses the content of a T5557 card. Remember the internal structure of a card in the chapter RFID cards. The

    content of the card is stored into a 7x4 bidimensional matrix.

    In fact, it gets the response to a requestReadCard() or a requestReadCardWithPass() command that the module will send, so one

    of these 2 functions must have been executed before.

    Example of use

    {uint8_t myMatrix [7][4]; // bidimensional matrix for storing the values inside the card (7 rows,

    // 4 columns)uint8_t state = 1; // stores the status of the executed command (0 = success)...RFID125.requestReadCard(1, 7); // asks the module to send the read command (T5557 card, 7

    // blocks)state = RFID125.getCard(myMatrix); // receives the response to the requestReadCard() command.// If a card was found and read, its content is stored in the

    // variable myMatrix, and variable state will be 0.// If no card was found, variable state will be 1.}

  • 8/9/2019 Rfid 125-Networking Guide

    18/24-18- v0.2

    Libeliums API

    8.9. Printing the content of a T5557 card

    It prints the content of a card via the serial port. Bear in mind a successful getCard() function must have been executed before

    in order to get the card information.

    Example of use

    {uint8_t myMatrix [7][4]; // bidimensional matrix for storing the values inside the card (7

    // rows, 4 columns)uint8_t state = 1; // stores the status of the executed command (0 = success)...RFID125.requestReadCard(1, 7); // asks the module to send the read command (T5557 card, 7

    // blocks)state = RFID125.getCard(myMatrix); // receives the response to the requestReadCard() commandif (state == 0) // it only makes sense to print a card if a card was found{ RFID.printCard(myMatrix); // prints the content of a T5557 card via the serial port}}

    8.10. Writing data in a block of a T5557 card

    It sends to the module the command for writing 4 bytes in one block of a T5557 card. The card must not be protected by

    password.

    The execution of this function does not ensure that the data was written, but that the module was configured to do so. The user

    should manually check the successful write manually, or using the funtion writeBlockAndCheck().

    It is not advised to write in blocks 0x00, 0x01, 0x07 unless you are an advanced user. You could leave your card unaccessible.

    The data blocks, availble for the user, are from number 0x02 to 0x06, so there are 20 bytes of total capacity in each card. If the

    Password Mode is not enabled, the user can write in the block number 0x07 like in any other data block.

    One execution is needed for each block we want to write.

    Example of use

    {uint8_t block = 0x04; // stores the number of block to be writtenuint8_t data0 = 0x13; // stores the data we want to writeuint8_t data1 = 0x12;uint8_t data2 = 0x19;

    uint8_t data3 = 0x83;...RFID125.writeBlock(block, data0, data1, data2, data3); // writes the code 13121983 (hex) in the

    // block 0x04. The card must not be protected by password.}

    8.11. Writing data with password in a block of a T5557 card

    It sends to the module the command for writing 4 bytes in one block of a T5557 card. The card is supposed to be protected by

    a 4-byte password.

    The execution of this function does not ensure that the data was written, but that the module was configured to do so. The usershould manually check the successful write manually, or using the funtion writeBlockAndCheck().

    It is not advised to write in blocks 0x00, 0x01, 0x07 unless you are an advanced user. You could leave your card unaccessible.

  • 8/9/2019 Rfid 125-Networking Guide

    19/24-19- v0.2

    Libeliums API

    The data blocks, availble for the user, are from number 0x02 to 0x06, so there are 20 bytes of total capacity in each card. If the

    Password Mode is not enabled, the user can write in the block number 0x07 like in any other data block.

    One execution is needed for each block we want to write.

    Example of use

    {uint8_t block = 0x04; // stores the number of block to be writtenuint8_t data0 = 0x13; // stores the data we want to writeuint8_t data1 = 0x12;uint8_t data2 = 0x19;uint8_t data3 = 0x83;uint8_t pass0 = 0xFA; // stores the password of the carduint8_t pass1 = 0xBA;uint8_t pass2 = 0xDA;uint8_t pass3 = 0x11;...// writes the code 13121983 in the block number 0x04. The card is supposed to be protected by

    // the password FABADA11 (hex):RFID125.writeBlockWithPass(block, data0, data1, data2, data3, pass0, pass1, pass2, pass3);}

    8.12. Writing data in a block of a T5557 card and checking it

    It sends to the module the command for writing 4 bytes in one block of a T5557 card. The card must not be protected by password.

    Then the function reads that block and checks that the correct data was written. It is useful to do these 2 steps in just one.

    So this function ensures that the data was written successfully, unlike the function writeBlock().

    It is not advised to write in blocks 0x00, 0x01, 0x07 unless you are an advanced user. You could leave your card unaccessible.

    The data blocks, availble for the user, are from number 0x02 to 0x06, so there are 20 bytes of total capacity in each card. If the

    Password Mode is not enabled, the user can write in the block number 0x07 like in any other data block.

    One execution is needed for each block we want to write.

    Example of use

    {uint8_t block = 0x04; // stores the number of block to be writtenuint8_t data0 = 0x13; // stores the data we want to writeuint8_t data1 = 0x12;uint8_t data2 = 0x19;

    uint8_t data3 = 0x83;uint8_t state = 1; // stores the status of the executed command (0 = success)...// writes the code 13121983 (hex) in the block 0x04. The card must not be protected by// password. If the check operation went well, returns 0, and 1 otherwise:state = RFID125.writeBlockAndCheck(block, data0, data1, data2, data3);}

    8.13. Writing data with password in a block of a T5557 card and

    checking it

    It sends to the module the command for writing 4 bytes in one block of a T5557 card. The card is supposed to be protected by a

    4-byte password. Then the function reads that block and checks that the correct data was written. It is useful to do these 2 steps

    in just one.

  • 8/9/2019 Rfid 125-Networking Guide

    20/24-20- v0.2

    Libeliums API

    So this function ensures that the data was written successfully, unlike the function writeBlockWithPass().

    It is not advised to write in blocks 0x00, 0x01, 0x07 unless you are an advanced user. You could leave your card unaccessible.

    The data blocks, availble for the user, are from number 0x02 to 0x06, so there are 20 bytes of total capacity in each card. If the

    Password Mode is not enabled, the user can write in the block number 0x07 like in any other data block.

    One execution is needed for each block we want to write.

    Example of use

    {uint8_t block = 0x04; // stores the number of block to be writtenuint8_t data0 = 0x13; // stores the data we want to writeuint8_t data1 = 0x12;uint8_t data2 = 0x19;uint8_t data3 = 0x83;uint8_t pass0 = 0xFA; // stores the password of the carduint8_t pass1 = 0xBA;

    uint8_t pass2 = 0xDA;uint8_t pass3 = 0x11;...// writes the code 13121983 in the block number 0x04. The card is supposed to be protected// by the password FABADA11 (hex). If the check operation went well, returns 0, and 1// otherwise:state = RFID125.writeBlockWithPass(block, data0, data1, data2, data3, pass0, pass1,pass2,pass3);}

    8.14. Setting and enabling Password Mode into a T5557 card

    It sends to the module the command for writing 4 bytes in the password block of a T5557 card, and then it enables the PasswordMode. The card must not be protected by password.

    Note that if the function is not correctly executed you could leave your card unaccessible.

    Example of use

    {uint8_t pass0 = 0xFA; // stores the new password of the carduint8_t pass1 = 0xBA;uint8_t pass2 = 0xDA;uint8_t pass3 = 0x11;...

    // sets the password FABADA11 in the block number 0x07 of a card and enables the Password// Mode. The card must not be protected by password. Returns 0 if everything went well,// and 1 otherwise:state = RFID125.passwordOn(pass0, pass1, pass2, pass3);}

    8.15. Disabling Password Mode into a T5557 card

    It sends to the module the command for writing in the block 0x00 of a T5557 card, for disabling the Password Mode. The card is

    supposed to be protected by a 4-byte password. The function provide this old password so that it can write.

    If the user does not know the password of the card, it is not possible to disable the Password Mode.

    Note that if the function is not correctly executed you could leave your card unaccessible.

  • 8/9/2019 Rfid 125-Networking Guide

    21/24-21- v0.2

    Libeliums API

    Example of use

    {uint8_t pass0 = 0xFA; // stores the old password of the carduint8_t pass1 = 0xBA;uint8_t pass2 = 0xDA;

    uint8_t pass3 = 0x11;...// access the card with the password FABADA11 and writes in the block number 0x00 of a card for// disabling the Password Mode. Returns 0 if everything went well, and 1 otherwise:state = RFID125.passwordOff(pass0, pass1, pass2, pass3);}

  • 8/9/2019 Rfid 125-Networking Guide

    22/24-22- v0.2

    Time of execution of the functions

    9. Time of execution of the functionsThe following is a list of the time it takes to execute the main functions:

    readSerialNumber(): 1500 ms

    requestReadCard(): 4 ms

    getCard(): 500 ms

    printCard(): 200 ms

    writeBlock(): 2000 ms

    writeBlockAndCheck(): 2500 ms

    So a full read of a T5557 card could take around 700 ms and a standard write in a block, 2 seconds.

    All the data blocks of a T5557 card can be read in about 10 seconds. This indicates that the maximum read rate is 2 bytes per

    second.

    10. Code exampleWhat follows is a complete example of the RFID module. Most of all the features are shown.

    // variables declaration:// the built-in LED pinint led = 13;// pin to wake the module up from sleep modeint wake_pin = 8;

    // bidimensional matrix for storing the values inside the card (7 rows, 4 columns):

    uint8_t myMatrix [7][4];

    uint8_t state = 1;

    uint8_t valueToStore = 0x00;

    void setup(){ // start serial port 19200 bps: Serial.begin(19200); delay(500);pinMode(led, OUTPUT);

    Serial.println(RFID @ 125 KHz module started in Read and Write Mode);

    /*// congure card programming parameters

    // command: FF 01 06 40 32 64 5A 1E 60 B5 uint8_t vCong [13] = {0xFF, 0x01, 0x06, 0x40, 0x32, 0x64, 0x5A, 0x1E, 0x60, 0xB5};// setting mode

    for (int i=0; i

  • 8/9/2019 Rfid 125-Networking Guide

    23/24-23- v0.2

    Code example

    void loop(){ // read the card: Byte track Mode - Manchester RF/64 7 blocks

    requestReadCard(1, 7); // mode = 1, blocks to read = 7digitalWrite(led, HIGH); // just for signaling

    Serial.println(\nwaiting card to read..); digitalWrite(led, LOW); // just for signaling state = getCard(myMatrix); if (state == 0) // if there is a card detected { printCard(myMatrix); // print the cards blocks blinkLED(); // blink the LED for signalling

    // write card Serial.println(waiting card to write ...); digitalWrite(led, HIGH); // just for signaling delay(1000);

    Serial.print(writing: ); writeByte(valueToStore); Serial.println();

    // write blocks 2, 3, 4, 5 and 6 // warning !!! do not write block 1 or 7 if you are not an advanced user!!! writeBlock(2, valueToStore, valueToStore, valueToStore, valueToStore); writeBlock(3, valueToStore, valueToStore, valueToStore, valueToStore); writeBlock(4, valueToStore, valueToStore, valueToStore, valueToStore); writeBlock(5, valueToStore, valueToStore, valueToStore, valueToStore); writeBlock(6, valueToStore, valueToStore, valueToStore, valueToStore);

    // write block 4 again and check Serial.print(\r\n writing again block 4: ); state = writeBlockAndCheck(4, valueToStore, valueToStore, valueToStore, valueToStore); if (state == 0) { Serial.println(\r\n block 4 was correctly written); } else { Serial.println(\r\n *** block 4 was NOT correctly written); }

    Serial.println(\r\n card ready!!!);

    // add 1 to the value to store in card

    if (valueToStore == 0xFF) { valueToStore = 0x00; } else { valueToStore++; }

    delay(1000); }}

  • 8/9/2019 Rfid 125-Networking Guide

    24/24

    Code examples and extended information

    11. Code examples and extended informationFor more information about the Waspmote hardware platform go to:

    http://www.libelium.com/waspmote

    http://www.libelium.com/support/waspmote

    http://www.libelium.com/development/waspmote

    http://www.libelium.com/waspmotehttp://www.libelium.com/support/waspmotehttp://www.libelium.com/development/waspmotehttp://www.libelium.com/development/waspmotehttp://www.libelium.com/support/waspmotehttp://www.libelium.com/waspmote