Code: Select all
*** api.txt Sat Nov 22 14:20:21 2025
--- api_new.php Mon Aug 26 15:48:52 2024
***************
*** 16,30 ****
# v2.2 2017-07-02 Added Extra sensors; fixed bug rain at begin of day
# v3.0 2017-08-11 Added multipliers
# v3.1 2017-12-20 Discard outdated parameters; added mysql error logging
#
############################################################################
! error_reporting(E_ALL);
$apiLog = array();
$rawInput = array();
$utc = time();
$timeId = "Time";
if(isset($apiUpdate)){
############################################################################
// api included by CUMULUS, WU, CUSTOM, NETATMO, WLIP
--- 16,75 ----
# v2.2 2017-07-02 Added Extra sensors; fixed bug rain at begin of day
# v3.0 2017-08-11 Added multipliers
# v3.1 2017-12-20 Discard outdated parameters; added mysql error logging
+ # v3.2 2021-05-08 added option not reload ( from meteotemplateLive.txt ) sensor not received
+ # v3.2a 2021-05-08 added option $numSensors to define max extra sensor
+ # v3.2b 2021-07-12 added option $logGetPost to log api.php call ( cache/apiReqLog.txt )
#
############################################################################
! //ini_set('display_errors', 1);
! //ini_set('display_startup_errors', 1);
! //error_reporting(E_ALL);
!
! if (!function_exists('count80'))
! {
! function count80($a)
! {
! if ((PHP_VERSION_ID < 70300) || (is_countable($a)))
! return count($a);
! else
! return 0;
! }
! }
!
$apiLog = array();
$rawInput = array();
$utc = time();
$timeId = "Time";
+ ini_set( 'serialize_precision', -1 ); // so json_encode does not 'change roundness' ( for PHP >= 7.1 )
+ $reloadLive = 1; // 1 = old behaviour 0 = does not reload sensor not received
+ $numSensors = 8;
+ $logGetPost = 0; // 1 = log Get/Post params to cache/apiReqLog.txt ( does not log your password )
+ $Log = array();
+ if ($logGetPost)
+ {
+ // log post and get data
+ if(isset($_POST))
+ {
+ foreach($_POST as $urlParameter=>$value)
+ {
+ if($urlParameter!="PASSWORD" && $urlParameter!="PASS")
+ {$Log['info'][] = "post ".$urlParameter.": ".$value;}
+ }
+ }
+ if(isset($_GET))
+ {
+ foreach($_GET as $urlParameter=>$value)
+ {
+ if($urlParameter!="PASSWORD" && $urlParameter!="PASS")
+ {$Log['info'][] = "get ".$urlParameter.": ".$value;}
+ }
+ }
+ generateLog($base, $Log, "apiReqLog.txt", 1);
+ }
+
+
if(isset($apiUpdate)){
############################################################################
// api included by CUMULUS, WU, CUSTOM, NETATMO, WLIP
***************
*** 90,96 ****
else{
// no data in api
$apiLog['error'][] = "api: no data";
! generateAPILog();
die("api: no data");
}
############################################################################
--- 135,141 ----
else{
// no data in api
$apiLog['error'][] = "api: no data";
! generateLog($base, $apiLog, "apiLog.txt");
die("api: no data");
}
############################################################################
***************
*** 228,236 ****
}
}
// add saved live data fields for not updated fields
! foreach ($liveInput as $key => $value) {
! if(!isset($rawInput[$key])){
// if live data key not present use saved live data
$rawInput[$key] = $value;
// time fields ($rawInput[$key.$timeId]) will be copied too
--- 273,285 ----
}
}
+ if ($reloadLive)
+ {
// add saved live data fields for not updated fields
! foreach ($liveInput as $key => $value)
! {
! if(!isset($rawInput[$key]))
! {
// if live data key not present use saved live data
$rawInput[$key] = $value;
// time fields ($rawInput[$key.$timeId]) will be copied too
***************
*** 252,258 ****
--- 301,344 ----
$rawOutput = json_encode($rawInput,JSON_NUMERIC_CHECK);
$apiLog['info'][] = "Save meteotemplateLive.txt: ".$rawOutput;
file_put_contents($base."meteotemplateLive.txt",$rawOutput);
+ }
+ else
+ {
+ // calculate dewpoint
+ if (isset($rawInput['T']) && isset($rawInput['H']) )
+ {
+ $rawInput['D'] = (string)dewpoint($rawInput['T'], $rawInput['H']);
+ $rawInput['D'.$timeId] = $utc;
+ $apiLog['info'][] = "calculated D: ".$rawInput['D'];
+ }
+ // calculate apparent temp
+ if (isset($rawInput['T']) && isset($rawInput['H']) && isset($rawInput['W']) )
+ {
+ $rawInput['A'] = (string)apparent($rawInput['T'], $rawInput['H'], $rawInput['W'] / 3.6);
+ $rawInput['A'.$timeId] = $utc;
+ $apiLog['info'][] = "calculated A: ".$rawInput['A'];
+ }
+ $rawInputOld = $rawInput;
+ // add saved live data fields for not updated fields
+ foreach ($liveInput as $key => $value)
+ {
+ if(!isset($rawInput[$key]))
+ {
+ // if live data key not present use saved live data
+ $rawInput[$key] = $value;
+ // time fields ($rawInput[$key.$timeId]) will be copied too
+ $apiLog['info'][] = "add live data: ".$key.": ".$value;
+ }
+ }
+
+ // save raw input
+ $rawOutput = json_encode($rawInput,JSON_NUMERIC_CHECK);
+ $apiLog['info'][] = "Save meteotemplateLive.txt: ".$rawOutput;
+ file_put_contents($base."meteotemplateLive.txt",$rawOutput);
+ $rawInput = $rawInputOld;
+ }
+
// check we have write permissions for the cache folder and meteotemplateLive.txt
if(!file_exists($base."meteotemplateLive.txt")){
$apiLog['error'][] = "meteotemplateLive.txt was not created! Probably incorrect permissions for the template root folder.";
***************
*** 749,755 ****
// EXTRA SENSORS
############################################################################
// Now parse extra sensors
! if(count($extraSensors)>0){
$extraQueryParams = array();
$extraQueryValues = array();
$apiLog['info'][] = "Now parsing extra sensors.";
--- 835,841 ----
// EXTRA SENSORS
############################################################################
// Now parse extra sensors
! if(count80($extraSensors)>0){
$extraQueryParams = array();
$extraQueryValues = array();
$apiLog['info'][] = "Now parsing extra sensors.";
***************
*** 790,801 ****
--- 876,905 ----
$thisSensorUnits = "";
$thisSensorDecimals = 0;
}
+ if($extraSensor == "LD"){
+ $thisSensorName = "lightning distance";
+ $thisSensorLimits = array(0,100);
+ $thisSensorUnits = "";
+ $thisSensorDecimals = 0;
+ }
+ if($extraSensor == "LT"){
+ $thisSensorName = "lightning time";
+ $thisSensorLimits = array(0,10000000000);
+ $thisSensorUnits = "";
+ $thisSensorDecimals = 0;
+ }
if($extraSensor == "SS"){
$thisSensorName = "sunshine";
$thisSensorLimits = array(0,24);
$thisSensorUnits = "h";
$thisSensorDecimals = 1;
}
+ if($extraSensor == "ET"){
+ $thisSensorName = "evapotranspiration";
+ $thisSensorLimits = array(0,24);
+ $thisSensorUnits = "mm";
+ $thisSensorDecimals = 3;
+ }
if($extraSensor == "UV"){
$thisSensorName = "UV";
$thisSensorLimits = array(0,20);
***************
*** 803,809 ****
$thisSensorDecimals = 1;
}
//$for($g=1;$g<=4;$g++){
! for($g=1;$g<=4;$g++){
if($extraSensor == "T".$g){
$thisSensorName = "extra temperature sensor ".$g;
$thisSensorLimits = array(-60,60);
--- 907,913 ----
$thisSensorDecimals = 1;
}
//$for($g=1;$g<=4;$g++){
! for($g=1;$g<=$numSensors;$g++){
if($extraSensor == "T".$g){
$thisSensorName = "extra temperature sensor ".$g;
$thisSensorLimits = array(-60,60);
***************
*** 824,830 ****
}
if($extraSensor == "SM".$g){
$thisSensorName = "soil moisture sensor ".$g;
! $thisSensorLimits = array(0.01,200);
$thisSensorUnits = "";
$thisSensorDecimals = 1;
}
--- 928,934 ----
}
if($extraSensor == "SM".$g){
$thisSensorName = "soil moisture sensor ".$g;
! $thisSensorLimits = array(0.0,200);
$thisSensorUnits = "";
$thisSensorDecimals = 1;
}
***************
*** 908,914 ****
// get latest date from cache file
$cacheRaw = file_get_contents($base."cache/apiCache.txt");
$cache = json_decode($cacheRaw,true);
! $latestCacheDate = $cache['timestamp'][count($cache['timestamp'])-1];
if (time()-$latestCacheDate > 60 * 30) {
unlink($base."cache/apiCache.txt");
$apiLog['info'][] = "Cache file is over 30 minutes old, deleting it.";
--- 1012,1018 ----
// get latest date from cache file
$cacheRaw = file_get_contents($base."cache/apiCache.txt");
$cache = json_decode($cacheRaw,true);
! $latestCacheDate = $cache['timestamp'][count80($cache['timestamp'])-1];
if (time()-$latestCacheDate > 60 * 30) {
unlink($base."cache/apiCache.txt");
$apiLog['info'][] = "Cache file is over 30 minutes old, deleting it.";
***************
*** 934,943 ****
// Check for partial data in cache when data is not present
$validCachedT = false;
! if(!isset($rawData['T'])){
// use cached data instead when present
! if(count($cache['T']) > 0) {
! $T = $cache['T'][count($cache['T'])-1];
$validCachedT = true;
$apiLog['info'][] = "Use cached Temperature for calculations: ".$T;
}
--- 1038,1047 ----
// Check for partial data in cache when data is not present
$validCachedT = false;
! if(!isset($rawData['T']) && $reloadLive){
// use cached data instead when present
! if(count80($cache['T']) > 0) {
! $T = $cache['T'][count80($cache['T'])-1];
$validCachedT = true;
$apiLog['info'][] = "Use cached Temperature for calculations: ".$T;
}
***************
*** 949,958 ****
}
$validCachedH = false;
! if(!isset($rawData['H'])){
// use cached data instead when present
! if(count($cache['H']) > 0) {
! $H = $cache['H'][count($cache['H'])-1];
$validCachedH = true;
$apiLog['info'][] = "Use cached Humidity for calculations: ".$H;
}
--- 1053,1062 ----
}
$validCachedH = false;
! if(!isset($rawData['H']) && $reloadLive){
// use cached data instead when present
! if(count80($cache['H']) > 0) {
! $H = $cache['H'][count80($cache['H'])-1];
$validCachedH = true;
$apiLog['info'][] = "Use cached Humidity for calculations: ".$H;
}
***************
*** 964,973 ****
}
$validCachedW = false;
! if(!isset($rawData['W'])){
// use cached data instead when present
! if(count($cache['W']) > 0) {
! $W = $cache['W'][count($cache['W'])-1];
$validCachedW = true;
$apiLog['info'][] = "Use cached Wind for calculations: ".$W;
}
--- 1068,1077 ----
}
$validCachedW = false;
! if(!isset($rawData['W']) && $reloadLive){
// use cached data instead when present
! if(count80($cache['W']) > 0) {
! $W = $cache['W'][count80($cache['W'])-1];
$validCachedW = true;
$apiLog['info'][] = "Use cached Wind for calculations: ".$W;
}
***************
*** 1072,1077 ****
--- 1176,1182 ----
$temperatureC = $T;
}
$rawDCelsius = dewpoint($temperatureC, $H);
+ $apiLog['info'][] = "rawDCelsius: ".$rawDCelsius." ".$temperatureC." ".$H;
// convert back to Farenheit if necessary
if($dataTempUnits=="F"){
$rawD = convertor($rawDCelsius,"C","F");
***************
*** 1127,1133 ****
// just do some basic checking, but should be ok since T, H and W both valid
if(is_numeric($rawA) && $rawA!=="" && $rawA!=null && $rawA>-100 && $rawA<200){
$data['A'] = $rawA;
! $apiLog['info'][] = "Apparent temperature ok.";
}
else{
$apiLog['error'][] = "There is some problem with the calculated apparent temperature value. Ignored.";
--- 1232,1238 ----
// just do some basic checking, but should be ok since T, H and W both valid
if(is_numeric($rawA) && $rawA!=="" && $rawA!=null && $rawA>-100 && $rawA<200){
$data['A'] = $rawA;
! $apiLog['info'][] = "Apparent temperature ok. ".$data['A'];
}
else{
$apiLog['error'][] = "There is some problem with the calculated apparent temperature value. Ignored.";
***************
*** 1147,1154 ****
$dbInterval = 300;
// check if cache file contain a record
! if(isset($cache['timestamp']) && is_array($cache['timestamp'])){
! if(count($cache["timestamp"]) > 0) {
// timeForUpdate calculated from timestamp of first cached data
$checkTimestamp = $cache["timestamp"][0];
$apiLog['info'][] = "End time for database update based on timestamp of first cache data: ".date("Y-m-d H:i:s",$checkTimestamp);
--- 1252,1258 ----
$dbInterval = 300;
// check if cache file contain a record
! if(count80($cache["timestamp"]) > 0) {
// timeForUpdate calculated from timestamp of first cached data
$checkTimestamp = $cache["timestamp"][0];
$apiLog['info'][] = "End time for database update based on timestamp of first cache data: ".date("Y-m-d H:i:s",$checkTimestamp);
***************
*** 1158,1169 ****
$checkTimestamp = $data['timestamp'];
$apiLog['info'][] = "End time for database update based on timestamp of current data: ".date("Y-m-d H:i:s",$checkTimestamp);
}
- }
- else {
- // timeForUpdate calculated from timestamp of current data
- $checkTimestamp = $data['timestamp'];
- $apiLog['info'][] = "End time for database update based on timestamp of current data: ".date("Y-m-d H:i:s",$checkTimestamp);
- }
if($checkTimestamp % $dbInterval == 0) {
$timeForUpdate = $checkTimestamp; // $checkTimestamp is equal to end time of current archive period
}
--- 1262,1267 ----
***************
*** 1229,1236 ****
}
// extra parameters
! if(count($extraQueryParams)>0){
! for($j = 0; $j < count($extraQueryParams); $j++){
$cache[$extraQueryParams[$j]][] = $extraQueryValues[$j];
}
}
--- 1327,1334 ----
}
// extra parameters
! if(count80($extraQueryParams)>0){
! for($j = 0; $j < count80($extraQueryParams); $j++){
$cache[$extraQueryParams[$j]][] = $extraQueryValues[$j];
}
}
***************
*** 1243,1249 ****
// create the column name array for db and values array and insert date
$db['parameters'][] = "DateTime";
$firstCacheDate = $cache['timestamp'][0];
! $lastCacheDate = $cache['timestamp'][count($cache['timestamp'])-1];
$apiLog['info'][] = "Timestamp first cached record: ".date("Y-m-d H:i:s",$firstCacheDate);
$apiLog['info'][] = "Timestamp last cached record: ".date("Y-m-d H:i:s",$lastCacheDate);
$apiLog['info'][] = "Timestamp last received record: ".date("Y-m-d H:i:s",$data['timestamp']);
--- 1341,1347 ----
// create the column name array for db and values array and insert date
$db['parameters'][] = "DateTime";
$firstCacheDate = $cache['timestamp'][0];
! $lastCacheDate = $cache['timestamp'][count80($cache['timestamp'])-1];
$apiLog['info'][] = "Timestamp first cached record: ".date("Y-m-d H:i:s",$firstCacheDate);
$apiLog['info'][] = "Timestamp last cached record: ".date("Y-m-d H:i:s",$lastCacheDate);
$apiLog['info'][] = "Timestamp last received record: ".date("Y-m-d H:i:s",$data['timestamp']);
***************
*** 1265,1271 ****
if(isset($cache['T'])){
$db['parameters'][] = "T";
// take temperature average and convert to db units
! $rawValue = array_sum($cache['T'])/count($cache['T']);
$db['fields'][] = number_format($rawValue,1,".","");
}
--- 1363,1369 ----
if(isset($cache['T'])){
$db['parameters'][] = "T";
// take temperature average and convert to db units
! $rawValue = array_sum($cache['T'])/count80($cache['T']);
$db['fields'][] = number_format($rawValue,1,".","");
}
***************
*** 1305,1311 ****
if(isset($cache['H'])){
$db['parameters'][] = "H";
// take humidity average
! $rawValue = array_sum($cache['H'])/count($cache['H']);
$db['fields'][] = number_format($rawValue,1,".","");
}
--- 1403,1409 ----
if(isset($cache['H'])){
$db['parameters'][] = "H";
// take humidity average
! $rawValue = array_sum($cache['H'])/count80($cache['H']);
$db['fields'][] = number_format($rawValue,1,".","");
}
***************
*** 1320,1326 ****
if(isset($cache['P'])){
$db['parameters'][] = "P";
// take pressure average
! $rawValue = array_sum($cache['P'])/count($cache['P']);
$db['fields'][] = number_format($rawValue,$decimalsP,".","");
}
--- 1418,1424 ----
if(isset($cache['P'])){
$db['parameters'][] = "P";
// take pressure average
! $rawValue = array_sum($cache['P'])/count80($cache['P']);
$db['fields'][] = number_format($rawValue,$decimalsP,".","");
}
***************
*** 1328,1334 ****
if(isset($cache['W'])){
$db['parameters'][] = "W";
// take wind average
! $rawValue = array_sum($cache['W'])/count($cache['W']);
$db['fields'][] = number_format($rawValue,1,".","");
}
--- 1426,1432 ----
if(isset($cache['W'])){
$db['parameters'][] = "W";
// take wind average
! $rawValue = array_sum($cache['W'])/count80($cache['W']);
$db['fields'][] = number_format($rawValue,1,".","");
}
***************
*** 1371,1377 ****
// use max value for check and update of last days registration
$maxRain = number_format(max($cache['R']),$decimalsR,".","");
// use last value for other periods
! $currentRain = number_format($cache['R'][count($cache['R'])-1],$decimalsR,".","");
// check if newDay
if($newDay){
--- 1469,1475 ----
// use max value for check and update of last days registration
$maxRain = number_format(max($cache['R']),$decimalsR,".","");
// use last value for other periods
! $currentRain = number_format($cache['R'][count80($cache['R'])-1],$decimalsR,".","");
// check if newDay
if($newDay){
***************
*** 1422,1428 ****
$rawValue = max($cache['RR']);
}
else{
! $rawValue = array_sum($cache['RR'])/count($cache['RR']);
}
$db['fields'][] = number_format($rawValue,$decimalsR,".","");
}
--- 1520,1526 ----
$rawValue = max($cache['RR']);
}
else{
! $rawValue = array_sum($cache['RR'])/count80($cache['RR']);
}
$db['fields'][] = number_format($rawValue,$decimalsR,".","");
}
***************
*** 1432,1438 ****
if(isset($cache['S'])){
$db['parameters'][] = "S";
// take solar radiation average
! $rawValue = array_sum($cache['S'])/count($cache['S']);
$db['fields'][] = number_format($rawValue,1,".","");
}
}
--- 1530,1536 ----
if(isset($cache['S'])){
$db['parameters'][] = "S";
// take solar radiation average
! $rawValue = array_sum($cache['S'])/count80($cache['S']);
$db['fields'][] = number_format($rawValue,1,".","");
}
}
***************
*** 1441,1447 ****
if(isset($cache['D'])){
$db['parameters'][] = "D";
// take dew point average
! $rawValue = array_sum($cache['D'])/count($cache['D']);
$db['fields'][] = number_format($rawValue,1,".","");
}
--- 1539,1545 ----
if(isset($cache['D'])){
$db['parameters'][] = "D";
// take dew point average
! $rawValue = array_sum($cache['D'])/count80($cache['D']);
$db['fields'][] = number_format($rawValue,1,".","");
}
***************
*** 1449,1466 ****
if(isset($cache['A'])){
$db['parameters'][] = "A";
// take apparent temperature average
! $rawValue = array_sum($cache['A'])/count($cache['A']);
$db['fields'][] = number_format($rawValue,1,".","");
}
// calculations
$finalExtraParams = array();
$finalExtraValues = array();
! if(count($extraSensors)>0){
foreach($extraSensors as $extraSensor){
if(isset($cache[$extraSensor])){
$finalExtraParams[] = $extraSensor;
! $thisExtraVal = array_sum($cache[$extraSensor])/count($cache[$extraSensor]);
$finalExtraValues[] = $thisExtraVal;
}
}
--- 1547,1564 ----
if(isset($cache['A'])){
$db['parameters'][] = "A";
// take apparent temperature average
! $rawValue = array_sum($cache['A'])/count80($cache['A']);
$db['fields'][] = number_format($rawValue,1,".","");
}
// calculations
$finalExtraParams = array();
$finalExtraValues = array();
! if(count80($extraSensors)>0){
foreach($extraSensors as $extraSensor){
if(isset($cache[$extraSensor])){
$finalExtraParams[] = $extraSensor;
! $thisExtraVal = array_sum($cache[$extraSensor])/count80($cache[$extraSensor]);
$finalExtraValues[] = $thisExtraVal;
}
}
***************
*** 1494,1500 ****
}
// perform query to alldataExtra if some params are available
! if(count($finalExtraParams)>0){
$finalExtraParams[] = "DateTime";
$finalExtraValues[] = "'".date("Y-m-d H:i:s",$timeForUpdate)."'";
$apiLog['info'][] = "Preparing extra sensor query...";
--- 1592,1598 ----
}
// perform query to alldataExtra if some params are available
! if(count80($finalExtraParams)>0){
$finalExtraParams[] = "DateTime";
$finalExtraValues[] = "'".date("Y-m-d H:i:s",$timeForUpdate)."'";
$apiLog['info'][] = "Preparing extra sensor query...";
***************
*** 1585,1592 ****
}
// extra sensors
! if(count($extraQueryParams)>0){
! for($j = 0; $j < count($extraQueryParams); $j++){
$cache[$extraQueryParams[$j]][] = $extraQueryValues[$j];
}
}
--- 1683,1690 ----
}
// extra sensors
! if(count80($extraQueryParams)>0){
! for($j = 0; $j < count80($extraQueryParams); $j++){
$cache[$extraQueryParams[$j]][] = $extraQueryValues[$j];
}
}
***************
*** 1661,1694 ****
}
// extra sensors
! if(isset($extraQueryParams) && is_array($extraQueryParams)){
! if(count($extraQueryParams)>0){
! for($j = 0; $j < count($extraQueryParams); $j++){
$cache[$extraQueryParams[$j]][] = $extraQueryValues[$j];
}
}
}
- }
$apiLog['info'][] = "Not yet time to update the db, saving new data to cache/apiCache.txt";
file_put_contents($base."cache/apiCache.txt",json_encode($cache));
}
// create API update log file
! $apiLog['info'][] = "Generating log file cache/apiLog.txt";
! $updateLog = "";
! foreach($apiLog['info'] as $info){
! $updateLog .= $info."\n\r";
! }
! $updateLog .= "\n\rERRORS:\n\r";
! if(isset($apiLog['error'])){
! foreach($apiLog['error'] as $error){
! $updateLog .= $error."\n\r";
! }
! }
! file_put_contents($base."cache/apiLog.txt",$updateLog);
! if($convertUgp){
! file_put_contents($base."cache/apiLogConvertUgp.txt",$updateLog);
! }
// return success status to caller
echo "Success";
--- 1759,1778 ----
}
// extra sensors
! if(count80($extraQueryParams)>0){
! for($j = 0; $j < count80($extraQueryParams); $j++){
$cache[$extraQueryParams[$j]][] = $extraQueryValues[$j];
}
}
}
$apiLog['info'][] = "Not yet time to update the db, saving new data to cache/apiCache.txt";
file_put_contents($base."cache/apiCache.txt",json_encode($cache));
}
// create API update log file
! generateLog($base, $apiLog, "apiLog.txt");
! if($convertUgp)
! {file_put_contents($base."cache/apiLogConvertUgp.txt",$updateLog);}
// return success status to caller
echo "Success";
***************
*** 1726,1745 ****
return ((rad2deg(atan2($sinSum, $cosSum)) + 360) % 360);
}
! function generateAPILog(){
! global $apiLog;
! global $base;
// create log and exit update script
! $apiLog['info'][] = "Generating log file cache/apiLog.txt";
! $updateLog = "";
! foreach($apiLog['info'] as $info){
! $updateLog .= $info."\n\r";
}
! $updateLog .= "\n\rERRORS:\n\r";
! if(isset($apiLog['error'])){
! foreach($apiLog['error'] as $error){
! $updateLog .= $error."\n\r";
! }
! }
! file_put_contents($base."cache/apiLog.txt",$updateLog);
}
--- 1810,1833 ----
return ((rad2deg(atan2($sinSum, $cosSum)) + 360) % 360);
}
! function generateLog($base, $apiLog, $fileName, $flags=false)
! {
! //global $apiLog;
! //global $base;
// create log and exit update script
! $apiLog['info'][] = "Generating log file cache/".$fileName;
! $updateLog = "\n".date("Y-m-d H:i:s")."\n";
! $updateLog .= "INFOS:\n";
! foreach($apiLog['info'] as $info)
! {$updateLog .= $info."\n";}
! if(isset($apiLog['error']))
! {
! $updateLog .= "\nERRORS:\n\r";
! foreach($apiLog['error'] as $error)
! {$updateLog .= $error."\n";}
}
! if ($flags == false)
! {file_put_contents($base."cache/".$fileName,$updateLog);}
! else
! {file_put_contents($base."cache/".$fileName,$updateLog,FILE_APPEND);}
}