moay / opensensemap-api-php-client
A client for retrieving sensor data from a senseBox from the opensensemap api
Requires
- php: >=7.1
- ext-json: *
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- phpunit/phpunit: ^7
This package is auto-updated.
Last update: 2024-10-26 07:12:45 UTC
README
opensensemap-api-php-client
A lightweight client for retrieving sensor data from a senseBox from the opensensemap api.
This is not an official project from the senseBox team.
Setup
Install via composer:
composer require moay/opensensemap-api-php-client
Usage
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'
Features
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.
License
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.