A lightweight client for retrieving sensor data from a senseBox from the opensensemap api.
This is not an official project from the senseBox team.
Install via composer:
composer require moay/opensensemap-api-php-client
Take a look at the implementation example in the directory example
.
$client = OpensensemapApiClientFactory::create();
// Change senseBox id
$senseBoxData = $client->getSenseBoxData('someSenseBoxId');
foreach ($senseBoxData as $sensorValue) {
// $sensorValue->getValueType()
// $sensorValue->getValue()
// $sensorValue->getUnit()
// $sensorValue->getSensorType()
// $sensorValue->getMeasurementTime()->format('Y-m-d H:i:s')
}
You don't have to iterate over all values, just use this handy function:
$temperature = $senseBoxData->getValueByType(SensorValue::TYPE_TEMPERATURE);
Outputting values can be done directly by casting the values to strings:
echo 'Temperature: '.$temperature; // Output: Temperature: 12 °C
echo $temperature; // Output: 12 °C
$temperatureString = (string) $temperature // $temperatureString = '12 °C'
The client gives you the latest data for a specific senseBox from the OpenSenseMap Api.
As there was no need for further features, none have been implemented. This could easily be done, though. Feel free to submit a PR.
The client is published under the MIT license.
senseBox and all related contents, visuals and brands are published under CC licenses or other public domain licenses. Make sure to check out the project.