PHP code example of graystackit / laravel-testo-api
1. Go to this page and download the library: Download graystackit/laravel-testo-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
graystackit / laravel-testo-api example snippets
use GraystackIT\TestoCloud\TestoCloudClient;
$client = app(TestoCloudClient::class);
use Carbon\Carbon;
// 1. Submit
$submit = $client->submitMeasurementRequest(
from: Carbon::parse('2025-01-01'),
to: Carbon::parse('2025-01-31'),
format: 'JSON', // optional, default 'JSON'
);
echo $submit->requestUuid;
// 2. Poll
$status = $client->checkRequestStatus($submit->requestUuid);
if ($status->isCompleted()) {
foreach ($status->dataUrls as $url) {
$content = $client->downloadDataFile($url);
// parse with MeasurementNdjsonParser...
}
}
use GraystackIT\TestoCloud\Parsers\MeasurementNdjsonParser;
$measurements = (new MeasurementNdjsonParser())->parse($content);
// [['timestamp' => '...', 'temperature' => 21.5, 'humidity' => 55.0], ...]
use Carbon\Carbon;
// 1. Submit
$submit = $client->submitAlarmRequest(
from: Carbon::parse('2025-01-01'),
to: Carbon::parse('2025-01-31'),
);
// 2. Poll
$status = $client->checkAlarmStatus($submit->requestUuid);
if ($status->isCompleted()) {
foreach ($status->dataUrls as $url) {
$content = $client->downloadDataFile($url);
}
}
$submit = $client->submitTaskRequest(
from: Carbon::parse('2025-01-01'),
to: Carbon::parse('2025-01-31'),
);
$status = $client->checkTaskStatus($submit->requestUuid);
if ($status->isFailed()) {
logger()->error($status->error);
}
$submit = $client->submitEquipmentRequest(format: 'JSON'); // format optional
$status = $client->checkEquipmentStatus($submit->requestUuid);
if ($status->isCompleted()) {
foreach ($status->dataUrls as $url) {
$content = $client->downloadDataFile($url);
}
}
$submit = $client->submitLocationRequest(format: 'JSON'); // format optional
$status = $client->checkLocationStatus($submit->requestUuid);
if ($status->isCompleted()) {
foreach ($status->dataUrls as $url) {
$content = $client->downloadDataFile($url);
}
// Optional metadata file
if ($status->metadataUrl) {
$meta = $client->downloadDataFile($status->metadataUrl);
}
}
use GraystackIT\TestoCloud\Enums\AsyncRequestStatus;
AsyncRequestStatus::Submitted // initial acknowledgment
AsyncRequestStatus::Processing // API is preparing data ("In Progress" normalised)
AsyncRequestStatus::Completed // data ready for download
AsyncRequestStatus::Failed // see $response->error
bash
# Last 7 days (default)
php artisan testo:fetch-measurements
# Specific date range
php artisan testo:fetch-measurements --from=2025-01-01 --to=2025-01-31
# Single device only
php artisan testo:fetch-measurements --from=2025-03-01 --to=2025-03-31 --logger-uuid=abc-123
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.