API REST

In this part we are going to see examples of how to use Ewetasker application making API REST requests. This is the best way to integrate Ewetasker with other applications.

To create a new rule

POST http://localhost:8080/api/mobile

Example for the rule When users enters the office (< 2 meters) then switch on the light. The request parameters are:

{
 'command': 'createRuleParams',
 'rule_channel_one': 'presence',
 'rule_title': 'light automation',
 'rule_action_title': 'Turn on',
 'rule_description': 'Presence Light',
 'rule_channel_two': 'hueLight',
 'rule_event_title': 'Presence Detected At Distance Less Than',
 'event_param_1': '5544',
 'event_param_2': 2,
 'rule_creator': 'admin',
 'rule_place': 'GSI Lab'
}

To get the channels available

POST http://localhost:8080/api/mobile

The request parameter is:

{'command': 'getChannels'}

The server response has this JSON structure:

[{
  "title":"",
  "description":"",
  "events":[{
     "title":"",
     "prefix":"",
     "rule":"",
     "numParameters":""
   }],
   "actions":[{
      "title":"",
      "prefix":"",
      "rule":"",
      "numParameters":""
  }]
}]

To evaluate the rules created

POST http://localhost:8080/api/events

Example to evaluate the rule When users enters office (< 2 meters) then switch on the light. The request parameters are:

{
 "user": "admin",
 "inputEvent":"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
 @prefix ewe: <http://gsi.dit.upm.es/ontologies/ewe/ns/#>.
 @prefix ewe-presence: <http://gsi.dit.upm.es/ontologies/ewe-connected-home-presence/ns/#>.
 ewe-presence:PresenceSensor rdf:type
 ewe-presence:PresenceDetectedAtDistance.
 ewe-presence:PresenceSensor ewe:sensorID '5544'.
 ewe-presence:PresenceSensor ewe:distance 0."
}

If the event accomplish the rule, the server response will contain all the actions that must be triggered:

{
 "success":"1",
 "actions":
    [{
      "url":"",
      "channel":"",
      "action":"",
      "parameter":""
    }]
}

However, if the event doesn’t accomplish the rule, the server response will be this:

{
 'actions': [],
 'success': 1
}