ko / ambient-weather
A PHP SDK for interacting with the ambient weather api to retrieve data and draw canvas visualizations
0.0.6
2018-02-05 16:22 UTC
Requires
- ko/json-cache: 0.0.*
Requires (Dev)
- apigen/apigen: dev-master
- roave/better-reflection: dev-master#c87d856
This package is not auto-updated.
Last update: 2024-11-16 01:41:14 UTC
README
This module is built for interacting with the ambientweather.net API. It utilizes the ko\json-cache module to reduce pressure on the ambient weather API and to provide a faster load time for the weather station data.
Demo
Install
composer require ko/ambient-weather
Properties
Usage
Build the cache
Build the cache
settings object
$KOCacheSettings = new \KO\Cache\Settings(); $KOCacheSettings->setValidity(15); $KOCacheSettings->setFile('data_cache.json');
Instantiate a new cache object with the settings
$KOCache = new \KO\Cache\Cache($KOCacheSettings);
Build the AmbientWeather object
Build the AmbientWeather
settings object
$AWSettings = new \KO\AmbientWeather\Settings(); $AWSettings->setApiKey('your-api-key-here'); $AWSettings->setApplicationKey('your-application-key-here'); $AWSettings->setInterval(5); $AWSettings->setTimeframe(4); $AWSettings->setDevice('device-mac-address');
Instantiate a new AmbientWeather
object with the settings
$AW = new \KO\AmbientWeather\AmbientWeather($AWSettings, $KOCache);
Charts
new KO\AmbientWeather\Charts\Wind($AW);
new KO\AmbientWeather\Charts\Temperature($AW);
new KO\AmbientWeather\Charts\Barometric($AW);
Gauges
KO\AmbientWeather\Gauges\WindDirection($AW);
KO\AmbientWeather\Gauges\WindSpeed($AW);
Complete Example
<?php
date_default_timezone_set("America/New_York");
require("vendor/autoload.php");
$KOCacheSettings = new \KO\Cache\Settings();
$KOCacheSettings->setValidity(15);
$KOCacheSettings->setFile('data_cache.json');
$KOCache = new \KO\Cache\Cache($KOCacheSettings);
$AWSettings = new \KO\AmbientWeather\Settings();
$AWSettings->setApiKey('your-key-here');
$AWSettings->setApplicationKey('your-key-here');
$AWSettings->setInterval(5);
$AWSettings->setTimeframe(1);
$AWSettings->setDevice('your-MAC-here');
$AW = new \KO\AmbientWeather\AmbientWeather($AWSettings, $KOCache);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js"></script>
<script src="//cdn.rawgit.com/Mikhus/canvas-gauges/gh-pages/download/2.1.4/all/gauge.min.js"></script>
</head>
<body>
<?php
new KO\AmbientWeather\Charts\Wind($AW);
new KO\AmbientWeather\Charts\Temperature($AW);
new KO\AmbientWeather\Charts\Barometric($AW);
new KO\AmbientWeather\Gauges\WindDirection($AW);
new KO\AmbientWeather\Gauges\WindSpeed($AW);
?>
</body>
</html>
Documentation
See the full Documentation for more details.