0% found this document useful (0 votes)
7 views5 pages

NK Squae Enviro Server API For Revised.

The NK Square Enviro Server API Ver 1.1 is a RESTful API that allows clients to send real-time and delayed environmental data to a server using JSON objects. It supports functions for sending current data every minute and sending delayed data if real-time transmission fails, with specific parameters for user authentication and data collection. The API provides response codes to indicate success or errors during data transmission.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

NK Squae Enviro Server API For Revised.

The NK Square Enviro Server API Ver 1.1 is a RESTful API that allows clients to send real-time and delayed environmental data to a server using JSON objects. It supports functions for sending current data every minute and sending delayed data if real-time transmission fails, with specific parameters for user authentication and data collection. The API provides response codes to indicate success or errors during data transmission.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

2. NK Square Enviro Server API Ver 1.

This API provides full functionality including remote calibration. Following is a list of
supported functions

Sr. Function Description


1. Send Data Send real time data and flags to server
2. Send delayed data Send delayed data, status and flags to server. This
function is used if real time data was not sent due to
failure in internet connection

This is a RESTful API where clients communicate with server using HTTPS
requests. All request and response data are in the form of JSON objects.

2.1. Server URL


https://ServerIp /NKS Enviro/API (Subject to change as per CPCB guidelines)

Server IP - server domain name or IP address (To be defined)


Port - port number (normally 8080)

2.2. Send Data


This request is used for sending current data and data flags along with a time stamp. This
request should be sent in real time every 1 minute. Client should average all data polled
within 1 minute and send to server.

Request Details

Parameter Description Possible values


Function Name Request code 53
Name User Name specified in Will be provided after
NKS Enviro Site registration on
configuration page NKS Enviro server
Password Password specified in Will be provided after
NKS Enviro Site registration on
Parameter Description Possible values
configuration page NKS Enviro server
DeviceID ID generated by Integer Value
NKS Enviro server
when device is configured
DateTime Data send Date Time YYYY-MM-DD HH:mm:SS
(24-hour clock)

Additional Info:
additional info to get GPS co-ordinates and client software name and version All the data from this block
will be tread as a variable in our system
LATITUDE latitude value of a device -
LONGITUDE Longitude value of a -
device
SOFTWARENAME Software name and version -

Variables: Collection of variables

Variable Name Parameter Name NO, NOX, SO, SOX etc.


Value * Average Value of Precision - 3 (float value
Parameter for selected with 3 digits after decimal)
minute e.g., 123.456
Flags Calibration/ Maintenance C/M
Unit Unit of measure for
selected parameter

* If data of a particular parameter is not available on site due to any reason, its value
should be sent as “err”

All above details are sent to server as a JSON object. The structure is given in below
example

Example

'FunctionName': 53
'Name' : 'UserName'
'Password' : 'Password'
'DeviceID' : 1
'Datetime' : "2015-06-10 12:30:00"

'additional Info' : {
"LATITUDE","Value":'17.87‟,
"LONGITUDE","Value":'79.10',
"SOFWARENAME","Value":'fm version 1.0'
},
'Variables' : {
{"Variablename":"NO2","Value":12.2,”Flags”:””,"Unit":"mg/nm3"},
{"Variablename":"NOX","Value":122.2, ”Flags”:””,"Unit":"mg/nm3"},
{"Variablename":"SO2","Value":0.0,”Flags”:”C”,"Unit":"mg/nm3"},
}
Sample Code

HttpClient client = new DefaultHttpClient();


HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout
Limit HttpResponse response;
JSONObject json = new JSONObject();

HttpPost post = new HttpPost(URL);


json.put("deviceid", deviceid);
json.put("username", user);
json.put("password", pwd);

JSONArray jsonVariables = new


JSONArray(); // Repeat this for each variable
JSONObject jsonVariable = new JSONObject();
jsonVariable.put(“Variablename”,”NO2”);
jsonVariable.put(“Value”,”12.2”);
jsonVariable.put(“Flags”,””);
jsonVariable.put(“Unit”,” mg/nm3”);
jsonVariables.add(jsonVariable);

// put all parameters list in json


json.put('Variables", jsonVariables);

StringEntity se = new StringEntity( json.toString());


se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json")); post.setEntity(se);
response = client.execute(post);

Response Details

„ResultCode‟ : 1/2/3
'Message' : „Error Message if any‟

Code 1 indicates success. Other codes indicate error. An associated error message is
provided

Response Code Message


1 Success
2 Invalid User Name and Password
3 Incomplete Data

*Multiple errors may get added. For ResultCode “1” i.e. success, there will be no
Message.
2.3. Send Delayed Data
This request is used for sending delayed data and data flags along with a time stamp. This
request should be sent if current data gets failed. Client should average all data polled
within 1 minute and send to server. It may have multiple records in single request

Request Details

Parameter Description Possible values


FunctionName Request code 54
Name User Name specified in Will be provided after
NKS Enviro Site registration on
configuration page NKS Enviro server
Password Password specified in Will be provided after
NKS Enviro Site registration on
configuration page NKS Enviro server
DeviceID ID generated by Will be provided when
NKS Enviro server when device is added on
device is configured NKS Enviro server
Additional Info:
additional info to get GPS co-ordinates and client software name and
version All the data from this block will be tread as a variable in our system
LATITUDE latitude value of a device -
LONGITUDE Longitude value of a device -
SOFTWARENAME Software name and version -
Records - Collection of old Records
Record Single record JSONObjectcontains
following fields
DateTime Data send Date Time YYYY-MM-DD
HH:mm:SS
Variables - Collection of variables
Variable Name Parameter Name NO, NOX, SO, SOX etc.
Value * Average Value of Parameter Precision - 3 (float value
for selected minute with 3 digits after decimal)
e.g. 123.456
Flags Calibration/ Maintenance C/M
Unit Unit of measure for selected
parameter

* If data of a particular parameter is not available on site due to any reason, its value
should be sent as “err”
Example

'functionName' : 54
'Name' : 'UserName'
'Password' : 'Password'
'DeviceID' : 1

'additionalInfo' : {
"LATITUDE","Value":'17.87‟,
"LONGITUDE","Value":'79.10',
"SOFWARENAME","Value":'fm varsion 1.0'
},

„Records‟:
{
„record‟ :{
'Datetime' : "2015-06-10 14:30:00"
'Variables' : {
{"Variablename":"NO2","Value":12.2,”Flag”:””, "Unit":"mg/nm3"},
{"Variablename":"NOX","Value":122.2, ”Flag”:””,"Unit":"mg/nm3"},
{" Variablename":"SO2","Value":23.2, ”Flag”:””,"Unit":"mg/nm3"}, {"
Variablename":"SOX","Value":43.2, ”Flag”:””,"Unit":"mg/nm3"}
}
},
„record‟ :{
'Datetime' : "2015-06-10 14:31:00"
'Variables' : {
{"Variablename":"NO2","Value":”err”, ”Flag”:””,"Unit":"mg/nm3"},
{"Variablename":"NOX","Value":122.2”Flag”:””,,"Unit":"mg/nm3"},
{"Variablename":"SO2","Value":23.2, ”Flag”:””,"Unit":"mg/nm3"},
{"Variablename":"SOX","Value":43.2, ”Flag”:””,"Unit":"mg/nm3"}
}
}
}

Response Details

„Result Code‟ : 1/2/3


'Message' : „Error Message if any‟

Response Code Message


1
2 Invalid User Name and Password
3 Incomplete Data

*Multiple error may get added. For Result Code “1” i.e. success, there will be no
Message.

You might also like