Rifidi Services Jumpstart

From RifidiWiki

Jump to: navigation, search


There are a variety of services available to anyone who wishes to write a RifidiApp. These services can help you more easily perform tasks that would normally require you to write custom esper within your app itself. The services can't handle every scenario, but they do give you an option to use if your particular use case can make use of them.

This list is NOT meant to fully document these services, but rather to provide a quick reference for you to check when you are designing your app. More complete documentation can be found in the edge developer document, the most recent Javadocs, and the Northwind sample app.


Monitors a ReadZone or group of ReadZones and reports when a tag enters or leaves a reader or antenna in the readzone. Passing in an empty list for the ReadZones argument will monitor all readers. Passing in "true" for the "wholereader" argument will treat the entire list of readers and antennas passed in as a monolithic entity, only giving you a departed event if the tag leaves the entire entity rather than updating you of any internal movement of the tag within the readzone.


The StableSetService returns a list of tags representing a "group" after an allotted time has passed with no new tags arriving. For instance, if you place 30 tags in the readzone of the reader, assuming all tags can be read correctly it will return a list of 30 tags assuming no new tags are seen for the duration given.


Exactly the same as the StableSetService, however you can also place a limit on the number of tags that can show up before it automatically returns. If the tag limit is hit before the time duration of the StableSet runs out it will automatically return with all seen tags.


This service will notify you at given intervals of all tags currently seen at the given readzones.

RSSI Monitoring Service

This service monitors which readzone returns the highest average RSSI value for a tag in a given duration. It returns a reader and epc code when the reader with the highest RSSI value changes for the tag over the given timeframe

How to use a Service

For an example of how to use a service, refer to the Northwind application referred to in the Developer's Guide.

Here is a list of all the steps you will need to get an instance of the ReadZoneMonitoringService running. All other services will be set up in a way that is very similar to this. The code examples used are taken from the Northwind example.

1. Get a reference the service in your spring.xml file:

<osgi:reference id="readZoneMonitoringService" interface="org.rifidi.edge.api.service.tagmonitor.ReadZoneMonitoringService" />

Then inject it into your application (second to last line):

<bean id="Northwind" class="org.rifidi.edge.northwind.NorthwindApp">
	<constructor-arg index="0" value="Northwind" />
	<constructor-arg index="1" value="Shipping" />
	<property name="stableSetService" ref="stableSetService" />
	<property name="readZoneMonitoringService" ref="readZoneMonitoringService" />

The "name" attribute is the name of the method spring will look for to inject the property into in your application class, although the method itself will have a "set" prefix to it. So as the name is "readZoneMonitoringService", spring will look for a method called "setReadZoneMonitoringService" in the class "org.rifidi.edge.northwind.NorthwindApp".

2. Prepare your application class to receive the injection from Spring:

	public void setReadZoneMonitoringService(ReadZoneMonitoringService rzms) {
		this.readZoneMonitoringService = rzms;

In this case I set a class variable called "readZoneMonitoringService" from this method. Now that the readZoneMonitoringService (RZMS from now on) is set, we can move on to the subscribers. There are 2 subscribers that are created and sent to the RZMS in the Northwind, however we'll just concentrate on one of them for this example. First, we'll create a subscriber class and implement the ReadZoneSubscriber method:

public class NorthwindReadZoneSubscriber implements ReadZoneSubscriber {
	private NorthwindApp app;
	private String location = null;
	private Boolean isDockDoor = null;
	public NorthwindReadZoneSubscriber(NorthwindApp app, String location) {
		this.app = app;
		this.location = location;
		this.isDockDoor = isDockDoor;
	public void tagArrived(TagReadEvent tag) {
		System.out.println("Tag arrived at location " + location + ": " + tag.getTag().getFormattedID());
	public void tagDeparted(TagReadEvent tag) {
		System.out.println("Tag departed at location " + location + ": " + tag.getTag().getFormattedID());

For simplicity's sake I've removed most of the functionality and all of the comments from this class. The actual class itself is much more descriptive, and much more useful. For this class, an alert will be printed whenever a tag arrives in the monitored readzone. You can do whatever you wish when the tag arrives, however, such as inserting it into a database, posting the result to facebook, or adding an event to Amazon cloud.

Now that we have a subscriber class, we can create one of them in our application class (in the start method):

NorthwindReadZoneSubscriber dock_door_subscriber = new NorthwindReadZoneSubscriber(this, DOCK_DOOR, true);

The final variable DOCK_DOOR is a string describing the location that we pass in to use in the System.out statement.

We also have to define a readzone. In the case of the Northwind I simply defined a readzone in the "readzone-dockdoor.properties" file in the "readzone" folder inside the "Northwind" folder in the app. The "readzone" folder goes in the same folder as your regular properties files (so remember to put the entire "Northwind" folder in "RifidiHome/applications" if you are running from eclipse):

#The ID of the reader

#The antennas from the reader

#If we want to filter based on a regular expression, use this property

#If set to true, only use tags that match the above pattern. If set to false, filter out tags
# that match the above patter.

Lines starting with "#" are ignored. We don't need to define specific antennas to listen to, nor do we need to filter tags based on their ID, so I've set the readerID to "Alien_1" (the reader we want to listen to for tags), and left the "antennas" property blank (which means "listen to all antennas"). The rest is unneeded for this example and commented out.

In the start method we will retrieve the readzone:

ReadZone dock_door = super.getReadZones().get("dock_door");

Now we need to subscribe to the readzone:

this.readZoneMonitoringService.subscribe(dock_door_subscriber, dock_door, this.dockdoor_timeout, TimeUnit.SECONDS);

We give a subscriber, the readzone, and a timeout with given units. Now, whenever a tag arrives at the readzone, the "arrived" method will get called in the subscriber class.

Example Rifidi Services Application

Here is where one can find the sources for the sample Rifidi Services Application Rifidi Services App using Rifidi SDK Note: The example application show the use of all the out of the box Rifidi Services mentioned above in a scenario for monitoring events for a front door with one reader ( 1 to 1 relationship between readzone and reader) and back door with 2 readers (1 to many relationship between readzone and reader using regular expressions)

Personal tools