API for IoT Device Connectivity
This section of the website describes the mechanism for retrieving data from "open devices."
If you're interested in connecting a device to our server, please refer to the documentation section on "
Protocols".
Remote data access for third-party services is available only for open-access devices
and is implemented as a URL request to the server. The request can be either GET or POST.
Parameters for getting data for a specific period of time:
- URL: 'https://viziot.com/getdata/';
- action: 'getDataOpenDeviceByPeriod';
- keyPublicDevice: public access key to the device (44 characters);
- timeStampStart: start date of the data retrieval period in Unix Time Stamp format, e.g., 1613825023;
- timeStampEnd: end date of the data retrieval period in Unix Time Stamp format, e.g., 1613835023;
The result of the request will be a JSON string with parameters:
- type (text parameter) – can take two values: "ok" or "error"
- points (array) – contains an array of elements of type "point"
- description (text parameter) – error description
Request: https://viziot.com/getdata/?action=getDataOpenDeviceByPeriod&ampampampampampampampampampampampampampampampampampampampampampampampamp;keyPublicDevice=8UNT6XZY9Y6VC48Q5S6HP9JHDK4XVII7UWHJSYU3MLPG&timeStampStart=1613825023&timeStampEnd=1613835023
Response: {"type":"ok","points":[{"date":"1543838492","param":{"f1":"-57","f2":"0.00","f3":"0.00","f4":"0.00","f5":"0.00"}},{"date":"1543838507","param":{"f1":"-56","f2":"0.00","f3":"0.00","f4":"0.00","f5":"0.00"}}]}
Parameters for getting the latest data from the IoT device:
- URL: 'https://viziot.com/getdata/';
- action: 'getLastDataOpenDevice';
- keyPublicDevice: public access key to the device (44 characters);
The result of the request will be a JSON string with parameters:
- type (text parameter) – can take two values: "ok" or "error"
- point (object) – data type "point"
- description (text parameter) – error description
Request: https://viziot.com/getdata/?action=getLastDataOpenDevice&keyPublicDevice=8UNT6XZY9Y6VC48Q5S6HP9JHDK4XVII7UWHJSYU3MLPG
Response: {"type":"ok","point":{"date":"1543839005","param":{"f1":"-56","f2":"0.00","f3":"0.00","f4":"0.00","f5":"0.00"}}}
Data type "point"
Data type "point" consists of two parameters:
- date (number) – date in Unix Time Stamp format
- point (object) – object with sensor data
JavaScript code example with jQuery library:
function getDataOpenDeviceByPeriod() {
$.ajax({
type:"POST",
dataType:'json',
url:'https://viziot.com/getdata/',
timeout: 10000,
data:{
'action':'getDataOpenDeviceByPeriod',
"keyPublicDevice" : "XPHQM555HIB8P7USMGZM7YFLLRMAP7YIFJZQJY0CTSCV",
"timeStampStart" : parseInt(new Date().getTime()/1000) - (60*60*24),
"timeStampEnd" : parseInt(new Date().getTime()/1000),
},
success: function(json){
var data = eval(json);
switch(data.type) {
case 'ok':
console.log('ok', data);
break;
case 'error':
console.log("error", data);
break;
default :
console.log(json);
}
}
});
}
function getLastDataOpenDevice() {
$.ajax({
type:"POST",
dataType:'json',
url:'https://viziot.com/getdata/',
timeout: 10000,
data:{
'action':'getLastDataOpenDevice',
"keyPublicDevice" : "XPHQM555HIB8P7USMGZM7YFLLRMAP7YIFJZQJY0CTSCV",
},
success: function(json){
var data = eval(json);
switch(data.type) {
case 'ok':
console.log('ok', data);
break;
case 'error':
console.log("error", data);
break;
default :
console.log(json);
}
}
});
}
$(function(){
getDataOpenDeviceByPeriod();
getLastDataOpenDevice();
})