Introduction: Cat-a-log
My wife was always worried when she had not seen all of our cats daily, and sometimes stayed up late to see them all in the house.
All of our cats have a RFID chip implanted to identify them, so the idea was to build a RFID reader in the catflap. The data is collected in a database and made available on the Internet. This was already foreseen when we built the house, so there is a CAT5 cable from the front door to a patch panel.
Every time a cat passes the catflap, the RFID is read, stored in a database and published on the Internet as shown above
Step 1: Software
The data is collected and made available on a Linux box with an Apache web server
Data collection
The MySQL database schema consists of 2 tables; "entry" with the chip-id and the date-time and "name" with chip-id and the name of the cat. The data is gathered with a small Perl program:
#!/usr/bin/perl
use strict;
use warnings;
use Device::SerialPort;
use DBI;
my $con = DBI->connect("dbi:mysql:dbname=cats","username","password",{RaiseError => 1},) or die "Connect DBI::errstr";
my $port = new Device::SerialPort("/dev/ttyUSB0");
print "open err " unless ($port);
$port->baudrate(9600);
$port->parity("none");
$port->databits(8);
$port->stopbits(1);
$port->handshake("none");
$port->write_settings;
$port->are_match("\r", "\n");
$port->lookclear;
my $resp='';
while (1)
{
until ( $resp ne '')
{
$resp=$port->lookfor;
sleep 1;
}
if (length($resp) ge 14)
{
#filter out disturbances on the serial connection which can upset the SQL server
if ($resp =~ m/^[0-9]{15}$/)
{
print $resp . "\n";
my $sth = $con->prepare("INSERT INTO entry (zeit,chip) VALUES (now(),\"" . $resp . "\")") or warn "Prepare DBI::errstr";
my $rc = $sth->execute() or warn "Excecute DBI::errstr";
}
}
$resp = '';
$port->lookclear;
}
DBI:close();
$port->close;
Data presentation
The data is presentend as a table of the 4 most recent events per cat using a simple php program.
Please look at the screenshot of the code as well, writing about HTML on a HTML pages does not always work..
query('SELECT * FROM name') or die(' select name');
if ($names->num_rows > 0)
{
while ($namerow = $names->fetch_assoc() )
{
echo ""; $name = $namerow["name"];
echo '';
$sel = 'SELECT zeit FROM entry WHERE chip=' . '\'' . $namerow["chip"] . '\'' . ' ORDER BY zeit DESC LIMIT 4'; $times = $mysqli->query($sel) or die('Error select entry');
if ($times->num_rows > 0)
{
while ($timerow = $times->fetch_assoc() )
{
$time = date_create($timerow["zeit"]);
echo '";
}
}
else
{
echo "";
}
echo "";
}
}
else
{
die('No names');
}
$mysqli->close();
?>
Step 2: Hardware
At first I tried the sytem according to the thesis from Leonid Kuritsin, but with an EM4095 in stead of the U2270, but I could not get reliable readings. After that I decided for the RFIDLOG from Priority 1 Design which has all the required functions and is not too expensive.
The antenna consists of about 100 turn of 0.2 mm enameled wire around the catflap. With the command "MOF" of the reader the number of turns is adjusted till the frequency show 134 kHz.
Beside logging the serial number and the time, the reader also sends the serial number over the serial port as soon as a tag is read.
A warning to the readers in the US: this system uses an ISO 11784 /ISO 11785 reader. Please check that your reader supports the US animal tags which commonly use another protocol.