API upload fails after DST change

Post Reply
danb35
Observer
Observer
Posts: 20
Joined: Sat Jan 20, 2018 4:14 pm
Station model: Davis Pro 2
Software: WeeWX

API upload fails after DST change

Post by danb35 » Mon Nov 03, 2025 1:23 pm

My Meteotemplate 19 system has been up and running for a few months now without major problems--until early Sunday morning (2:00 EST), when the idiotic Daylight Savings Time ended for the year in .us. At that time, updates via the API from WeeWx began failing with "500 Internal Server Error" in the logs.

Nothing in the server or WeeWx logs gave any further error message; the only thing shown in my server log was:

Code: Select all

2025-11-03T07:09:31-05:00 [1:lamp1:apache2-app] 172.69.208.133 - - [03/Nov/2025:12:09:31 +0000] "GET /template/api.php?PASS=(redacted)&U=1762171119&SW=weewx-5.1.0&T=9.67&H=88.0&P=1021.436&UGP=1020.511&W=0.00&G=0.00&RR=0.000&R=0.000&TIN=24.00&HIN=49.0&TXBAT=0 HTTP/1.1" 500 217 "-" "weewx/5.1.0"
Suspecting this might resulting from trying to overwrite database entries (since rows in alldata appear to use local time as a time stamp), I deleted the rows from that table between 1:00 am and 1:59 am, and restarted WeeWx. Still getting the same result.

The wiki (https://www.meteotemplate.com/web/wiki/wiki8GB.php) says there's a debugging mode I can enable from setup.php, but I don't see any mention of "debug" anywhere on that page or in config.php.

Still trying to figure out what the actual error is, I edited .htaccess to include "php_flag display_errors On". And surprisingly, that changed the result. It didn't display any errors, but it did return a 200 status code for the update attempt:

Code: Select all

2025-11-03T07:55:37-05:00 [1:lamp1:apache2-app] 172.69.208.133 - - [03/Nov/2025:12:55:37 +0000] "GET /template/api.php?PASS=(redacted)&U=1762174536&SW=weewx-5.1.0&T=9.83&H=88.0&P=1022.181&UGP=1021.256&W=0.00&G=0.00&RR=0.000&R=0.000&TIN=23.83&HIN=49.0&TXBAT=0 HTTP/1.1" 200 179 "-" "weewx/5.1.0"
A status code of 200 should indicate success, but the update is still failing; WeeWx is now logging this error:

Code: Select all

Failed to publish record 2025-11-03 07:57:53 EST (1762174673): Server returned ''
If I turn off display_errors, Meteotemplate goes back to returning an internal server error.

If I look at the template directory, I see that meteotemplateLive.txt has a modification date of 07:16 UTC 2 Nov, which would be 02:16 EST, or 16 minutes after the change. That's not exactly the time this started, but close enough that I'm suspicious.

Environment is Linux/Apache/PHP 8.3.19

Where should I be looking, or what should I be changing, to try to sort out what's going on here?

danb35
Observer
Observer
Posts: 20
Joined: Sat Jan 20, 2018 4:14 pm
Station model: Davis Pro 2
Software: WeeWX

Re: API upload fails after DST change

Post by danb35 » Sat Nov 08, 2025 11:42 am

This has been up for almost a week with nearly 400 views; it's kind of discouraging to see no replies at all.

I figured that if the API updates were broken (and giving no clue why), I'd try updating via Weather Underground, since I also report there. Going to the control panel, setting the update method to Weather Underground, and entering my station ID went without incident, and when I clicked the Test button it appeared to work, returning a new tab with:
Update Test
Update type tested: Weather Underground

Loading data from weatherunderground.com for station: KGARICHM14...
I don't know if that indicates success or not, but it doesn't update anything on my main page.

The page then tells me I need to set up a cron job for a URL. Well, URLs aren't cron jobs, but I figured I'm supposed to GET that URL on a schedule, e.g., with curl.

Code: Select all

root@lamp:/app/template/update# curl "https://wx.familybrown.org/template/update/update.php?password=(redacted)"
<br />
<b>Fatal error</b>:  Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in /app/template/api.php:164
Stack trace:
#0 /app/template/update/update.php(451): include_once()
#1 {main}
  thrown in <b>/app/template/api.php</b> on line <b>164</b><br />
So updating this way still goes through the API. Makes sense from a software design standpoint, but it also means that a different update method isn't going to get me around whatever the problem is with the API now. But at least I have an error message now. But that message doesn't do much to help me understand where the problem is. Here's the section of api.php containing line 164 (that's the if(array_key_exists line):

Code: Select all

    if(file_exists($base."meteotemplateLive.txt")){
        // get latest date from cache file
        $mtLive = file_get_contents($base."meteotemplateLive.txt");
        $liveInput = json_decode($mtLive,true);

        if(array_key_exists("R".$timeId,$liveInput)){ // check if rain is from yesterday, if so, delete it
            $dayRain = date("Ymd",$liveInput['R'.$timeId]);
            $dayNow = date("Ymd");
            if($dayRain!=$dayNow){
                unset($liveInput['R']);
                unset($liveInput['RTime']);
            }
        }
I also see references throughout api.php to an $apiLog array, but not where that's saved. That might help sort out what's going on--does anyone know where it would be?

User avatar
lemimi
Forecaster
Forecaster
Posts: 105
Joined: Wed Dec 12, 2018 3:31 pm
Location: France - Normandie
Station model: Brandson 304557
Contact:

Re: API upload fails after DST change

Post by lemimi » Sun Nov 09, 2025 11:16 am

Hello,

Maybe you should try asking an AI (like ChatGPT, for example) and request an explanation for your Fatal error.
Be sure to mention that your website is based on MeteoTemplate (https://www.meteotemplate.com/web/index.php
) and specify which PHP version you’re using.

I asked about it myself (in French) and got some answers, but I think if you do it directly, the responses will be more relevant to your setup.

I also noticed some other errors when visiting:
https://wx.familybrown.org/template/ind ... php?errors

Good luck…
Lemimi

* One idea... Since your MeteoTemplate seems to be outdated for PHP 8, if you can, try reverting to PHP 7... if you can.

danb35
Observer
Observer
Posts: 20
Joined: Sat Jan 20, 2018 4:14 pm
Station model: Davis Pro 2
Software: WeeWX

Re: API upload fails after DST change

Post by danb35 » Sun Nov 09, 2025 11:22 pm

* One idea... Since your MeteoTemplate seems to be outdated for PHP 8, if you can, try reverting to PHP 7... if you can.
I don't believe that's an option, unfortunately. I really wish the PHP devs understood backward compatibility. Is there a Meteotemplate that isn't outdated for PHP 8? I thought 19.0 was the latest.

I'll see what ChatGPT can suggest.

danb35
Observer
Observer
Posts: 20
Joined: Sat Jan 20, 2018 4:14 pm
Station model: Davis Pro 2
Software: WeeWX

Re: API upload fails after DST change

Post by danb35 » Thu Nov 20, 2025 10:14 pm

I'd still like to know if there's a version that actually supports PHP8, since 7.4 has been EOL for over 3 years now. But changing to run on PHP 7.4 seems to have resolved the issue.

FSC830
Forecaster
Forecaster
Posts: 191
Joined: Thu Aug 02, 2018 11:40 am
Station model: Davis Vantage Pro2
Software: Meteobridge

Re: API upload fails after DST change

Post by FSC830 » Fri Nov 21, 2025 3:29 am

Actually Meteotemplate 19.0 is modified for PHP8.x, unfortunately it still contains some files with not modified code :? .
Currently I am using PHP 8.3 at my site without any issue, but I modified the files I am using by myself.

Regards

P.S. Later or at weekend I will attach my API.PHP here so you can check if this resolves your issue.

Here it is, at least at my site it runs perfect. But even if API.PHP do not through any errors anymore, may other files at your site still not compatible.
api.zip
(11.84 KiB) Downloaded 190 times
Image

danb35
Observer
Observer
Posts: 20
Joined: Sat Jan 20, 2018 4:14 pm
Station model: Davis Pro 2
Software: WeeWX

Re: API upload fails after DST change

Post by danb35 » Sat Nov 22, 2025 11:30 pm

So here's the diff between the original api.php and this updated one:

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);}
          }

FSC830
Forecaster
Forecaster
Posts: 191
Joined: Thu Aug 02, 2018 11:40 am
Station model: Davis Vantage Pro2
Software: Meteobridge

Re: API upload fails after DST change

Post by FSC830 » Sun Nov 23, 2025 5:45 am

And does it works at your site?

Regards
Image

Post Reply