Rifidi App API

From RifidiWiki

Jump to: navigation, search

Introduction

Starting in Rifidi 3.1, Rifidi Apps can now be manged via rest

Note: In order for the properties to take effect the associated Rifidi App will need to be stopped and started. This allows for more fine grain control of when properties should take effect (as opposed to having the apps restart dynamically as properties change while a app is running)

The operations available are:

  • Get/Stop/Start App
  • Get/Set Application and Group Properties
  • Get/Add Delete Readzones
  • Get/Set Readzone Properties

Command Example

Note: localhost can be substituted with IP address/Host name of Rifidi Edge Server. Port can be changed in Rifidi configuration

apps command example

  • apps - returns a list of available applications

Request (via HTTP Post/Get) "apps" command like this:

http://localhost:8111/apps

Response:

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <apps>
      <app>
         <id>AppService:ReadZones</id>
         <number>0</number>
         <status>STARTED</status>
      </app>
      <app>
         <id>AppService:SensorStatus</id>
         <number>1</number>
         <status>STARTED</status>
      </app>
      <app>
         <id>RifidiManagement:RifidiManagementApp</id>
         <number>2</number>
         <status>STARTED</status>
      </app>
      <app>
         <id>AppService:UniqueTagInterval</id>
         <number>3</number>
         <status>STARTED</status>
      </app>
      <app>
         <id>AppService:StableSet</id>
         <number>4</number>
         <status>STARTED</status>
      </app>
      <app>
         <id>AppService:LimitStableSet</id>
         <number>5</number>
         <status>STARTED</status>
      </app>
      <app>
         <id>AppService:UniqueTagBatchInterval</id>
         <number>6</number>
         <status>STARTED</status>
      </app>
      <app>
         <id>AppService:RSSI</id>
         <number>7</number>
         <status>STARTED</status>
      </app>
      <app>
         <id>Diagnostic:GPIO</id>
         <number>8</number>
         <status>STOPPED</status>
      </app>
      <app>
         <id>Diagnostic:Serial</id>
         <number>9</number>
         <status>STOPPED</status>
      </app>
      <app>
         <id>Diagnostic:Tags</id>
         <number>10</number>
         <status>STARTED</status>
      </app>
      <app>
         <id>Diagnostic:TagGenerator</id>
         <number>11</number>
         <status>STARTED</status>
      </app>
      <app>
         <id>Monitoring:ReadZones</id>
         <number>12</number>
         <status>STARTED</status>
      </app>
      <app>
         <id>Monitoring:Tags</id>
         <number>13</number>
         <status>STARTED</status>
      </app>
      <app>
         <id>Monitoring:SensorStatus</id>
         <number>14</number>
         <status>STARTED</status>
      </app>
   </apps>
</response>

stopapp command example

  • stopapp/{appID} - stops a Rifidi Application

Request (via HTTP Post/Get) "stopapp" command like this:

http://localhost:8111/stopapp/2

Response:

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Success</message>
</response>

startapp command example

  • startapp/{appID} - starts a Rifidi Application

Request (via HTTP Post/Get) "startapp" command like this:

http://localhost:8111/startapp/2

Response:

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Success</message>
</response>

loadapp command example (as of Rifidi Edge 3.3.)

  • loadapp/{groupname} - loads a Rifidi Application

Request (via HTTP Post/Get) "loadapp" command like this:


http://localhost:8111/loadapp/HelloWorld

Will load the "HelloWorld" appliction.

Response:

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Success</message>
</response>

adddefaultapp command example (as of Rifidi Edge 3.3.)

  • adddefaultapp/{groupname} - sets a Rifidi Application to start by default when edge server starts

Request (via HTTP Post/Get) "adddefaultapp" command like this:


http://localhost:8111/adddefaultapp/HelloWorld

Note:Always have a newline after the last entry if one manually modifies the default.ini (where server looks for list of applications to load a server start).

Response:

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Success</message>
</response>

get application properties command example

  • getAppProperties/{appID} - returns a list of properties for an application

Request (via HTTP Post/Get) "getAppProperties" command like this:

Response success:

http://localhost:8111/getAppProperties/10

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <attributes>
      <entry>
         <key>RecentTagTimeout</key>
         <value>1 min</value>
      </entry>
      <entry>
         <key>LazyStart</key>
         <value>false</value>
      </entry>
   </attributes>
</response>

Response fail (if there is no properties file in file system):

http://localhost:8111/getAppProperties/3

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Application properties file not found for groupName: AppService and appName: StableSet</description>
</response>

Response fail (if there is no application given the id):

http://localhost:8111/getAppProperties/85

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Application with id 85 does not exist.</description>
</response>

set application properties command example

  • setAppProperties/{appID}/{properties} - sets a list of properties for an application
  • Note: In order for the properties to take effect the associated Rifidi App will need to be stopped and started. This allows for more fine grain control of when properties should take effect (as opposed to having the apps restart dynamically as properties change while a app is running)
  • Special characters: See how to send special characters in properties' values http://wiki.rifidi.net/index.php?title=Rifidi_App_API#Properties_with_special_characters

Request (via HTTP Post/Get) "setAppProperties" command like this:

Response success (in this case, if property already exists in properties file in file system, it is updated; otherwise it is added at the end of properties file. And if properties file does not exist in file system, it is created, according to structure and naming conventions):

http://localhost:8111/setAppProperties/7/LLRP_3_stableSetTime=7.0;anotherProp=val1

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Success</message>
</response>

Response fail (if there is a bad formed property=value pair):

http://localhost:8111/setAppProperties/7/LLRP_3_stableSetTime;anotherProp=val1

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Property with no recognizable value: LLRP_3_stableSetTime</description>
</response>

Response fail (if there is no application given the id):

http://localhost:8111/setAppProperties/87/LLRP_3_stableSetTime=4.0;anotherProp=val1

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Application with id 87 does not exist.</description>
</response>

get group properties command example

  • getGroupProperties/{appID} - returns a list of properties for a group

Request (via HTTP Post/Get) "getGroupProperties" command like this:

Response success:

http://localhost:8111/getGroupProperties/7

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <attributes>
      <entry>
         <key>mqttClientId</key>
         <value>stablesetstationApp</value>
      </entry>
      <entry>
         <key>threadSleepTime</key>
         <value>500</value>
      </entry>
      <entry>
         <key>mqttQos</key>
         <value>2</value>
      </entry>
      <entry>
         <key>mqttBroker</key>
         <value>tcp://localhost:1883</value>
      </entry>
   </attributes>
</response>

Response fail (if there is no properties file in file system):

http://localhost:8111/getGroupProperties/3

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Group properties file not found for groupName: AppService</description>
</response>

Response fail (if there is no application given the id):

http://localhost:8111/getGroupProperties/85

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Application with id 85 does not exist.</description>
</response>

set group properties command example

  • setGroupProperties/{appID}/{properties} - sets a list of properties for a group
  • Note: In order for the properties to take effect the associated Rifidi App will need to be stopped and started. This allows for more fine grain control of when properties should take effect (as opposed to having the apps restart dynamically as properties change while a app is running)
  • Special characters: See how to send special characters in properties' values http://wiki.rifidi.net/index.php?title=Rifidi_App_API#Properties_with_special_characters

Request (via HTTP Post/Get) "setGroupProperties" command like this:

Response success (in this case, if property already exists in properties file in file system, it is updated; otherwise it is added at the end of properties file. And if properties file does not exist in file system, it is created, according to structure and naming conventions):

http://localhost:8111/setGroupProperties/7/threadSleepTime=800;mqttQos=3

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Success</message>
</response>

Response fail (if there is a bad formed property=value pair):

http://localhost:8111/setGroupProperties/7/threadSleepTime=800;mqttQos

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Property with no recognizable value: mqttQos</description>
</response>

Response fail (if there is no application given the id):

http://localhost:8111/setGroupProperties/71/threadSleepTime=800;mqttQos=3

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Application with id 71 does not exist.</description>
</response>

get read zones command example

  • getReadZones/{appID} - returns a list of read zones for an application

Request (via HTTP Post/Get) "getReadZones" command like this:

Response success:

http://localhost:8111/getReadZones/7

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <attributes>
      <entry>
         <value>FPP_3</value>
      </entry>
      <entry>
         <value>FPP_4</value>
      </entry>
      <entry>
         <value>FPP_1</value>
      </entry>
      <entry>
         <value>FPP_2</value>
      </entry>
      <entry>
         <value>observable</value>
      </entry>
   </attributes>
</response>

Response success (if there are no read zones):

http://localhost:8111/getReadZones/3

<response>
    <attributes/>
</response>

Response fail (if there is no application given the id):

http://localhost:8111/getReadZones/33

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Application with id 33 does not exist.</description>
</response>

add readzone command example

  • addReadZone/{appID}/{readZoneName}/{properties} - adds a read zone for an application
  • Note: In order for the properties to take effect the associated Rifidi App will need to be stopped and started. This allows for more fine grain control of when properties should take effect (as opposed to having the apps restart dynamically as properties change while a app is running)
  • Special characters: See how to send special characters in properties' values http://wiki.rifidi.net/index.php?title=Rifidi_App_API#Properties_with_special_characters

Valid Readzone properties

  • readerID is the Service ID of the reader we will be using defined in the rifidi.xml
  • antennas (optional) are where you list the antennas. Blank means all antennas
  • tagPattern (optional) is where we can filter tags based on a regular expression.
  • matchPattern (optional) allows us to either match or exclude the filter pattern..

Request (via HTTP Post/Get) "addReadZone" command like this:

Response success (in this case, if read zone does not exist, it is created; otherwise it returns a fail message):

http://localhost:8111/addReadZone/7/FPP_5/antennas=3;readerID=My_Id

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Success</message>
</response>


Response fail (if there is a bad formed property=value pair):

http://localhost:8111/addReadZone/7/FPP_5/antennas=3;readerID=

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Property with no recognizable value: readerID</description>
</response>

Response fail (if there is no application given the id):

http://localhost:8111/addReadZone/71/FPP_5/antennas=3;readerID=My_Id

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Application with id 71 does not exist.</description>
</response>

Response fail (if there is a read zone already created with the same name):

http://localhost:8111/addReadZone/7/FPP_5/antennas=3;readerID=My_Id

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Readzone FPP_5 already exists.</description>
</response>

Response fail (if there are not the minimum required properties to create the read zone):

http://localhost:8111/addReadZone/7/FPP_5/antennas=3

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Required property readerID not found. Required ones are : readerID </description>
</response>

Response fail (if there are invalid properties for a read zone):

http://localhost:8111/addReadZone/7/FPP_5/antennas=3;prop2=4

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Invalid property prop2 for readzone. Valid ones are: readerID antennas tagPattern matchPattern </description>
</response>

delete readzone command example

  • deleteReadZone/{appID}/{readZoneName} - deletes a read zone for an application

Request (via HTTP Post/Get) "deleteReadZone" command like this:

Response success (in this case, if read zone exists, it is deleted; otherwise it returns a fail message):

http://localhost:8111/deleteReadZone/7/FPP_5

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Success</message>
</response>

Response fail (if there is no application given the id):

http://localhost:8111/deleteReadZone/75/FPP_5

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Application with id 75 does not exist.</description>
</response>

Response fail (if there is no read zone with that name):

http://localhost:8111/deleteReadZone/7/FPP_56

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Readzone FPP_56 does not exist</description>
</response>

get readzone properties command example

  • getReadZoneProperties/{appID}/{readZoneName} - returns a list of properties for a read zone

Valid Readzone properties

  • readerID is the Service ID of the reader we will be using defined in the rifidi.xml
  • antennas (optional) are where you list the antennas. Blank means all antennas
  • tagPattern (optional) is where we can filter tags based on a regular expression.
  • matchPattern (optional) allows us to either match or exclude the filter pattern..


Request (via HTTP Post/Get) "getReadZoneProperties" command like this:

Response success:

http://localhost:8111/getReadZoneProperties/7/FPP_3

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <attributes>
      <entry>
         <key>antennas</key>
         <value/>
      </entry>
      <entry>
         <key>readerID</key>
         <value>LLRP_3</value>
      </entry>
   </attributes>
</response>

Response fail (if there is no read zone given that name):

http://localhost:8111/getReadZoneProperties/7/FPP_35

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Readzone properties file not found for groupName: Gtux and appName: StableSetStationApp and readzone: FPP_35</description>
</response>

Response fail (if there is no application given the id):

http://localhost:8111/getReadZoneProperties/17/FPP_3

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Application with id 17 does not exist.</description>
</response>

set readzone properties command example

.

  • setReadZoneProperties/{appID}/{readZoneName}/{properties} - sets the properties for a read zone

Note: In order for the properties to take effect the associated Rifidi App will need to be stopped and started. This allows for more fine grain control of when properties should take effect (as opposed to having the apps restart dynamically as properties change while a app is running)

Valid Readzone properties

  • readerID is the Service ID of the reader we will be using defined in the rifidi.xml
  • antennas (optional) are where you list the antennas. Blank means all antennas
  • tagPattern (optional) is where we can filter tags based on a regular expression.
  • matchPattern (optional) allows us to either match or exclude the filter pattern..

Request (via HTTP Post/Get) "setReadZoneProperties" command like this:

Response success (in this case, if read zone exists, properties are set; otherwise it returns a fail message):

http://localhost:8111/setReadZoneProperties/7/FPP_4/readerID=MyReaderId;antennas=2

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Success</message>
</response>


Response fail (if there is a bad formed property=value pair):

http://localhost:8111/setReadZoneProperties/7/FPP_4/readerID=MyReaderId;antennas

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Property with no recognizable value: antennas</description>
</response>

Response fail (if there is no application given the id):

http://localhost:8111/setReadZoneProperties/37/FPP_4/readerID=MyReaderId;antennas=2

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Application with id 37 does not exist.</description>
</response>

Response fail (if there is no a read zone created with that name):

http://localhost:8111/setReadZoneProperties/7/FPP_32/readerID=MyReaderId;antennas=2

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Readzone FPP_32 does not exist.</description>
</response>

Response fail (if there are invalid properties for a read zone):

http://localhost:8111/setReadZoneProperties/7/FPP_3/readerID=MyReaderId;antennas=2;prop=val

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <message>Fail</message>
   <description>Invalid property prop for readzone. Valid ones are: readerID antennas tagPattern matchPattern </description>
</response>

Properties with special characters

Depending on the properties values, if there are special characters, you must encode them in order to properly send the values to restlet.

  • Note: You must encode only the url properties portion, in UTF-8 character encoding. For example if you need to set a property value that contains slashes, like this:

http://localhost:8111/setGroupProperties/7/mqttBroker=tcp://broker.mqtt-dashboard.com:1883 this is not an url recognized by restlet server due to slashes contained in mqttBroker property's value, so you must encode it, resulting in this encoded url (remember, encode only the url properties portion):

http://localhost:8111/setGroupProperties/7/mqttBroker%3Dtcp%3A%2F%2Fbroker.mqtt-dashboard.com%3A1883

Take a look at this encode client example:

https://transcends.svn.cloudforge.com/rifidi/rifidi/trunk/org.rifidi.edge.rest/src/org/rifidi/edge/rest/test/UrlEncodeHttpTestClient.java

Personal tools