Failed experiments and bad code for physical computing, data visualization and video delivery.

Flex 3 + AIR + RFID + AMFPHP + SMS

Posted: October 13th, 2007 | Author: Barton | Filed under: AIR, AS3, Flex, RFID, Web Services |

I had originally wanted to build this project with my Parallax RFID reader, but since I can’t interface it with the Make Controller until Liam at MakingThings fixes the serial BLOB implementation fixed in mchelper 2.0, I decided to complete a proof-of-concept with a Phidgets RFID reader. The application is pretty straightforward - it consists of an RFID tag embedded in a cell phone that is read for its unique ID, prompts a user to enter some data and then remembers their personal data when they return. While the premise is simple, there are a few moving parts required to stitch it together.


But first, before an explanation, here’s a demo of the application:

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

The Phidgets RFID Reader
PhidgetRFID is a EM4102 125Khz protocol reader. This means that it does not have the capability to write to RFID tags, only read from them. While this is just fine, I point it out so that you are aware of this fact if you are new to RFID. It should also be noted that RFID readers like these usually fit into a larger architecture that consists of a database of some sort. This allows RFID tag IDs to be stored along with additional metadata.

This particular reader is nice in that you can connect it directly to a computer (Mac, Windows and Linux support) via USB and simply run a web service that provide connectivity to the board. In this example, that process is abstracted away in the AS3 classes that Phidgets provides (they also have a .SWC if you prefer that), so connecting to it and reading tags from it is really quite easy.

After installing the software from Phidgets, I set up an alias in my bash profile set up to make it easy to fire up the web service: alias phidget=’/usr/bin/phidgetwebservice21′. That way, I just type phidget into a terminal window and it starts. After plugging the RFID reader into an open USB port, it’s ready to communicate. That’s really all there is to setting it up since there is no microcontroller involved.

Flex Builder 3 and AIR
I opted to build this as an AIR application because an application like this is most applicable in a kiosk scenario, rather than as a web application. Anyway, connecting to the RFID reader using Flex is quite easy and a majority of the code is devoted to setting up event handlers:

creationcomplete="onCreationComplete()">
 
<!--[CDATA[
 
import com.phidgets.*;
 
import com.phidgets.events.*;
 
private var devRFID:PhidgetRFID;
 
private function onCreationComplete():void {
 
devRFID = new PhidgetRFID();
 
devRFID.addEventListener(PhidgetEvent.DETACH, onDetach);
 
devRFID.addEventListener(PhidgetEvent.ATTACH, onAttach);
 
devRFID.addEventListener(PhidgetErrorEvent.ERROR, onError);
 
devRFID.addEventListener(PhidgetDataEvent.TAG, onTag);
 
devRFID.addEventListener(PhidgetDataEvent.TAG_LOST, onTagLoss);
 
devRFID.open("localhost", 5001, "1234");
 
}
 
private function onAttach(pdeEvent:PhidgetEvent):void{
 
trace(pdeEvent);
 
devRFID.Antenna = true;
 
devRFID.LED = true;
 
}
 
private function onDetach(pdeEvent:PhidgetEvent):void{
 
trace(pdeEvent);
 
}
 
private function onTag(pdeEvent:PhidgetDataEvent):void {
 
&nbsp;	trace(pdeEvent);
 
//This is where all of the good stuff goes...
 
}
 
private function onTagLoss(pdeEvent:PhidgetDataEvent):void {
 
trace(pdeEvent);
 
}
 
private function onError(pdeEvent:PhidgetErrorEvent):void {
 
trace(pdeEvent);
 
}
 
]]-->

If you’re interested in the rest of the code, download the source. Also, a quick disclaimer that this was just a quick proof-of-concept and is all in a single MXML file for simplicity rather than encapsulating objects and creating components.

AMFPHP Remoting
For server/Flash Player communication, I generally opt for remoting due to its ease of implementation and speed, especially if dynamic, database-driven calls are required for the application. In this case, PHP and MySQL will handle user data and authentication as well as consuming SMS services. I could write an entire article about AMFPHP and Flex 3, and probably will, but for now, I’ll just mention it and note that it in the source code.

SMS
In the demo version (I’m not releasing this portion publicly), I’ve also rigged up some PHP classes to send SMS messages. I found a service called Clickatell that provides SMS gateway services to a bunch of giant corporations like BBC, Vodafone and Oracle. However, they do actually offer services to substantially smaller entities such as myself, which is pretty cool. Not only that, but they offer a free trial of their services.

I’d recommend them if you only need to send outgoing SMS messages. If you are interested in two-way messaging, be prepared to pony up a large amount of cash for short codes (somewhere in the neighborhood of $1200/month) and message routing. The other alternative is to set up your own SMS gateway. However, keep in mind that while setting up your own gateway is easy, it is not cost effective for sending large numbers of text messages using a normal consumer account. It will end up being cheaper using a bulk service like Clickatell.

Source
Click here to download the source for the AIR source and installer, PHP code and MySQL schema.


9 Comments on “Flex 3 + AIR + RFID + AMFPHP + SMS”

  1. 1 noah said at 11:13 am on October 14th, 2007:

    That is very, very, very cool indeed.

    I can already think of about 20 different implementations for this…

    Thanks for the demo!

  2. 2 Ben Arent said at 8:41 am on December 16th, 2007:

    this is great stuff. I’m going to be working on a very similar project soon. I’m desiging a social communication project for the eldery, keep an eye on my blog. Thanks for sharing.

  3. 3 Hans said at 9:53 am on July 22nd, 2008:

    this is, so SO cool.
    How did you get the text/dialogue to happen on your computer?

  4. 4 Johny said at 11:56 am on September 19th, 2008:

    Thanks for the great article, just wanted to let you know that the demo video is not loading.

  5. 5 Barton said at 5:10 pm on November 5th, 2008:

    I finally got around to fixing the video. I got rid of my FMS server a while back and neglected to realized that I had hosted the streaming version of that video there. Now, I’m taking advantage of someone else’s expensive system architecture (thanks, Vimeo) to deliver my videos.

  6. 6 maurizio said at 12:10 am on February 1st, 2009:

    Excelent!!. Thanks for the great idea.

    Sos un capo, amigoo..

    Saludoss

  7. 7 jubari said at 12:20 pm on May 9th, 2009:

    We are currently working on a project with RFID and Flex. Since http://www.merapiproject.net is still in closed alpha you saved my day ;)

    Thanks.

  8. 8 George Molson said at 10:24 pm on May 23rd, 2009:

    Exceptional work! I am building ATM (Automatic Teller Machine) software and I want to port my Flash demo to Linux / Flex for security reasons. I want the final version to integrate with an RFID sensor and USB cash dispenser. My biggest obstacle is that the majority of the new cash dispenser drivers are for windows. I don’t know who the geniuses (genii?) behind that one are… Anyways would love to hear about any cool ideas you have. Smart people are hard to find.

  9. 9 3wstudio» Conectándose al hardware directamente con AS3 said at 7:58 pm on September 23rd, 2009:

    [...] Flex3 + AIR + RFID + AMFPHP + SMS: http://blog.phy5ics.com/2007/10/13/flex-3-air-rfid-amfphp-sms/ [...]


Leave a Reply