Developers & Code

l

Go back to documentation

May 16, 2020

Devices must be authenticate before start to send data. Easyberry Iot has a JWT (Token) authentication available. Let do how it works. 

In this post, we are going to support us in POSTMAN software. You can download it if you wish or use our Easyberry LAB section to make your first tests.

 

TOKEN Authentication

With token-type authentication, user submission and password are not required with each data submission, thereby reducing the exposure of our credentials. This process requires two steps.

  1. Token Request
  2. Sending Data

NOTE: once the token is obtained, it is not required to send the user and pass again.

With Jquery

Step 1:
Token request

var username = “user”;
var password = “pwd”;

var url = ‘mysite.com’;
$ .ajax ({
url: url,
success: function (json) {
alert (“Success”, json);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert (textStatus, errorThrown);
},
type: ‘POST’,
contentType: ‘json’,
data: {username: <user>, password: <password>},
});

This request returns the token that must be stored in the RAM of the devices or if you want to save it in non-volatile memory make sure you encrypt those to not compromise your app. 

Step 2:
Sending data

var url = ‘mysite.com’;
$ .ajax ({
     url: url,
     success: function (json) {
         alert (“Success”, json);
     },
     error: function (XMLHttpRequest, textStatus, errorThrown) {
        alert (textStatus, errorThrown);
     },

     // headers: {‘Authorization’: ‘Basic bWFkaHNvbWUxMjM =’},
     beforeSend: function (xhr) {
       xhr.setRequestHeader (“Authorization”, “Bearer” + <token>);
     },
     type: ‘POST’,
     contentType: ‘json’,
     data: <JSON string>
});

Example using POSTMAN
Token Request:

Sending Data:

There are two processes by which we can request and send data. And they are GET and PUT respectively through the formats and / or models established in JSON to communicate with the Easyberry IoT data engine (API REST).
Sending data to Easyberry IoT
https://easyberry-iot.com/wp-json/iot-engine/v2/iodata

 

Data request to Easyberry. You can make requests for a single object or “thing” or you can do it using grouped objects “context” or “dataset”. For more information see how a context and / or datasets are defined here.

https://easyberry-iot.com/wp-json/iot-engine/v2/iodata

Data Objects Summary and examples

GET Functions

  1. {“op”:”get”,”thing”:[“thing1″,”thing2”,…]}
  2. {“op”:”get”,”context”:”[“context1″,”context”,…]}
  3. {“op”:”get”,”dataset”:[“datasetname,…”]}
  4. {“op”:”get”,”list”:”[things|contexts|datasets]”}
  5. {“op”:”get”,”list”:”things”}
  6. {“op”:”get”,”list”:”contexts”}
  7. {“op”:”get”,”list”:”datasets”}

PUT Functions

  1. Put things:

{“op”:”put”,

“data”:[{“name”:”register name”,

“value”:”register value”,

“epoch”:”timestamp(optional)”,

“properties”:{“name property 1″:”property value 1”,

“name property 2″:”property value 2”,

       }

},

{“name”:”register name 2″,

“value”:”register value 2″,

“epoch”:”timestamp(optional)”,

“properties”:{“name property 1″:”property value 1”,

“name property 2″:”property value 2”

}

}

]

  1. Put datasets:

{“op”:”put”,”dataset”:[….]}    available soon…

You May Also Like…

MODBUS TCP Gateway

MODBUS TCP Gateway

 Try this Modbus gateway and connect several Modbus devices to Easyberry IoT platform in just seconds. Go to App's...

Become a Developer

Become a Developer

Become an expert developer and sell yours amazing Android, IOS or Windows APP to Easyberry Marketplace. In addition,...

Become an Integrator

Become an Integrator

Become an expert integrator and publish your works related to IoT and Automation Systems, earning stars and gaining...

System Message

System Message

Get in touch in real time with what is going on in your Easyberry environment with your configuration. Message system...

My Resources

My Resources

MY RESOURCES My Resource feature is related which information is shared or can be accessed by your remote devices,...

Lab

Lab

Lab tool help you to give your first step and test applications, find errors, understand what is involved in login...

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *