Tag-it

RFID integration in Ruby

Active RFID can be a game changer in certain fields (time-clock, fleet tracking, etc). Why are you still doing it the old fashioned way?

Tag-it is a ruby gem that you can start up to monitor an RFID receiver; just create an observer to watch the tag events roll in and you can automatically tell your webservice or other system when things arrive and depart without having to do any data input at all.

Installation

The recommended way is that you get the gem hosted on rubygems.org:

gem install tag-it

I suggest you use ruby 1.8.7, I’ve had problems so far with ruby 1.9.x and this project.

Prerequisites:

1) You will need the hardware (an RFID receiver and RFID tags). I bought mine from cliste.sailwhatcom.com/, and these are the only ones the library will work with out of the box yet.

2) you will need the serial-to-usb port driver for your OS installed: www.prolific.com.tw/eng/downloads.asp?ID=31

3) tag-it uses the ‘ruby-serialport’ gem for device communication. Make sure you have that installed and working.

Example usage

Typical usage involves building an observer like this:

class YourCustomObserver
  def update(tag,strength,event)
    if event == :tag_arrived
      # do something because a tag has come into range
    elsif event == :tag_departed
      # do something because a tag has gone out of range
    elsif even == :pulse
      # let something know the client is still active
    end
  end
end

And then attaching it to a tag-it tag_tracker like this:

require "tag_it"
port = SerialPort.new("/dev/tty.yourport",{:baud=>9600})
tracker = TagIt::TagTracker.new(port)
watcher = YourCustomObserver.new
tracher.add_observer(watcher)
tracker.start!

the tracker will run indefinitely, pulling in tag ids as they come into range and leave the area, and dispatch the necessary events. It also will dispatch a “pulse” event every 3 minutes so you know that the client is still running. Right now there are 3 events – :tag_arrived when the tag comes into range, :tag_departed when it leaves, and the :pulse event every three minutes. The other parameters to the update method are the tag id (“1nrw”) and the Relative Signal Strength (an integer: 34, 86, etc) indicating how close to the source the tag is.

ATTENTION!: In the “pulse” event, the tag parameter will actually be an array of currently in-range tags

As of version 0.3.0, you don’t have to use the tracker. If you just want to fetch a quick snapshot of all tags currently in range, the TagIt TagSnapshot will do the trick:

require "tag_it"
port = SerialPort.new("/dev/tty.yourport",{:baud=>9600})
snapshot = TagIt::TagSnapshot.new(port)
tags = snapshot.shoot!
# tags => ["1nri","1okD","1nrP"]

Both the Tracker and the Snapshot class are subclasses of TagIt::Monitor, which does the heavy lifting of tag parsing, so if you want to engineer your own functionality, you could make a custom TagIt implementation by making your own subclass and taking advantage of the “monitor” method which you can pass a block to (it will yield each tag name it finds back to you, one by one).

Happy Tagging!

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 evizitei. See LICENSE for details.