blueweather/api/json.php

42 lines
1.1 KiB
PHP
Raw Normal View History

2019-07-13 20:02:47 +02:00
<?php
/**
* BlueWeather
*
* PHP version 7.2
*
* @param locId
* @param range (range[from]: from UNIX time; range[to]: to UNIX time)
* @param maxVals (maximum measvals to be transmitted; if more are present in the timespan, the avarage will be calculated)
*
* @category Tools
* @package BlueWeather
* @author Dorian Zedler <dorian@itsblue.de>
* @license GPLV3 gpl.com
* @link itsblue.de
*/
require_once './config.php';
2019-07-15 20:29:19 +02:00
require_once './blueweather.php';
2019-07-13 20:02:47 +02:00
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
2019-07-15 20:29:19 +02:00
$blueweather = new BlueWeather($config);
2019-07-13 20:02:47 +02:00
if (isset($_GET['locId'])) {
// get data of given location
$locId = $con->real_escape_string($_GET['locId']);
$range['from'] = $con->real_escape_string($_GET['range']['from']);
$range['to'] = $con->real_escape_string($_GET['range']['to']);
$maxVals = $con->real_escape_string($_GET['maxVals']);
2019-07-15 20:29:19 +02:00
$data = getLocationData($locId, $range, $maxVals);
2019-07-13 20:02:47 +02:00
} else {
2019-07-15 20:29:19 +02:00
$data = $blueweather->getAllLocations();
2019-07-13 20:02:47 +02:00
}
http_response_code(200);
echo json_encode($data);