NAV undefined
undefined
bash python javascript java

Introduction

Overview

Internet of Things ecosystems consists of many components and require different expertise to provide a good and valuable solution. One of the main components is the middleware which glues together the hardware and the application. It should have many tools that allows developers to manage and deploy devices and data efficiently. However, if one has to develop it from scratch, it will be a long winding and time consuming.

FAVORIOT a middleware platform specifically designed for any Internet of Things (IoT) and Machine to Machine (M2M) solutions. The platform is developed to support the integration of data from various sensors, actuators and other sources of data. Collecting and storing data from IOT devices become much easier. Moreover, the platform also helps developers to build vertical applications. Develops does not need to worry about hosting and storing the data generated by their IoT devices.

FAVORIOT enables the devices to push the data to the FAVORIOT middleware platform using its REST API. The external application can also pull the data from FAVORIOT middleware platfrom using REST API.

Components of FAVORIOT

Screenshot of Example Documentation created with Slate
Figure 1:  The Building Blocks of FAVORIOT Middleware Platform

As shown in Figure 1 above, the FAVORIOT IOT Middleware consists of several building blocks:

How Does it Work?

Architecture
Figure 2:  The role of FAVORIOT IOT Middleware in an IOT Project

FAVORIOT Hierarchy

Device is central entity in FAVORIOT. It is used to represent the physical devices in IOT realms within the IOT middleware. Hence, the data produced by devices can be aggregated easily. FAVORIOT Middleware is built based on hierarchy that allows easy and efficient handling at different level.

REST API

This section explains the various endpoints that are involved in FAVORIOT middleware.

Project

API presented in this section deals with project endpoint.

Get All Project

FAVORIOT Middleware expects for the API key to be included in all API requests to the server in a header that looks like the following:

apiKey: <YOUR API KEY HERE>

Make sure to replace with your API key.

# With shell, you can just pass the correct header with each request
curl -X GET --header 
'Accept: application/json' --header 
'apiKey: <YOUR API KEY HERE>' 
'http://api.favoriot.com/v1/projects'

var request = require("request");

var options = { method: 'GET',
  url: 'https://api.favoriot.com/v1/projects',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/projects")
  .get()
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
import requests

url = "https://api.favoriot.com/v1/projects"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

The above command returns JSON structured like this:

{
  "numFound": 1,
  "results": [
    {
      "project_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
      "project_developer_id": "projectDefault@FAVORIOT",
      "description": "projectDefault is an IOT project",
      "project_name": "project-1",
      "active": true,
      "user_id": "FAVORIOT"
    }
  ]
}

This endpoint retrieves all Project.

HTTP Request

GET /projects

QUERY PARAMETERS

Name Description Type Data Type
project_name project name query string
project_developer_id project Developer ID query string
active status of the project query boolean
created_at filter the list of results by field created_at (timestamp) query string
created_from_to Allow to specify a range of project creation query string
max define the number of results to be returned query number
order sorting the results by creation date (asc or desc) query string { ASC , DESC }
offset list project at given offset query number

RESPONSES

Status Meaning Description
200 OK Success
400 Bad Request Operation Failed
503 Service Unavailable Error: Something wrong with the database or the query

Get a Specific Project

curl -X GET --header 
'Accept: application/json' --header 
'apiKey: <YOUR API KEY HERE>' 
'http://api.favoriot.com/v1/projects/{project_developer_id}'

var request = require("request");

var options = { method: 'GET',
  url: 'https://api.favoriot.com/v1/projects/{project_developer_id}',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/projects/{project_developer_id}")
  .get()
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
import requests

url = "https://api.favoriot.com/v1/projects/{project_developer_id}"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

The above command returns JSON structured like this:

{
  "project_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
  "project_developer_id": "projectDefault@FAVORIOT",
  "description": "Project-1 is an IOT project",
  "project_name": "projectDefault",
  "active": true,
  "user_id": "zeldi"
}

This endpoint retrieves a specific project.

HTTP Request

GET /projects/{project_developer_id}

URL Parameters

Name Description Type Data Type Required
project_developer_id ID of the project path string Yes

Responses

Status Meaning Description
200 OK Success
400 Bad Request Operation Failed
503 Service Unavailable Error: Something wrong with the database or the query

Creating a Project

This endpoint creates a Project.

HTTP Request

POST /projects

curl -X POST --header 
'Content-Type: application/json' 
--header 'Accept: application/json' 
--header 'apiKey: YOUR API KEY HERE' 
-d '{
  "project_name": "PROJECT NAME",
  "active": true,
  "description": "DESCRIPTION",
  "user_id": "USER ID"
}' 'https://api.favoriot.com/v1/projects'

var request = require("request");

var options = { method: 'POST',
  url: 'https://api.favoriot.com/v1/projects',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/projects")
  .post(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
import requests

url = "https://api.favoriot.com/v1/projects"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("POST", url, headers=headers)

print(response.text)

Body parameter

{
  "project_name": "string",
  "active": true,
  "description": "string",
  "user_id": "string"
}

The above command returns JSON structured like this:

{
  "code": 2012,
  "message": "project created",
  "details": {
    "project_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
    "project_developer_id": "projectDefault@FAVORIOT",
    "description": "projectDefault is an IOT project",
    "active": true,
    "project_name": "projectDefault",
    "user_id": "FAVORIOT"
  }
}

Description of body parameter

Name Description
project_name Name of the project.
This should be unique.
Example: Parkingproject
active true or false.
Indicate whether project is active or not.
default true. Example: true
description Brief description of project.
Example: Parking project for my house
user_id Your username for FAVORIOT platform.
Example: @FAVORIOT

URL Parameters

Name Description Type Data Type Required
project_developer_id ID of the project path string Yes

Responses

Status Meaning Description
200 OK Success
400 Bad Request Operation Failed
422 [Unprocessable Entity] validationError : Empty string or invalid character
503 Service Unavailable Error: Something wrong with the database or the query

Deleting a Project

This endpoint deletes a project.

HTTP Request

DELETE /projects/{project_developer_id}

# You can also use wget
curl -X DELETE --header 
'Accept: application/json' 
--header 'apiKey: YOUR API KEY HERE' 
'https://api.favoriot.com/v1/projects/{project_developer_id}'

var request = require("request");

var options = { method: 'DELETE',
  url: 'https://api.favoriot.com/v1/projects/{project_developer_id}',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/projects/{project_developer_id}")
  .delete(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
import requests

url = "https://api.favoriot.com/v1/projects/{PROJECT DEVELOPER ID}"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache"
    }

response = requests.request("DELETE", url, headers=headers)

print(response.text)

The above command returns JSON structured like this:

{
  "code": 2012,
  "message": "project created",
  "details": {
    "project_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
    "project_developer_id": "projectDefault@FAVORIOT",
    "description": "projectDefault is an IOT project",
    "active": true,
    "project_name": "projectDefault",
    "user_id": "FAVORIOT"
  }
}

The above command returns JSON structured like this:

{
  "code": 2004,
  "message": "project_id projectDefault@FAVORIOT successfully deleted"
}

Parameters

Name Description Type Data Type Required
project_developer_id ID of the project path string Yes

Responses

Status Meaning Description
200 OK Success
400 Bad Request Operation Failed
422 Unprocessable Entity Delete Failed: The project is currently being referred by one or more applications entity
503 Service Unavailable Error: Something wrong with the database or the query

Updating a Project

Alter and update a project -- Only fields 'active','description', and 'project_updated_at' allowed to be changed.

HTTP request

PUT /projects/{project_developer_id}

# You can also use wget
curl -X PUT --header 'Content-Type: application/json' 
--header 'Accept: application/json' 
--header 'apiKey: YOUR API KEY HERE' 
-d '{
  "description": "No Desc",
  "active": true
}' 
'https://api.favoriot.com/v1/projects/{project_developer_id}'

var request = require("request");

var options = { method: 'PUT',
  url: 'https://api.favoriot.com/v1/projects/{project_developer_id}',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/projects/{project_developer_id}")
  .put(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
import requests

url = "https://api.favoriot.com/v1/projects/{PROJECT DEVELOPER ID}"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache"
    }

response = requests.request("PUT", url, headers=headers)

print(response.text)

Body parameter

{
  "description": "No Desc",
  "active": true
}

The above command returns JSON structured like this:

{
    "code": 20020,
    "details": {
        "description": "Project-1 is an IOT project",
        "project_developer_id": "projectDefault@FAVORIOT",
        "project_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
        "project_name": "projectDefault",
        "user_id": "FAVORIOT"
    },
    "message": "project updated"
}

Parameters

Name Description Type Data Type Required
project_developer_id ID of the project path string Yes
Body Body of the data Object Object Yes

Responses

Status Meaning Description
200 OK Success
400 Bad Request Operation Failed
404 Not Found Updated failed : Couldn't find rows as specified by parameters in the body
503 Service Unavailable Error: Something wrong with the database or the query

Return a list of all applications from a project

HTTP request

GET /projects/{project_developer_id}/apps

# You can also use wget
curl -X GET --header 'Accept: application/json'
 --header 'apiKey: YOUR API KEY HERE' 
 'https://api.favoriot.com/v1/projects/{project_developer_id}/apps'

var request = require("request");

var options = { method: 'GET',
  url: 'https://api.favoriot.com/v1/projects/{project_developer_id}/apps',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/projects/{project_developer_id}/apps")
  .get(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
import requests

url = "https://api.favoriot.com/v1/projects/{project_developer_id}/apps"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

The above command returns JSON structured like this:

{
  "numResults": 1,
  "results": [
    {
      "application_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
      "application_developer_id": "applicationDefault@FAVORIOT",
      "project_developer_id": "projectDefault@FAVORIOT",
      "description": "an IOT application",
      "application_name": "applicationDefault",
      "active": true,
      "user_id": "FAVORIOT"
    }
  ]
}

Parameters

Name Description Type Data Type Required
project_developer_id ID of the project path string Yes

Responses

Status Meaning Description
200 OK Success
400 Bad Request Request not valid
503 Service Unavailable Error: Something wrong with the database or the query

Show an application from a specific project

HTTP request

GET /projects/{project_developer_id}/apps/{application_developer_id}

Code samples

# You can also use wget
curl -X GET --header 'Accept: application/json' 
--header 'apiKey: YOUR API KEY HERE'
 'https://api.favoriot.com/v1/projects/{project_developer_id}/apps/{application_developer_id}'

var request = require("request");

var options = { method: 'GET',
  url: 'https://api.favoriot.com/v1/projects/{project_developer_id}/apps/{application_developer_id}',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/projects/{project_developer_id}/apps/{application_developer_id}")
  .get(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
import requests

url = "https://api.favoriot.com/v1/projects/{project_developer_id}/apps/{application_developer_id}"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

The above command returns JSON structured like this:

{
  "application_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
  "application_developer_id": "applicationDefault@FAVORIOT",
  "project_developer_id": "projectDefault@FAVORIOT",
  "description": "applicationDefault is an IOT application",
  "application_name": "applicationDefault",
  "active": true,
  "user_id": "FAVORIOT"
}

Parameters

Parameter In Type Required Description
project_developer_id path string true Project developer ID
application_developer_id path string true application ID

Responses

Status Meaning Description
200 OK Success
400 Bad Request Request not valid
503 Service Unavailable Error: Something wrong with the database or the query

Applications

Endpoints related to application

Creating Application

Create an application by passing necessary information in the HTTP body

HTTP REQUEST

POST /apps

# You can also use wget
curl -X POST --header 'Content-Type: application/json' 
--header 'Accept: application/json'
 --header 'apiKey: YOUR API KEY HERE' 
 -d '{
  "application_name": "string",
  "active": true,
  "project_developer_id": "string",
  "description": "string",
  "user_id": "string"
}' 
'https://api.favoriot.com/v1/apps'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/apps")
  .post(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'POST',
  url: 'https://api.favoriot.com/v1/apps',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/apps"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("POST", url, headers=headers)

print(response.text)

Body parameter

{ 
 "application_name": "string",
  "active": true,
  "project_developer_id": "string",
  "description": "string",
  "user_id": "string"
  }

Example responses

{
  "code": 2011,
  "message": "application created",
  "details": {
    "_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
    "app_id": "app1@FAVORIOT",
    "project_id": "projectDefault@FAVORIOT",
    "description": "Application-1 is an IOT application",
    "enabled": true,
    "name": "applicationDefault",
    "owner": "FAVORIOT"
  }
}

Description of body parameter

Name Description
application_name Name of the project.
This should be unique.
Example: parkingApplication
active true or false.
Indicate whether application is active or not.
default true. Example: true
project_developer_id ID of the project to which the application will be associated.
Example: projectDefault@FAVORIOT
description Brief description of Application.
Example: Parking application for my house
user_id Your username for FAVORIOT platform.
Example: @FAVORIOT

QUERY PARAMETERS

Parameter In Type Required Description
body body object true No description

RESPONSES

Status Meaning Description
201 Created Created
400 Bad Request Request not valid
422 Unprocessable Entity validationError : project_developer_id can not be empty. It is used as reference
404 Not Found Either or that's referred in this application is not exists
409 Conflict has been used by this user
503 Service Unavailable Error: Something wrong with the database or the query

Get all applications

Return a list containing all applications

HTTP REQUEST

GET /apps

# You can also use wget
curl -X GET --header 'Accept: application/json' 
--header 'apiKey: YOUR API KEY HERE' 
'https://api.favoriot.com/v1/apps'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/apps")
  .get(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'GET',
  url: 'https://api.favoriot.com/v1/apps',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/apps"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

Example responses

{
  "numResults": 1,
  "results": [
    {
      "application_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
      "app_developer_id": "applicationDefault@FAVORIOT",
      "project_id": "projectDefault@FAVORIOT",
      "description": "an IOT application",
      "applicationname": "applicationDefault",
      "active": true,
      "user_id": "FAVORIOT"
    }
  ]
}

QUERY PARAMETERS

Parameter In Type Required Description
application_name query string false application name
application_developer_id query string false application developer ID
created_at query number false filter the list of results by field created_at (timestamp)
created_from_to query string false Allow to specify a range of creation (created_at_from, e.g. value 13370093222)
max query integer false define the number of results to be returned
sort query string false sorting the results by the given field
order query string false sorting the results by creation date (asc or desc)
offset query number false list applications at given offset

RESPONSES

Status Meaning Description
200 OK Success
400 Bad Request Request not valid
503 Service Unavailable Error: Something wrong with the database or the query

Get a particular application

Show an application as specified by app_id

HTTP REQUEST

GET /apps/{application_developer_id}

Code samples

# You can also use wget
curl -X GET --header 'Accept: application/json' 
--header 'apiKey: YOUR API KEY HERE'
'https://api.favoriot.com/v1/apps/{application_developer_id}'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/apps/{application_developer_id}")
  .post(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'POST',
  url: 'https://api.favoriot.com/v1/apps/{application_developer_id}',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/apps/{application_developer_id}"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("POST", url, headers=headers)

print(response.text)

Example responses

{
  "application_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
  "application_developer_id": "applicationDefault@FAVORIOT",
  "project_developer_id": "projectDefault@FAVORIOT",
  "description": "applicationDefault is an IOT application",
  "application_name": "applicationDefault",
  "active": true,
  "user_id": "FAVORIOT"
}

Parameters

Parameter In Type Required Description
application_developer_id path string true application developer ID

Responses

Status Meaning Description
200 OK Success
400 Bad Request Request not valid
503 Service Unavailable Error: Something wrong with the database or the query

Updating an application

Alter and update an application

HTTP REQUEST

PUT /apps/{application_developer_id}

# You can also use wget
curl -X PUT --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'apiKey: YOUR API KEY HERE' -d '{
  "application_name": "string",
  "active": true,
  "description": "string"
}' 'https://api.favoriot.com/v1/apps/applicationDefault%40riot'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/apps/{application_developer_id}")
  .put(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'PUT',
  url: 'https://api.favoriot.com/v1/apps/{application_developer_id}',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/apps/{application_developer_id}"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("PUT", url, headers=headers)

print(response.text)

Body parameter

{
  "application_name": "string",
  "active": true,
  "description": "string"
}

Example responses

{
  "code": 2005,
  "message": "application updated",
  "details": {
    "application_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
    "app_developer_id": "applicationDefault@FAVORIOT",
    "project_developer_id": "projectDefault@FAVORIOT",
    "description": "applicationDefault is an IOT application",
    "application_name": "applicationDefault",
    "active": true,
    "user_id": "FAVORIOT"
  }
}

QUERY PARAMETERS

Parameter In Type Required Description
application_developer_id path string true application developer ID
body body object true No description

RESPONSES

Status Meaning Description
200 OK Success
400 Bad Request Operation Failed
404 Not Found Updated failed : Couldn't find Rows as specified by parameters in the body
503 Service Unavailable Error: Something wrong with the database or the query

Deleting an application

Delete an application

HTTP REQUEST

DELETE /apps/{application_developer_id}

Code samples

# You can also use wget
curl -X DELETE --header 'Accept: application/json' 
--header 'apiKey: YOUR API KEY HERE'
'https://api.favoriot.com/v1/apps/{APPLICATION ID}'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/apps/{application_developer_id}")
  .delete(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'DELETE',
  url: 'https://api.favoriot.com/v1/apps/{application_developer_id}',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/apps/{application_developer_id}"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("DELETE", url, headers=headers)

print(response.text)

Example responses

{
  "code": 2004,
  "message": "an application has been successfully deleted"
}

QUERY PARAMETERS

Parameter In Type Required Description
application_developer_id path string true application developer ID

RESPONSES

Status Meaning Description
200 OK Success
400 Bad Request Operation Failed
422 Unprocessable Entity Delete Failed: This application is currently being referred by one or more groups
503 Service Unavailable Error: Something wrong with the database or the query

Get all groups of an application

Return a list of all groups from an application

HTTP REQUEST

GET /applications/{application_developer_id}/groups

Code samples

# You can also use wget
curl -X GET --header 'Accept: application/json' 
--header 'apiKey: YOUR API KEY HERE' 
'https://api.favoriot.com/v1/applications/{application_developer_id}/groups'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/applications/{application_developer_id}/groups")
  .delete(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'DELETE',
  url: 'https://api.favoriot.com/v1/applications/{application_developer_id}/groups',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/applications/{application_developer_id}/groups"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("DELETE", url, headers=headers)

print(response.text)

Example responses

{
  "numResults": 1,
  "results": [
    {
      "group_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
      "application_developer_id": "applicationDefault@zeldi",
      "group_developer_id": "groupDefault@zeldi",
      "description": "no description",
      "group_name": "groupDefault",
      "active": true,
      "user_id": "FAVORIOT"
    }
  ]
}

QUERY PARAMETERS

Parameter In Type Required Description
application_developer_id path string true Application developer ID

RESPONSES

Status Meaning Description
200 OK Success
400 Bad Request Request not valid
503 Service Unavailable Error: Something wrong with the database or the query

Groups

Groups endpoints

Creating a group

Create a group of devices by passing necessary information in the HTTP body

HTTP request

POST /groups

# You can also use wget
curl -X POST --header 'Content-Type: application/json' 
--header 'Accept: application/json'
 --header 'apiKey: YOUR API KEY HERE'
 -d '{
  "group_name": "groupDefault",
  "active": true,
  "application_developer_id": "APPLICATION NAME",
  "description": "none"
}' 'https://api.favoriot.com/v1/groups'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/groups")
  .post(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'POST',
  url: 'https://api.favoriot.com/v1/groups',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/groups"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("POST", url, headers=headers)

print(response.text)

Body parameter

{
  "group_name": "groupDefault",
  "active": true,
  "application_developer_id": "applicationDefault@FAVORIOT",
  "description": "none"
}

Description of body parameter

Name Description
group_name Name of the group.
This should be unique.
Example: parkingGroup
active true or false.
Indicate whether application is active or not.
default true. Example: true
application_developer_id ID of the group to which the application will be associated.
Example: groupDefault@FAVORIOT
description Brief description of Application.
Example: Parking application for my house
user_id Your username for FAVORIOT platform.
Example: @FAVORIOT

RESPONSES

Status Meaning Description
201 Created Created
400 Bad Request Request not valid
404 Not Found Either specified or that's referred in this Group Hierarchy is not exists
409 Conflict has been used by this user
503 Service Unavailable Error: Something wrong with the database or the query

Example responses

{
  "code": 2011,
  "message": "Group created",
  "details": {
    "_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
    "group_id": "groupDefault@FAVORIOT",
    "app_id": "applicationDefault@FAVORIOT",
    "description": "groupDefault is a group name",
    "enabled": true,
    "name": "groupDefault",
    "owner": "FAVORIOT"
  }
}

QUERY PARAMETERS

Parameter In Type Required Description
body body object true No description

Get all groups

Return a list containing all groups

HTTP request

GET /groups

Code samples

# You can also use wget
curl -X GET --header 'Accept: application/json'
 --header 'apiKey: YOUR API KEY HERE' 
 'https://api.favoriot.com/v1/groups'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/groups")
  .get(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'GET',
  url: 'https://api.favoriot.com/v1/groups',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/groups"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

Example responses

{
  "numResults": 1,
  "results": [
    {
      "group_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
      "group_developer_id": "groupDefault@FAVORIOT",
      "app_developer_id": "applicationDefault@FAVORIOT",
      "description": "no description",
      "group_name": "groupDefault",
      "active": true,
      "user_id": "FAVORIOT"
    }
  ]
}

QUERY PARAMETERS

Parameter In Type Required Description
group_name query string false Group name
group_developer_id query string false Group ID
created_at query number false filter the list of results by field created_at (timestamp)
created_from_to query string false Allow to specify a range of group creation (e.g. [ 2016-09-03T01:39:39.473Z TO NOW] )
max query integer false define the number of results to be returned
order query string false sorting the results (asc or desc)
offset query number false list of groups at given offset

RESPONSES

Status Meaning Description
200 OK Success
400 Bad Request Request not valid
503 Service Unavailable Error: Something wrong with the database or the query

Get a specific group

show a group as specified by group_developer_id

HTTP request

GET /groups/{group_developer_id}

# You can also use wget
curl -X GET --header 'Accept: application/json' 
--header 'apiKey: YOUR API KEY HERE' 
'https://api.favoriot.com/v1/groups/{group_developer_id}'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/groups/{group_developer_id}")
  .get(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'GET',
  url: 'https://api.favoriot.com/v1/groups/{group_developer_id}',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/groups/{group_developer_id}"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

Example responses

{
  "group_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
  "application_developer_id": "applicationDefault@FAVORIOT",
  "group_developer_id": "groupDefault@FAVORIOT",
  "description": "no description",
  "group_name": "groupDefault",
  "active": true,
  "user_id": "FAVORIOT"
}

QUERY PARAMETERS

Parameter In Type Required Description
group_developer_id path string true group developer ID

RESPONSES

Status Meaning Description
200 OK Success
400 Bad Request Request not valid
503 Service Unavailable Error: Something wrong with the database or the query

Updating a group

This API endpoint is used to update information about the group.

HTTP request

PUT /groups/{group_developer_id}

# You can also use wget
curl -X PUT --header 'Content-Type: application/json' 
--header 'Accept: application/json' --header 'apiKey: YOUR API KEY HERE'
 -d '{
  "description": "No Desc",
  "active": true
}' 
'https://api.favoriot.com/v1/groups/group_developer_id'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/groups/{group_developer_id}")
  .put(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'PUT',
  url: 'https://api.favoriot.com/v1/groups/{group_developer_id}',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/groups/{group_developer_id}"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("PUT", url, headers=headers)

print(response.text)

Body parameter

{
  "description": "No Desc",
  "active": true
}

Example responses

{
  "code": 2005,
  "message": "Group updated",
  "details": {
    "group_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
    "application_developer_id": "applicationDefault@FAVORIOT",
    "group_developer_id": "groupDefault@FAVORIOT",
    "description": "no description",
    "group_name": "groupDefault",
    "active": true,
    "user_id": "FAVORIOT"
  }
}

QUERY PARAMETERS

Parameter In Type Required Description
group_developer_id path string true Group developer ID
body body object true No description

RESPONSES

Status Meaning Description
200 OK Success
400 Bad Request Operation Failed
404 Not Found Updated failed : Couldn't find Rows as specified by parameters in the body
503 Service Unavailable Error: Something wrong with the database or the query

Deleting a group

Delete a particular group. -- NB: Once a particular group is removed, all entities under that group will also be removed.

HTTP request

DELETE /groups/{group_developer_id}

# You can also use wget
curl -X DELETE --header 'Accept: application/json'
 --header 'apiKey: YOUR API KEY HERE'
 'https://api.favoriot.com/v1/groups/{group_developer_id}'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/groups/{group_developer_id}")
  .delete(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'DELETE',
  url: 'https://api.favoriot.com/v1/groups/{group_developer_id}',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/groups/{group_developer_id}"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("DELETE", url, headers=headers)

print(response.text)

Example responses

{
  "code": 2004,
  "message": "A group has been successfully deleted"
}

QUERY PARAMETERS

Parameter In Type Required Description
group_developer_id path string true Group ID

RESPONSES

Status Meaning Description
200 OK Success
400 Bad Request Operation Failed
503 Service Unavailable Error: Something wrong with the database or the query
422 Unprocessable Entity Delete Failed: The group is currently being referred by one or more devices

Get a group from particular application

show a group from a specific application

HTTP request

GET /applications/{application_developer_id}/groups/{group_developer_id}

# You can also use wget
curl -X GET --header 'Accept: application/json'
 --header 'apiKey: YOUR API KEY HERE' 
 'https://api.favoriot.com/v1/applications/{APPLICATION ID}/groups/{group_developer_id}'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/applications/{application_developer_id}/groups/{group_developer_id}")
  .get(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'GET',
  url: 'https://api.favoriot.com/v1/applications/{application_developer_id}/groups/{group_developer_id}',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/applications/{application_developer_id}/groups/{group_developer_id}"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

Example responses

{
  "group_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
  "application_developer_id": "applicationDefault@FAVORIOT",
  "group_developer_id": "groupDefault@FAVORIOT",
  "description": "no description",
  "group_name": "groupDefault",
  "active": true,
  "user_id": "FAVORIOT"
}

QUERY PARAMETERS

Parameter In Type Required Description
application_developer_id path string true application developer ID
group_developer_id path string true Group developer ID

RESPONSES

Status Meaning Description
200 OK Success
400 Bad Request Request not valid
503 Service Unavailable Error: Something wrong with the database or the query

Get all device of a group

Return a list of all devices from a specific group.

HTTP request

GET /groups/{group_developer_id}/devices

# You can also use wget
curl -X GET --header 'Accept: application/json' 
--header 'apiKey: YOUR API KEY HERE'
'https://api.favoriot.com/v1/groups/{group_developer_id}/devices'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/groups/{group_developer_id}/devices")
  .get(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'GET',
  url: 'https://api.favoriot.com/v1/groups/{group_developer_id}/devices',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/groups/{group_developer_id}/devices"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

Example responses

{
  "numResults": 1,
  "results": [
    {
      "device_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
      "group_developer_id": "groupDefault@FAVORIOT",
      "device_developer_id": "deviceDefault@FAVORIOT",
      "description": "no description",
      "device_name": "deviceDefault",
      "active": true,
      "user_id": "FAVORIOT"
    }
  ]
}

QUERY PARAMETERS

Parameter In Type Required Description
group_developer_id path string true Group developer ID

RESPONSES

Status Meaning Description
200 OK Success
400 Bad Request Request not valid
503 Service Unavailable Error: Something wrong with the database or the query

Get a device for specific group

Show a specific device from a specific group.

HTTP request

GET /groups/{group_developer_id}/devices/{device_developer_id}

# You can also use wget
curl -X GET --header 'Accept: application/json'
 --header 'apiKey: YOUR API KEY HERE' 
 'https://api.favoriot.com/v1/groups/{group_developer_id}/devices/{device_developer_id}'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/groups/{group_developer_id}/devices/{device_developer_id}")
  .get(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'GET',
  url: 'https://api.favoriot.com/v1/groups/{group_developer_id}/devices/{device_developer_id}',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/groups/{group_developer_id}/devices/{device_developer_id}"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

Example responses

{
  "device_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
  "group_developer_id": "groupDefault@FAVORIOT",
  "device_developer_id": "deviceDefault@FAVORIOT",
  "description": "no description",
  "device_name": "deviceDefault",
  "active": true,
  "user_id": "FAVORIOT"
}

QUERY PARAMETERS

Parameter In Type Required Description
group_developer_id path string true Group developer ID
device_developer_id path string true device developer ID

RESPONSES

Status Meaning Description
200 OK Success
400 Bad Request Request not valid
503 Service Unavailable Error: Something wrong with the database or the query

Devices

Device APIs enable developers to quickly connect devices and communicate data over encrypted connections using industry-standard TLS protocol. A device is a representation of specific device or logical entity. It can be a physical device or sensor (such as a temperature sensor at home).

The following REST APIs are used to manage IOT devices within FAVORIOT middleware platform.

Create a device

Code samples

# You can also use wget
curl -X POST --header 'Content-Type: application/json'
 --header 'Accept: application/json'
  --header 'apiKey: YOUR API KEY' 
  -d '{
  "device_name": "string",
  "active": true,
  "group_developer_id": "groupDefault@FAVORIOT",
  "description": "string",
  "device_type": "arduino",
  "sensor_type": "temperature",
  "timezone": "Asia/Kuala_Lumpur",
  "latitude": 0,
  "longitude": 0
}' 
'https://api.favoriot.com/v1/devices'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/devices")
  .post(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'POST',
  url: 'https://api.favoriot.com/v1/devices',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/devices"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("POST", url, headers=headers)

print(response.text)

Body parameter

{
  "device_name": "string",
  "active": true,
  "group_developer_id": "groupDefault@FAVORIOT",
  "description": "string",
  "device_type": "arduino",
  "sensor_type": "temperature",
  "timezone": "Asia/Kuala_Lumpur",
  "latitude": 0,
  "longitude": 0
}

Example responses

{
  "code": 20140,
  "message": "Device successfully created",
  "details": {
    "device_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
    "device_developer_d": "deviceDefault@FAVORIOT",
    "group_id": "groupDefault@FAVORIOT",
    "description": "groupDefault is an IOT device",
    "active": true,
    "device_name": "deviceDefault",
    "device_type": "others",
    "sensor_type": "others",
    "timezone": "Asia/Kuala_Lumpur",
    "user_id": "FAVORIOT"
  }
}

Create a device by passing necessary information in the HTTP body

URL: https://api.favoriot.com/v1/devices
Method: POST

QUERY PARAMETERS

In Type Required Description
HTTP body JSON object true All attributes related to device are declared as JSON object

The following are attributes that can be stored within the HTTP body when creating a device.

Attribute Description
device_name String
Device name
Example:device-1
if device_name is not defined, default name will be set.
active Boolean
true or false
Enables or disables the device.
Default is true.
group_developer_id String
Group identifier.
A device should be structured under certain group, default is groupDefault@username
Example: group-01@FAVORIOT
description String
Device description.
device_type String
Can be one of the device types available
Example: Arduino
sensor_type String
Can be any types of sensor attached to the device
Example: Temperature
timezone String
Defines device time zone. Default value is “Asia/Kuala_Lumpur”.
Value must be one defined by FAVORIOT: https://api.favoriot.com/v1/time_zones/
latitude Number - Defines the Latitude coordinate.
Example:43.170
longitude Number - Defines the longitude coordinate.
Example:-3.101

RESPONSES

Status Description
201 Device successfully created
409 Device name has been used by the current user
422 Unable to process the contained instructions

Get all device

Code samples

# You can also use wget
curl -X GET --header 'Accept: application/json' 
--header 'apiKey: YOUR API KEY HERE' 
'https://api.favoriot.com/v1/devices'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/devices")
  .get(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'GET',
  url: 'https://api.favoriot.com/v1/devices',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/devices"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

Example responses

{
  "numResults": 1,
  "results": [
    {
      "device_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
      "group_developer_id": "groupDefault@FAVORIOT",
      "device_developer_id": "deviceDefault@FAVORIOT",
      "description": "no description",
      "device_name": "deviceDefault",
      "active": true,
      "latitude": null,
      "longitude": null,
      "timezone": "Asia/Kuala_Lumpur",
      "user_id": "FAVORIOT"
    }
  ]
}

Return a list containing all devices, max 10000.

URL: https://api.favoriot.com/v1/devices
Method: GET
Response: JSON

QUERY PARAMETERS

To narrow the query, the following parameters can be appended as query parameters in the URL.

Parameter Description
device_name Type:String
Required:optional
Device name
device_developer_id Type:String
Required:optional
Device developer ID
created_at Type:Timestamp
Required:optional
filter the list of results by field created_at (timestamp)
created_from_to Type:String
Required:optional
Allow to specify a range of device creation (e.g. [ 2016-09-03T01:39:39.473Z TO NOW] )
max Type:Integer
Required:optional
define the number of results to be returned
order Type:String
Required:optional
sorting the results by creation date either ascending or descending ( asc or desc)
offset Type:Integer
Required:optional
list devices at given offset

Example of API usage:
To return 10 devices, the following API is used:
https://api.favoriot.com/v1/devices?max=10

RESPONSES CODE

Status Description
200 Success
refer to example responses for the result format
422 Unable to process the contained instructions

Get a specific device

Code samples

# You can also use wget
curl -X GET --header 'Accept: application/json' 
--header 'apiKey: YOUR API KEY HERE'
'https://api.favoriot.com/v1/devices/{device_developer_id}'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/devices/{device_developer_id}")
  .get(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'GET',
  url: 'https://api.favoriot.com/v1/devices/{device_developer_id}',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/devices/{device_developer_id}"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

Example responses

{
  "device_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
  "group_developer_id": "groupDefault@FAVORIOT",
  "device_developer_id": "deviceDefault@FAVORIOT",
  "description": "no description",
  "device_name": "deviceDefault",
  "active": true,
  "latitude": null,
  "longitude": null,
  "timezone": "Asia/Kuala_Lumpur",
  "user_id": "FAVORIOT"
}

URL: https://api.favoriot.com/v1/devices/{device_developer_id}
Method: GET
Response: JSON

As can be seen from the URL above, with this API, the query parameter (device_developer_id) part of the URL.

QUERY PARAMETERS

Parameter In Type Required Description
device_developer_id path String true Device developer ID

RESPONSES

Status Description
200 Success
refer to example responses for the result format
422 Unable to process the contained instructions

Update a device

# You can also use wget
curl -X PUT --header 'Content-Type: application/json' 
--header 'Accept: application/json' --header 'apiKey: YOUR API KEY HERE'
 -d '{
  "description": "No Desc",
  "active": true,
  "device_type": "arduino",
  "sensor_type": "temperature",
  "timezone": "Asia/Kuala_Lumpur",
  "latitude": 0,
  "longitude": 0
}' 
'https://api.favoriot.com/v1/devices/{DEVICE ID}'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/devices/{device_developer_id}")
  .put(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'PUT',
  url: 'https://api.favoriot.com/v1/devices/{device_developer_id}',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/devices/{device_developer_id}"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("PUT", url, headers=headers)

print(response.text)

Body parameter

{
  "description": "No Desc",
  "active": true,
  "device_type": "arduino",
  "sensor_type": "temperature",
  "timezone": "Asia/Kuala_Lumpur",
  "latitude": 0,
  "longitude": 0
}

Example responses

{
  "code": 2005,
  "message": "Device updated",
  "details": {
    "device_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
    "group_developer_id": "groupDefault@FAVORIOT",
    "device_developer_id": "deviceDefault@FAVORIOT",
    "description": "no description",
    "deveice_name": "deviceDefault",
    "active": true,
    "latitude": null,
    "longitude": null,
    "timezone": "Asia/Kuala_Lumpur",
    "user_id": "FAVORIOT"
  }
}

URL: https://api.favoriot.com/v1/devices/{device_developer_id}
Method: PUT
Response: JSON

QUERY PARAMETERS

Parameter In Type Required Description
device_developer_id path string true device developer ID
HTTP Body body JSON true The attributes meant for updating device is stored in HTTP Body

Attributed for Updating A Device

The following are attributes that can be mentioned within the HTTP body in order to change the information about a device.

Attribute Type Description
description String
Device description.
active Boolean
true or false
Enables or disables the device.
Default is true.
device_type String
Can be one of the device types available
Example: Arduino
sensor_type String
Can be any types of sensor attached to the device
Example: Temperature
timezone String
Defines device time zone. Default value is “Asia/Kuala_Lumpur”.
Value must be one defined by FAVORIOT: https://api.favoriot.com/v1/time_zones/
latitude Number Defines the Latitude coordinate.
Example:43.170
longitude Number Defines the longitude coordinate.
Example:-3.101

RESPONSES

Status Description
201 Successfully updating the device
422 Failed to update the device

Delete a device

# You can also use wget
curl -X DELETE --header 'Accept: application/json'
--header 'apiKey: YOUR API KEY HERE' 
'https://api.favoriot.com/v1/devices/{DEVICE ID}'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/devices/{device_developer_id}")
  .delete(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'DELETE',
  url: 'https://api.favoriot.com/v1/devices/{device_developer_id}',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/devices/{device_developer_id}"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("DELETE", url, headers=headers)

print(response.text)

Example responses

{
  "code": 200,
  "message": "Device is deleted"
}

URL: https://api.favoriot.com/v1/devices/{device_developer_id}
Method: DELETE

As can be seen from the URL above, with this API, the query parameter (device_developer_id) part of the URL.

QUERY PARAMETERS

Parameter In Description
device_developer_id path Type:String - Required:true
Device developer ID

RESPONSES

Status Description
200 Successfully deleting a device.
422 Unable to deleted the device

Get all data stream of a device

Code samples

# You can also use wget
curl -X GET --header 'Accept: application/json' 
--header 'apiKey: YOUR API KEY HERE' 
'https://api.favoriot.com/v1/devices/{device_developer_id}/streams'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/devices/{device_developer_id}/streams")
  .get(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
var request = require("request");

var options = { method: 'GET',
  url: 'https://api.favoriot.com/v1/devices/{device_developer_id}/streams',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
import requests

url = "https://api.favoriot.com/v1/devices/{device_developer_id}/streams"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

Example responses

{
  "numResults": 1,
  "results": [
    {
      "user_id": "FAVORIOT",
      "stream_created_at": "2016-10-01T12:29:41.029Z",
      "stream_developer_id": "a2971fd7-dca7-472d-b57c-d8282c6ce033t@FAVORIOT",
      "device_developer_id": "deviceDefault@FAVORIOT",
      "data": {}
    }
  ]
}

URL:
https://api.favoriot.com/v1/devices/{device_developer_id}/streams
Method: GET
Response: JSON

As can be seen from the URL above, with this API, the query parameter (device_developer_id) part of the URL.

Parameter In Description
device_developer_id path Type:String - Required:true
Device developer ID

RESPONSES

Status Description
200 Success.
422 Unable to process the contained instructions

Data

HTTP Endpoints related to data streams management

Send data from a device

Code samples

# You can also use wget
curl -X POST --header 'Content-Type: application/json'
 --header 'Accept: application/json' 
 --header 'apiKey: YOUR API KEY HERE' 
 -d '{
  "device_developer_id": "deviceDefault@FAVORIOT",
  "data": { "temperature": "31","humidity": "70"}
  }' 
'https://api.favoriot.com/v1/streams'

var request = require("request");

var options = { method: 'POST',
  url: 'https://api.favoriot.com/v1/streams',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/streams")
  .post(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
import requests

url = "https://api.favoriot.com/v1/streams"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache",
    'postman-token': "b404ce24-2b0b-b9c8-8895-6324a6900c47"
    }

response = requests.request("POST", url, headers=headers)

print(response.text)

Example of Body parameter

{
  "device_developer_id": "deviceDefault@FAVORIOT",
  "data": { "temperature": "31",
            "humidity": "70"}
}

Example responses

{
  "status": "OK"
}
{
  "code": 4002,
  "message": "Invalid JSON"
}
{
  "code": 4002,
  "message": "There entities are not enabled"
}

URL: https://api.favoriot.com/v1/streams
Method: POST

QUERY PARAMETERS

Parameter In Type Required Description
body body JSON true data stream from a device

RESPONSES

Status Description
201 Data Stream Created
400 Invalid JSON or Data format
401 Un-authorized user or API-key
422 Request not valid

Get all data of a device

# You can also use wget
curl -X GET --header 'Accept: application/json' 
--header 'apiKey: YOUR API KEY HERE' 
'https://api.favoriot.com/v1/streams'

var request = require("request");

var options = { method: 'GET',
  url: 'https://api.favoriot.com/v1/streams',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/streams")
  .get()
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
import requests

url = "https://api.favoriot.com/v1/streams"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

Example responses

{
  "statusCode": "200,",
  "numResults": 1,
  "results": {
    "user_id": "FAVORIOT",
    "stream_developer_id": "28e7a313-011c-4d95-a8b9-d6609883d18@FAVORIOT",
    "stream_created_at": "2016-10-01T13:23:26.787Z",
    "device_developer_id": "defaultDevice@FAVORIOT",
    "data": {
      "temperature": "23"
    }
  }
}
{
  "code": 400,
  "message": "Request not valid"
}

URL: https://api.favoriot.com/v1/streams
Method: GET

QUERY PARAMETERS

Parameter In Type Required Description
device_developer_id query string false Device developer ID
created_at query string false filter the list of results by field created_at (timestamp)
created_from_to query string false Allow to specify a range of streams creation (e.g. [ 2016-09-03T01:39:39.473Z TO NOW] )
max query integer false define the number of results to be returned
order query string false sorting the results by creation date either ascending or descending (asc or desc)
offset query number false list the streams at given offset

Example of API usage with specific parameters:

To return 10 streams, the following API is used:
https://api.favoriot.com/v1/streams?max=10&order=asc

RESPONSES

Status Description
200 Success
401 Un-authorized user or API-key
422 Request not valid

Get specific data stream

# You can also use wget
curl -X GET --header 'Accept: application/json' 
--header 'apiKey: YOUR API KEY HERE' 
'https://api.favoriot.com/v1/streams/{STREAM ID}'

var request = require("request");

var options = { method: 'GET',
  url: 'https://api.favoriot.com/v1/streams/{STREAM ID}',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/streams/{STREAM ID}")
  .get()
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
import requests

url = "https://api.favoriot.com/v1/streams/%7BSTREAM%20ID%7D"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

Example responses

{
  "stream_id": "b771141b-aa8b-44f3-a18a-3b29bb7579a2",
  "stream_developer_d": "b771141b-aa8b-44f3-a18a-3b29bb7579a2@FAVORIOT",
  "device_developer_id": "deviceDefault@FAVORIOT",
  "data": {},
  "stream_created_at": 141232322,
  "owner": "FAVORIOT"
}
{
  "code": 400,
  "message": "Error!!"
}

URL: https://api.favoriot.com/v1/streams/{stream_developer_id}
Method: GET Response: JSON Object

QUERY PARAMETERS

Parameter In Type Required Description
stream_developer_id path string true Stream developer ID

RESPONSES

Status Description
200 Success
401 Un-authorized user or API-key
422 Request not valid

Delete data sent by a device

# You can also use wget
curl -X DELETE --header 'Accept: application/json' 
--header 'apiKey: YOUR API KEY HERE' 
'https://api.favoriot.com/v1/streams/{STREAM ID}'

var request = require("request");

var options = { method: 'DELETE',
  url: 'https://api.favoriot.com/v1/streams/{STREAM ID}',
  headers: 
   { 'postman-token': '683948a5-70d7-0080-15f3-b2929bac016c',
     'cache-control': 'no-cache',
     'content-type': 'application/json',
     'apikey': 'YOUR API KEY HERE' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api.favoriot.com/v1/streams/{STREAM ID}")
  .delete(null)
  .addHeader("apikey", "YOUR API KEY HERE")
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();
import requests

url = "https://api.favoriot.com/v1/streams/{STREAM ID}"

headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json",
    'cache-control': "no-cache"
    }

response = requests.request("DELETE", url, headers=headers)

print(response.text)

Example responses

{
  "code": 200,
  "message": "A data has been successfully deleted"
}
{
  "code": 400,
  "message": Operation failed
  }

URL: https://api.favoriot.com/v1/streams/{stream_developer_id}
Method: DELETE

QUERY PARAMETERS

Parameter In Type Required Description
stream_developer_id path string true stream developer ID

RESPONSES

Status Description
200 Success
401 Un-authorized user or API-key
422 Request not valid

Errors

The FAVORIOT API uses the following error codes. The error code are separated according to functionality of the APIs.

User Authentication

Type of Status HTTP Code status Code
Database Error 503 -
Not Unique Field 409 409xx
Unable to find user 404 404xx
Wrong password (Un-authenticated) 401 401xx
Token Related (Un-authenticated) 401 401xx
Validation error 422 422xx
Invalid token on changing passwd 422 422xx
Token un-authorized (forbidden) 403 403xx

Validation Error

Project Creation

Type of Status HTTP Code status Code
Unable to create project 422
ERROR: Database Error 503 5031x
ERROR: Unable to find user 404 4041x
ERROR: Not Unique Field 409 4091x
ERROR: Validation error 422 4221x
ERROR: Unable to update 400 4001x
ERROR:(Field speciefied not found) 404 4041x

Application

Type of Status HTTP Code status Code
ERROR: Database Error 503 5032x
ERROR: Unable to update 400 4002x
ERROR:(Specified field not found) 404 4042x
ERROR: Validation error 422 4223x

Group

Type of Status HTTP Code status Code
ERROR: Database Error 503 5033x
ERROR: Unable to find user 404 4043x
ERROR: Not Unique Field 409 4093x
ERROR: Validation error 422 4223x

Device

Type of Status HTTP Code status Code
ERROR: Database Error 503 5034x
ERROR: Unable to find user 404 4044x
ERROR: Not Unique Field 409 4094x
ERROR: Validation error 422 4224x

Data Stream

Type of Status HTTP Code status Code
ERROR: Database Error 503 5035x
ERROR: Unable to find user 404 4045x
ERROR: Not Unique Field 409 4095x
ERROR: Validation error 422 4225x

TUTORIALS

This section provide tutorials on connecting various device from different platform. The code sample for each section is given on the right side of the page. select the respective language tab for your programming.

Arduino

code to send data to FAVORIOT platform from Arduino

    The code is only available for java
    The code is only available for java
    The code is only available for java
/*
    This sketch sends streams to FAVORIOT Platform using Ethernet shield
*/
#include <SPI.h>
#include <Ethernet.h>

const int ON = 1;    // Constant to indicate that lights are on
const int OFF = 2;  // Constant to indicate that lights are off
const String APIKEY = "YOUR API KEY HERE"; // Replace with your FAVORIOT apikey
const String DEVICE = "YOUR DEVICE HERE"; // Replace with the id_developer of your device

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Your IP Address
IPAddress ip(192,168,0,16); // This is assigned to the arduino device (Please assign IP according to your network)

// api.favoriot.com address
char server[] = "api.favoriot.com"; 

EthernetClient client; // Initialize the library instance
int ledPin = 5;        // Led pin number
int LDRPin = 7;        // LDR sensor pin number
String lights = "OFF";       // Current status
String newLights = "OFF";    // New status

// The setup routine runs once when you press reset
void setup() {
  pinMode(ledPin, OUTPUT);        // Initialize the digital pin as an output
  Serial.begin(9600);             // Start serial port
  Serial.println(F("Starting"));
  Ethernet.begin(mac,ip);         // Start the Ethernet connection
  delay(2000);                    // Give the Ethernet shield a second to initialize
}

// The loop routine runs over and over again forever
void loop() {
  int val = analogRead(LDRPin);   // Read the value from the sensor
  Serial.println(val);
  if (val > 990) {  // This is the value limit between day or night with our LDR sensor. Maybe you need adjust this value.
    newLights = OFF;             // Now it's night. We have to turn on the LED
    digitalWrite(ledPin, HIGH);   // Turn the LED on (HIGH is the voltage level)
  }
  else {
    newLights = ON;               // Now it's day. We have to turn off the LED
    digitalWrite(ledPin, LOW);    // Turn the LED off by making the voltage LOW
  }
  if (lights != newLights) {        // Check if we have a change in status
    Serial.println(F("Send Stream"));
    lights = newLights;             // Status update and send stream
    sendStream();
  }
  delay(500);
  // If there's incoming data from the net connection, send it out the serial port
  // This is for debugging purposes only
  while (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
      client.stop();
  }
}
// Send stream to FAVORIOT
void sendStream()
{
  String txt = "";          // Text to send
  if ( lights == "OFF" ) {   // Alarm OFF
     txt = "OFF";
  } else {                  // Alarm ON
     txt = "ON";
  }
  Serial.println(txt);      // For debugging purpose only

  if (client.connect(server, 80)) {   // If there's a successful connection
    Serial.println(F("connected"));
    // Build the data field
    String json = "{\"device_developer_id\":\""+DEVICE+"\",\"data\":{\"Light\":\""+txt+"\"}}";
    // Make a HTTP request
    client.println("POST /v1/streams HTTP/1.1");
    client.println("Host: api.favoriot.com");
    client.println(F("apikey: YOUR API KEY HERE"));
    client.println("Content-Type: application/json");
    client.print("Content-Length: ");
    int thisLength = json.length();
    client.println(thisLength);
    client.println("Connection: close");

    client.println();
    client.println(json);
  }
  else {
    // If you didn't get a connection to the server:
    Serial.println(F("connection failed"));
  }

}




/*
  FAVORIOT Arduino Code for Wi-Fi shield
 */

#include <SPI.h>
#include <WiFi.h>

char ssid[] = "YOUR WI-FI Network SSID"; //  your network SSID (name)
char pass[] = "WI-FI Password";    // your network password (use for WPA, or use as key for WEP)

const String DEVICE = "DEVICE NAME"; // Replace with the id_developer of your device
String txt = "OFF";          // Text to send

int status = WL_IDLE_STATUS;

char server[] = "api.favoriot.com";    //  address for FAVORIOT Platform

WiFiClient client;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  // check for the presence of the shield:
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
}

void loop() {

  // Json Data to send to Platform
  String json = "{\"device_developer_id\":\"YOUR DEVICE HERE\",\"data\":{\"light\":\""+txt+"\"}}";
  Serial.println(json);
  if (client.connect(server, 80)) {
    // Make a HTTP request:
    client.println("POST /v1/streams HTTP/1.1");
    client.println("Host: api.favoriot.com");
    client.println(F("apikey: YOUR API KEY HERE"));
    client.println("Content-Type: application/json");
    client.println("cache-control: no-cache");
    client.print("Content-Length: ");
    int thisLength = json.length();
    client.println(thisLength);
    client.println("Connection: close");

    client.println();
    client.println(json);
  }
  // if there are incoming bytes available
  // from the server, read them and print them:
  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }
  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    client.stop();
  }
  delay(10000);
}

This section provide tutorials on connecting various arduino device to FAVORIOT IoT. This easy tutorial helps you build a system for turning LED ON and OFF based in the light sensor reading (LDR sensor) and send an email alert. For this, a Arduino able to measure the light is used. In this tutorial you will learn how to:

Components used

Arduino is programmed to send a data stream to FAVORIOT depending on the intensity of light.

All the data streams sent by Arduino is stored in FAVORIOT platform.

In addition to storing data, the true power of FAVORIOT is to let you build Apps quickly with simple rule based on if-else logic. In this scenario we are going to build a Alert App that sends an email to you in case that Arduino detects the lights are ON or OFF.

The connections in Arduino are extremely simple. Refer to the diagram below.

Screenshot of Example Documentation created with Slate

If you are registered in FAVORIOT, you have a default device already created for you. Go to right platform on https://platform.favoriot.com and see the device panel to see the devices that are present. Basically you need the device_developer_id that might be something like defaultDevice@myusername. But if you want, you can create a new device and use it in this example.

Apikey

Now, go to your "account setting" which is available on the top right corner in the dropdown and check your Apikey. It's a big alphanumeric token like:
"98346673a6377ef1fde2357ebdcb0da582b150b00cabcd5a0d83045425407ab4".
You need this apikey to complete the example.

From Arduino you have to build a HTTP request and send the data.

HTTP request
POST /streams HTTP/1.1
Host: api.favoriot.com
Accept: application/json
Content-Type: application/json
apiKey: YOUR APIKEY HERE
Content-Length: YOUR CONTENT LENGTH HERE
Connection: close


Data

{ { "device_developer_id": "deviceDefault@FAVORIOT", "data": {"light":"ON"} } }

Alright then now your device must be sending streams when you turn on and turn off the lights.

It's time to see whether you can view the data on the platform and check if we have new streams. Login to you account on https://platform.favoriot.com and go to data stream tab.

Screenshot of Example Documentation created with Slate

You will see data like this in the data stream tab.

Screenshot of Example Documentation created with Slate

Great! now as we are receiving data on our platform let's send email whenever new data comes. Go to the Rules tab below the data stream tab.

when inside the Rule tab click on Add New Rule button. A form will appear and fill in the details as described:

Field Details
Rule Name Short name for rule (.e.g: Light_rule)
Description Describe what the rule does (.e.g.: sends email when light turn on or off)
Device Name Select from the dropdown on which you want to create the rule
Data Field for device this is optional field and decribe to which data inside the device you are associating the rule.
Rule Describe the rule here (see more information below)
Then select what to do from dropdown (email or sms. More alert channel coming soon.)
To enter the email or sms here (based in your previous selection in previous step).
Message enter the short message you want to be attache with alert.

The rule should be described as follows:

(stream.Light === "ON") || (stream.Light === "OFF")

The syntax should be followed while describing the rule. stream. prefix (adding stream. is required) is followed the data field sent by device which is light in this case (the data sent by device is temperature then you will write stream.temperature). You can multiple rule using || (OR) && (AND) logical operators.

Now, whenever the data comes to the platform the rule will be triggered and and alert will be sent.

Congratulations! you have just created an IoT project from scratch. Now go ahead and let your imagination run wild. Show us what great things you can build.

If you are having trouble with connecting your device to our platform please contact us at support@favoriot.com.

Raspberry Pi

This section provide tutorials on connecting Raspberry Pi to FAVORIOT platform.

code for creating a data stream

    The code is only available for python
    The code is only available for python
    The code is only available for python
import requests
import json

url = "https://api.favoriot.com/v1/streams"
payload = json.dumps({
  "device_developer_id": "deviceDefault@favoriot.iot",
  "data": {"temp":"14"}
})
headers = {
    "apikey": "YOUR API KEY HERE",
    "content-type": "application/json",
    "cache-control": "no-cache",
    }

response = requests.request("POST", url, headers=headers, data=payload)
parsed = json.loads(response.text)
print json.dumps(parsed, indent=4, sort_keys=True)

code for getting all data stream

import requests
import json

url = "https://api.favoriot.com/v1/streams"
headers = {
    "apikey": "YOUR API KEY HERE",
    "content-type": "application/json",
    "cache-control": "no-cache"
    }
response = requests.request("GET", url, headers=headers)
parsed = json.loads(response.text)
print json.dumps(parsed, indent=4, sort_keys=True)

Raspbian comes preloaded with Python, the official programming language of the Raspberry Pi and IDLE 3, a Python Integrated Development Environment. We're going to show you now how to get started with Raspberry pi using python to connect to our FAVORIOT platform.

You can use Raspberry pi as IoT device by connecting sensors to it or it can be used as IoT Gateway.

Replace the device_developer_id in the payload with your device name. Follow the syntax as given inside the payload.

import request is used to enable set http request from python. You install this library by running
pip install request command in the terminal.

import json is used to format the json response received from FAVORIOT and prepare the json data to be sent to the FAVORIOT platform.

If you are having trouble with connecting your device to our platform please contact us at support@favoriot.com.

MQTT

code for sending data using MQTT

Command to publish: Mosquitto publish

mosquitto_pub -d -h mqtt.favoriot.com -p 1883 -u Your-API-Key -P Your-API-Key  -t Your-API-Key/hello -m {data}

Command to publish : Mosquito publish secure version

mosquitto_pub -d -h mqtt.favoriot.com -p 8883 --cafile path_to_ca.crt_file -u Your-API-Key -P Your-API-Key  -t Your-API-Key/hello -m {data} --insecure

data format example:
"{\"device_developer_id\":\"deviceDefault@{user_id}\",\"data\":{\"humidity\":\"10\",\"Temperature\":\"10\"}}"

Command to subscribe: Mosquitto subscribe 

mosquitto_sub -d -h mqtt.favoriot.com -p 1883 -u Your-API-Key -P Your-API-Key  -t Your-API-Key/hello

Command to subscribe : Mosquito subscribe secure version

mosquitto_sub -d -h mqtt.favoriot.com -p 8883 --cafile path_to_ca.crt_file -u Your_API_key -P Your_API_key -t Your_API_key/hello --insecure
var mqtt = require('mqtt')   // use 'npm install mqtt -g' to install globally or  'npm install mqtt' for local installation
var api = 'Your API key here';
var url = 'mqtt://mqtt.favoriot.com' ; // use mqtts for secure connection
// Uncomment following line to enable secure connection
//var TRUSTED_CA_LIST = __dirname + '/ca.crt'; // the ca.crt file in this case in the same folder this code will be


var options = {
  port: 1883,   // use 8883 for secure connection 
  clientId: 'mqttjs_' + Math.random().toString(16).substr(2, 8),
  username: api,
  password: api
 // ,rejectUnauthorized : false, // uncomment to enable secure connection
 // ca: TRUSTED_CA_LIST         // uncomment to enable secure connection

};

// Create a client connection
var client = mqtt.connect(url, options);

var data = {
              "device_developer_id": "deviceDefault@developer_id",   // replace user_id with your developer_id
              "data": {"temp":"30", "Humidity":"40"}
           };

client.on('connect', function () {

  client.subscribe( api+'/hello');
  client.publish( api+'/hello', JSON.stringify(data));

})

client.on('message', function (topic, message) {
  // message is Buffer 
  console.log(message.toString());
  client.end();
})
    The code is only available for javascript and command line (bash)
    The code is only available for javascript and command line (bash)

This section explains on how to use MQTT protocol to connect to FAVORIOT platform.

The MQTT broker is hosted on the following domain:

Host : mqtt.favoriot.com

The standard ports for MQTT are:

Port : 1883 and 8883 (for secure connection using TLS/SSL)

Use your API-Key as username and password to connect to the platform.

The topics that a user can publish and subscribe to are in the following format:

Publish : {Your-API-Key}/*

Example : {Your-API-Key}/Home/Temperature

Subscribe : {Your-API-Key}/*

Example : {Your-API-Key}/Home/Temperature

FAVORIOT platform accepts JSON data from a MQTT device. The format is in the following format if using mosquitto_pub command from CLI:

"{\"device_developer_id\":\"deviceDefault@mqtttest7\",\"data\":{\"humidity\":\"10\"}}"

MQTT QoS supported by Favoriot platform

Establishing secure MQTT connection

In order to establish secure MQTT connection to the platform, create ca.crt file, copy and paste the following certificate inside it.

-----BEGIN CERTIFICATE----- MIIDmTCCAoGgAwIBAgIJAMPWVA80Rf38MA0GCSqGSIb3DQEBDQUAMGMxGzAZBgNV BAMMElNlY3VyZSBNUVRUIGJyb2tlcjERMA8GA1UECgwIRmF2b3Jpb3QxDDAKBgNV BAsMA0lvVDEjMCEGCSqGSIb3DQEJARYUc3VwcG9ydEBmYXZvcmlvdC5jb20wHhcN MTcwNjIwMDcxMjQyWhcNMzIwNjE2MDcxMjQyWjBjMRswGQYDVQQDDBJTZWN1cmUg TVFUVCBicm9rZXIxETAPBgNVBAoMCEZhdm9yaW90MQwwCgYDVQQLDANJb1QxIzAh BgkqhkiG9w0BCQEWFHN1cHBvcnRAZmF2b3Jpb3QuY29tMIIBIjANBgkqhkiG9w0B AQEFAAOCAQ8AMIIBCgKCAQEAw6jfao9GPyXR2oIjFseVN2wGHHf321VaOB21NwS9 hobsh7o37mOJUurDon2j2cnwj3PzRLxr5+1jtMlTh18KR7YvtI4QNVC0yZ1kfeYw doTVZ0JMm7kKqcwG75/HYTNehFTnTOKlCHcNG/lALOBUaF0Q8gccuP8w7mKsB/WY Kct7sG3Kom09vHpg14QML/4BqfBso3nMy2UpilmFqkd3iBZOc3OP93wbfoMdv+TY f3NuMC8GvjVj6w3y/ThVT5v9nW0hIOxnH0Z7/Z+StpKf66LEYrVK6wqrE+QOyPbt 7egm7xzufeMFYRG9D8yq1cdkgv91D+d0WZcGJ1WuhGmyGQIDAQABo1AwTjAdBgNV HQ4EFgQU92lSlWRQCgYvnDR+yKqbrJhXH8cwHwYDVR0jBBgwFoAU92lSlWRQCgYv nDR+yKqbrJhXH8cwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQ0FAAOCAQEAA0HF TipnY6COyJX9fPH9ZCW9+FitArf0liTJTOci2Wga6f7AWAvaqgEAYtOEwGmARTK8 i8MkAnf3rncvy/tegHIlklkmVHAnE8DaJIw+GwIQqg+CG+zW96M9ZicE2gP78I2d oMTKznk4POPzZOs5GnsFD50y49TY/gy7YEsmRhsyegnew9Ny45ZvAEsI1CD4QDZN nifCffGE5nNp7gcIlW5u66FvQ32deO9/Ag/83Qzj+MKvXtdkW+2PTG++g8qZnuZ6 51NjwKNY6DApQ5f7QN9WZHRs82s/SrWkMxv9HgIHMyQ6PxiRYZfaLdjTKgwv92P6 cDpPSjaUgpEJwiMvpQ== -----END CERTIFICATE-----

After saving the certifcate in ca.crt file, provide the path to the certificate in the programme used to send MQTT data. See the sample code in the right column.

If you are having issues connecting your device to our platform, please contact us at support@favoriot.com.

Contact Us

If you are having trouble with connecting your device to our platform or you find a bug please contact us at support@favoriot.com.

If you want your project to showcased on our website please contact us at support@favoriot.com.