In [1]:
// Portia service URL for token authorization checking
$url = "http://io.portia.supe.solutions/api/v1/accesstoken/check";
// Creates a stream for HTTP request
$options = [
"http" => [
"method" => "GET"
]
];
$context = stream_context_create($options);
// Makes the request
$response = file_get_contents($url, false, $context);
Out[1]:
In [2]:
// Portia service URL for token authorization checking
$url = "http://io.portia.supe.solutions/api/v1/accesstoken/check";
// Creates a stream for HTTP request
$options = [
"http" => [
"method" => "GET",
"header" => "Authorization: Bearer bdb6e780b43011e7af0b67cba486057b\r\n" // Setting the header with a token for successful authorization
]
];
$context = stream_context_create($options);
// Makes the request
$response = file_get_contents($url, false, $context);
// Shows response
if($http_response_header[0] == "HTTP/1.1 200 OK") {
echo("Success accessing Portia Service - Status: " . $http_response_header[0] . "\n" . $response);
} else {
echo("Couldn't access Portia service - Status: " . $http_response_header[0]);
}
Out[2]:
In [8]:
// Example for getting the last 5 minutes of data
$fiveMinutes = 1000 * 60 * 5;
$toTimestamp = time() * 1000; // The time function only gives us the UTC time as seconds since January 1, 1970, so, we multiply by 1000 to get the milliseconds
$fromTimestamp = $toTimestamp - $fiveMinutes;
// Portia service URL for specific time frame
$url = "http://io.portia.supe.solutions/api/v1/device/HytTDwUp-j8yrsh8e/port/2/sensor/1";
// Adding the calculated timestamps as GET parameters
$url = $url . "?from_timestamp=$fromTimestamp&?to_timestamp=$toTimestamp"; // If no parameters, the service default response is for the last 24 hours
// Creates a stream for HTTP request
$options = [
"http" => [
"method" => "GET",
"header" => "Authorization: Bearer bdb6e780b43011e7af0b67cba486057b\r\n" // Setting the header with a token for successful authorization
]
];
$context = stream_context_create($options);
// Makes the request
$response = file_get_contents($url, false, $context);
// Shows response
if($http_response_header[0] == "HTTP/1.1 200 OK") {
// Parses dimensions
$dimensions = json_decode($response);
echo("Success! For each received dimension: ");
foreach($dimensions as $dimension) {
echo("Accessing dimension package:");
echo("\tDimension Code: " . $dimension -> dimension_code);
echo("\tUnity Code: " . $dimension -> dimension_unity_code);
echo("\tThing Code: " . $dimension -> dimension_thing_code);
echo("\tDimension Value: " . $dimension -> dimension_value);
echo("\tServer Timestamp: " . $dimension -> server_timestamp);
}
} else {
echo("Couldn't access Portia service - Status: " . $http_response_header[0]);
}
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
Out[8]:
In [11]:
// Portia service URL for getting the latest data
$url = "http://io.portia.supe.solutions/api/v1/device/HytTDwUp-j8yrsh8e/port/2/sensor/1/last";
// Creates a stream for HTTP request
$options = [
"http" => [
"method" => "GET",
"header" => "Authorization: Bearer bdb6e780b43011e7af0b67cba486057b\r\n" // Setting the header with a token for successful authorization
]
];
$context = stream_context_create($options);
// Makes the request
$response = file_get_contents($url, false, $context);
// Shows response
if($http_response_header[0] == "HTTP/1.1 200 OK") {
// Parses dimensions
$dimension = json_decode($response)[0];
echo("Success! Accessing dimension package:");
echo("\tDimension Code: " . $dimension -> dimension_code);
echo("\tUnity Code: " . $dimension -> dimension_unity_code);
echo("\tThing Code: " . $dimension -> dimension_thing_code);
echo("\tDimension Value: " . $dimension -> dimension_value);
echo("\tServer Timestamp: " . $dimension -> server_timestamp);
} else {
echo("Couldn't access Portia service - Status: " . $http_response_header[0]);
}
Out[11]:
Out[11]:
Out[11]:
Out[11]:
Out[11]:
Out[11]:
In [12]:
// Portia service URL for getting the latest data
$url = "http://io.portia.supe.solutions/api/v1/device/HytTDwUp-j8yrsh8e/port/2/sensor/1/last";
# Adding GET parameter for specifying that we want the last 3 dimension packages
$url = $url . "?limit=3";
// Creates a stream for HTTP request
$options = [
"http" => [
"method" => "GET",
"header" => "Authorization: Bearer bdb6e780b43011e7af0b67cba486057b\r\n" // Setting the header with a token for successful authorization
]
];
$context = stream_context_create($options);
// Makes the request
$response = file_get_contents($url, false, $context);
// Shows response
if($http_response_header[0] == "HTTP/1.1 200 OK") {
// Parses dimensions
$dimensions = json_decode($response);
echo("Success! For each received dimension: ");
foreach($dimensions as $dimension) {
echo("Accessing dimension package:");
echo("\tDimension Code: " . $dimension -> dimension_code);
echo("\tUnity Code: " . $dimension -> dimension_unity_code);
echo("\tThing Code: " . $dimension -> dimension_thing_code);
echo("\tDimension Value: " . $dimension -> dimension_value);
echo("\tServer Timestamp: " . $dimension -> server_timestamp);
}
} else {
echo("Couldn't access Portia service - Status: " . $http_response_header[0]);
}
Out[12]:
Out[12]:
Out[12]:
Out[12]:
Out[12]:
Out[12]:
Out[12]:
Out[12]:
Out[12]:
Out[12]:
Out[12]:
Out[12]:
Out[12]:
Out[12]:
Out[12]:
Out[12]:
Out[12]:
Out[12]:
Out[12]: