Skip to content | Skip to navigation
Powered by RSPowered by RSPowered by RS

RFID tracking with mbed & RS-EDP - Pt.3: Logging data on a MySQL Server

Donatien

France

Using a microcontroller to acquire data is more than common, but remotely accessing this data is usually tricky, especially if you have multiple devices at different places.

Logging data to an SQL server is a really nice solution to this problem.
It provides reliability, easy access to the data on any computer (through the different SQL connectors that exist), can be coupled with a web server easily, etc.

MySQL & mbed

The mbed libraries provide a very neat "connector" to one of the most used SQL server, MySQL.

To try it out you can have a quick look at the MySQLClient cookbook page and its associated example program on the mbed website (http://mbed.org/cookbook/MySQL-Client).

Using this component you can easily connect to a server and execute SQL
requests to append data to a table for instance.

From the RFID tag to the database

For this design we will append a record in a table for each RFID tag "touch" event. The record will contain the location of the event, the tag ID and the time at which the event occured.

So our SQL request will look something like:

INSERT INTO mytable (TagId, LastLocationId, Timestamp) VALUES('12345678',3,'2010-07-27 12:52:53')

Our table structure is:

  Image

 

 

Reliability & Portability

In our implementation, a "Logger" class has been developed to ensure that every SQL request has  been executed properly.
Basically it queues every request and tries to execute them until they are, reconnecting to the server if necessary.

A "TagInfo" class creates the SQL request for our specific application from the event parameters.

Code & Reference

The commented code can be found here: http://mbed.org/users/donatien/programs/RSEDP_DPDemo/.
These classes can be found in the log/ directory.

Other posts in this series:

1. Introduction

2. Using an RWD module to read Mifare cards IDs

3. Logging data on a MySQL server

4. Putting it all together