blueweather/api/json.php

41 lines
1.1 KiB
PHP

<?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';
require_once './blueweather.php';
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
$blueweather = new BlueWeather($config);
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']);
$data = getLocationData($locId, $range, $maxVals);
} else {
$data = $blueweather->getAllLocations();
}
http_response_code(200);
echo json_encode($data);