Simple concept, put an RFID chip on your cat and a reader by the door. Tweet whenever the cat uses the door.The reader is a APSX 15.56MHZ RW-210 reader. The RFID is a Sakymat LOGI TAG aka “laundry tag”. The server is a Hush mini-ITX machine with a 32G CF chip instead of a hard drive. The code is written in Python running on Fedora Core 10.Pictures will follow, the code is below:
This is the first draft of the catdoor.py
[geshi lang=”python” nums=”0″ ]
#!/usr/bin/python
import twitter from apsx import *rfid_open(0) api = twitter.Api(username='catdoor', password='xxxxxx')# let's blink some # for i in range(1,50) : red_LED(True) green_LED(True) red_LED(False) green_LED(False)while 1 :
# get a button # b = read_UID() sleep(.1)
if b : green_LED(True) print 'got a button: %s' % hexer(b) status = api.PostUpdate('Cat at the door UID: %s' % hexer(b)) print 'TWEET! | %s' % status.text
while b : sleep(1) b = read_UID()
green_LED(False)
else : red_LED(True) sleep(.1) red_LED(False) sleep(.9)
[/geshi]
The apsx.py code to talk to the APSX board is here:
[geshi lang=”python” nums=”0″ ]
#
# Python code to talk to a APSX RFID Module #
# Not a complete set of functions but enough to get my cat door working.
#
# 10 Jan 09 JV - Created
# import serialser = NonePresetValue = 0xffff Polynomial = 0x8408
def crc(DataBytes) : "APSX ISO 15693 CRC-16"
CRCValue = PresetValue for b in DataBytes : CRCValue = CRCValue ^ ord(b)
for j in range(0,8) : if CRCValue & 1 : CRCValue = (CRCValue>>1) ^ Polynomial else : CRCValue >>= 1
CRCValue = ~CRCValue - 65536 CRCValue &= 0xffff CRCLSB = CRCValue % 256 CRCMSB = CRCValue >> 8
return (CRCLSB, CRCMSB)
def read_UID() : "Read a UID or None if not exactly 12 bytes" ser.write('\0xfa') s = ser.read(12) if len(s) == 12 : return s return None
def red_LED(on) : if on : ser.write('\xfd') else : ser.write('\xfc') sleep(.02)
def green_LED(on) : if on : ser.write('\xff') else : ser.write('\xfe') sleep(.02)
def rfid_open(port) : "call to open the serial port"
global ser if ser : if ser.isOpen() : ser.close() ser = serial.Serial(port, 19200, timeout=1) print ser.portstr
def hexer(s) : "return a hex string"
h = '' for c in s : h += '0x%02x ' % ord(c) return h
#red_LED(True) #green_LED(True) #red_LED(False) #green_LED(False)
#ser.close()
[/geshi]