Author Topic: Problems with AWN  (Read 522 times)

0 Members and 1 Guest are viewing this topic.

Offline hkson2005

  • Member
  • *
  • Posts: 2
Problems with AWN
« on: May 19, 2021, 04:43:13 AM »
http://weatherhk.org/pws/saratoga/wxindex.php
I have recently bought and set up an Ambient Weather station at home, and I have an account on ambientweather.net. So the WXsoftware should be AWN. I have used the template to produce the above webpage. Currently, I have encountered the following problems and they remain unsolved:
1. Notice: Undefined index: location in /var/www/domains/weatherhk.org/public_html/pws/saratoga/AWNtags.php on line 155. (The "location" of my device shown on ambientweather.net is in Chinese, is it the reason causing this error?)
2. The date cannot be loaded. Instead, the above error message is shown where the date is expected.
3. The thermometer cannot be shown. The image is broken, but the temperatures can be loaded. If I view thermometer.php, only a small blank grey square appears instead of a thermometer image. I have checked the FAQ already and all the files should start with <?php . And the thermometer-blank.png is also in the same directory and it can be loaded normally.
4. At the top grey bar, it shows " -17.2°C/hr" next to the current temperature, which is unreasonable.
5. Frequently the data does not update automatically. "Updates paused - reload page to start" is shown.
6. I do not quite understand  the part of capturing yesterday data as shown on  https://saratoga-weather.org/wxtemplates/Settings-config-AWN.php. It tells us to edit the cron-yday.txt. What should I edit? I found that the cron-yday.txt I downloaded from the AWN plugin is a little bit different from the script shown. Does it matter? How can I set cron to run the script? (Sorry I do not have any knowledge in Linux  :sad:)
7. Can I customize the description next to the temperature (e.g. Hot, Extremely Hot)? I want to change it according to our local definitions.

I would be grateful if anyone knows how to solve the above problems.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9288
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Problems with AWN
« Reply #1 on: May 19, 2021, 01:37:08 PM »
Welcome to the forum, and you are the first one (that I'm aware of) to use the template in Hong Kong.

1) the Undefined error in line 155 in AWNtags.php is likely the cause of (2) (3) and (4) also.  Try changing AWNtags.php
Code: [Select]
$t = trim($d['info']['name'])."\t".trim($d['info']['location']);
to
Code: [Select]
$t = trim($d['info']['name'])."\t".@trim($d['info']['location']);
to suppress that Notice error.  That should fix the thermometer.php and date display at the same time.

For (5), that's a setting in ajaxAWNwx.js that turns off updates after a set number of times.  In ajaxAWNwx.js, change
Code: [Select]
var maxupdates = 10;          // Maxium Number of updates allowed (set to zero for unlimited)
to
Code: [Select]
var maxupdates = 0;          // Maxium Number of updates allowed (set to zero for unlimited)
to have no automatic timeout of updates.

for (6), the exact requirements for the cron-yday.txt shell script depend heavily on your specific *nix server configuration.  Specifically, the filesystem locations for your document root and for the PHP interpreter.  Fortunately, the check-fetch-times.php?show=info reveals both:
Quote
PHP cmd location: /usr/bin/php
Document root: /var/www/domains/weatherhk.org/public_html
Template root: /var/www/domains/weatherhk.org/public_html/pws/saratoga
so the start of the cron-yday.txt file should read
Code: [Select]
# --- begin settings
HDIR="/var/www/domains/weatherhk.org/public_html/pws/saratoga"
SCRIPT=saveYesterday.php
URL="http://weatherhk.org/pws/saratoga/$SCRIPT"
PHPcmd=/usr/bin/php
CURLcmd=/usr/bin/curl
USECMD=PHP
#USECMD=CURL
# --- end settings
Remember that the cron-yday.txt file must use Unix line endings (NL or \n or x0A) and NOT Windows line endings (CRNL or \r\n or x0D0A).  If you're using Windows to edit the file, use Notepad++ and you can easily change line endings from \r\n to \n before you upload.
Your webhoster should have a control panel for your website that has a cron configuration menu .. use that after you've uploaded the cron-yday.txt as modified.

for (7), the descriptions are not easily customizable and are based in two places ajax-dashboard.php (in PHP) and ajaxAWNwx.js (JavaScript).

I hope this helps, and thanks for trying the Saratoga template with Ambientweather.net

Best regards,
Ken

Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline hkson2005

  • Member
  • *
  • Posts: 2
Re: Problems with AWN
« Reply #2 on: May 20, 2021, 09:56:05 AM »
Welcome to the forum, and you are the first one (that I'm aware of) to use the template in Hong Kong.

1) the Undefined error in line 155 in AWNtags.php is likely the cause of (2) (3) and (4) also.  Try changing AWNtags.php
Code: [Select]
$t = trim($d['info']['name'])."\t".trim($d['info']['location']);
to
Code: [Select]
$t = trim($d['info']['name'])."\t".@trim($d['info']['location']);
to suppress that Notice error.  That should fix the thermometer.php and date display at the same time.

For (5), that's a setting in ajaxAWNwx.js that turns off updates after a set number of times.  In ajaxAWNwx.js, change
Code: [Select]
var maxupdates = 10;          // Maxium Number of updates allowed (set to zero for unlimited)
to
Code: [Select]
var maxupdates = 0;          // Maxium Number of updates allowed (set to zero for unlimited)
to have no automatic timeout of updates.

for (6), the exact requirements for the cron-yday.txt shell script depend heavily on your specific *nix server configuration.  Specifically, the filesystem locations for your document root and for the PHP interpreter.  Fortunately, the check-fetch-times.php?show=info reveals both:
Quote
PHP cmd location: /usr/bin/php
Document root: /var/www/domains/weatherhk.org/public_html
Template root: /var/www/domains/weatherhk.org/public_html/pws/saratoga
so the start of the cron-yday.txt file should read
Code: [Select]
# --- begin settings
HDIR="/var/www/domains/weatherhk.org/public_html/pws/saratoga"
SCRIPT=saveYesterday.php
URL="http://weatherhk.org/pws/saratoga/$SCRIPT"
PHPcmd=/usr/bin/php
CURLcmd=/usr/bin/curl
USECMD=PHP
#USECMD=CURL
# --- end settings
Remember that the cron-yday.txt file must use Unix line endings (NL or \n or x0A) and NOT Windows line endings (CRNL or \r\n or x0D0A).  If you're using Windows to edit the file, use Notepad++ and you can easily change line endings from \r\n to \n before you upload.
Your webhoster should have a control panel for your website that has a cron configuration menu .. use that after you've uploaded the cron-yday.txt as modified.

for (7), the descriptions are not easily customizable and are based in two places ajax-dashboard.php (in PHP) and ajaxAWNwx.js (JavaScript).

I hope this helps, and thanks for trying the Saratoga template with Ambientweather.net

Best regards,
Ken
My pleasure to be the first one  :grin: I appreciate your great effort in making this sophisticated and professional template for us to use!  [tup]
Thanks for your quick and helpful reply. I tried to add the @ in AWNtags.php, it successfully solves problems 1,2,3. Awesome!
However, problem 4 still exists. Today I saw a more ridiculous number -19.3°C/hr ...
For problem 5, I have updated the maxupdates to be 0, but still the update paused after a while and requires reloading the page... Any ideas what's happening?

For problem 6, thank you for helping me to identify the paths. I have set up the cronjob just now, and will know whether it works at 23:58 tonight. 2 more hours to wait!

For problem 7, I have found the langHeatWords in ajaxAWNwx.js and tried to change the if-else statements in the heatColor function, but couldn't make it work. You mentioned the descriptions are also based on ajax-dashboard.php. I found the following code which should be relevant
Code: [Select]
<span class="ajax" id="ajaxheatcolorword">
                    <?php  langtrans($heatcolourword); ?></span>
, but don't know how to edit. It seems that $heatcolourword only appears once in this PHP file?

One more question... Ambientweather.net shows the maximum temp today is 34.1C at 3:19pm while Saratoga is only 33.9C at 3:45pm. I observe that the max/min values (including temperatures, wind, UV, solar radiation) are only captured every 5 minutes at xx:x5 or xx:x0, so it cannot capture the actual max/min values which happen between the 5 minutes. Is it possible to change the frequency in order to capture the actual max/min?
« Last Edit: May 20, 2021, 10:17:31 AM by hkson2005 »

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9288
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Problems with AWN
« Reply #3 on: May 20, 2021, 05:08:39 PM »
For the (5) the updates issue, I see that ajaxAWNwx.js has maxupdates =0; in the script.  You may need to shift-reload the page to get the Javascript refreshed in your browser. 

For (4) the unreasonable hour change display, it relies on $tempchangehour value.  That value is set in AWN-defs.php by
Code: [Select]
if(isset($WX['outsideTempChg1hr'])) {$tempchangehour = $WX['outsideTempChg1hr']; }
and $WX['outsideTempChg1hr'] is set in AWNtags.php by
Code: [Select]
if(isset($JSON[11]->tempf) and isset($cjson->tempf)) {
$WX['outsideTempChg1hr'] = AWN_convertTemp($cjson->tempf - $JSON[11]->tempf,'F',$uomTemp);
if($doDebug) {
echo "<!-- AWN_getTrends temp chg 1hr: '".$WX['outsideTempChg1hr']."' $uomTemp -->\n";
}
}
and looking at a view-source of AWNtags.php?sce=dump shows
Quote
<!-- AWN_convertTemp temperature: 0.40000000000001 , unitFrom: F ,unitTo: &deg;C, out = -17.6 -->
<!-- AWN_getTrends temp chg 1hr: '-17.6' &deg;C -->
so the actual temp change was only 0.4 degrees F.  D'Oh.. my bad.  Change the line in AWNtags.php
Code: [Select]
$WX['outsideTempChg1hr'] = AWN_convertTemp($cjson->tempf - $JSON[11]->tempf,'F',$uomTemp); to
Code: [Select]
$WX['outsideTempChg1hr'] = AWN_convertTemp($cjson->tempf,'F',$uomTemp) -
AWN_convertTemp($JSON[11]->tempf,'F',$uomTemp);
and that should fix the issue.

Hopefully, your (6) cron will work fine and yesterday data will be captured for display tomorrow.

For (7), the $heatcolourword is actually done in AWN-defs.php by code
Code: [Select]
list($feelslike,$heatcolourword) = WL_setFeelslike ($temperature,$windch,$heati,$uomtemp);
with the WL_setFeelslike function
Code: [Select]
#-------------------------------------------------------------------------------------
# WL support function - WL_setFeelslike
#-------------------------------------------------------------------------------------


function WL_setFeelslike ($temp,$windchill,$heatindex,$tempUOM) {
global $Debug;
// establish the feelslike temperature and return a word describing how it feels

$HeatWords = array(
 'Unknown', 'Extreme Heat Danger', 'Heat Danger', 'Extreme Heat Caution', 'Extremely Hot', 'Uncomfortably Hot',
 'Hot', 'Warm', 'Comfortable', 'Cool', 'Cold', 'Uncomfortably Cold', 'Very Cold', 'Extreme Cold' );

// first convert all temperatures to Centigrade if need be
  $TC = $temp;
  $WC = $windchill;
  $HC = $heatindex;
 
  if (preg_match('|F|i',$tempUOM))  { // convert F to C if need be
$TC = sprintf("%01.1f",round(($TC-32.0) / 1.8,1));
$WC = sprintf("%01.1f",round(($WC-32.0) / 1.8,1));
$HC = sprintf("%01.1f",round(($HC-32.0) / 1.8,1));
  }
 
 // Feelslike
 
  if ($TC <= 16.0 ) {
$feelslike = $WC; //use WindChill
  } elseif ($TC >=27.0) {
$feelslike = $HC; //use HeatIndex
  } else {
$feelslike = $TC;   // use temperature
  }

  if (preg_match('|F|i',$tempUOM))  { // convert C back to F if need be
$feelslike = (1.8 * $feelslike) + 32.0;
  }
  $feelslike = round($feelslike,0);

// determine the 'heat color word' to use 
 $hcWord = $HeatWords[0];
 $hcFound = false;
 if ($TC > 32 and $HC > 29) {
if ($HC > 54 and ! $hcFound) { $hcWord = $HeatWords[1]; $hcFound = true;}
if ($HC > 45 and ! $hcFound) { $hcWord = $HeatWords[2]; $hcFound = true; }
if ($HC > 39 and ! $hcFound) { $hcWord = $HeatWords[4]; $hcFound = true; }
if ($HC > 29 and ! $hcFound) { $hcWord = $HeatWords[6]; $hcFound = true; }
 } elseif ($WC < 16 ) {
if ($WC < -18 and ! $hcFound) { $hcWord = $HeatWords[13]; $hcFound = true; }
if ($WC < -9 and ! $hcFound)  { $hcWord = $HeatWords[12]; $hcFound = true; }
if ($WC < -1 and ! $hcFound)  { $hcWord = $HeatWords[11]; $hcFound = true; }
if ($WC < 8 and ! $hcFound)   { $hcWord = $HeatWords[10]; $hcFound = true; }
if ($WC < 16 and ! $hcFound)  { $hcWord = $HeatWords[9]; $hcFound = true; }
 } elseif ($WC >= 16 and $TC <= 32) {
if ($TC <= 26 and ! $hcFound) { $hcWord = $HeatWords[8]; $hcFound = true; }
if ($TC <= 32 and ! $hcFound) { $hcWord = $HeatWords[7]; $hcFound = true; }
 }

 if(isset($_REQUEST['debug'])) {
  echo "<!-- WL_setFeelslike input T,WC,HI,U='$temp,$windchill,$heatindex,$tempUOM' cnvt T,WC,HI='$TC,$WC,$HC' feelslike=$feelslike hcWord=$hcWord -->\n";
 }

 return(array($feelslike,$hcWord));

} // end of WL_setFeelslike
  the ajaxAWNwx.js and AWN-defs.php have the words in the same orderings for conditions.

For the final question about conditions, ambientweather.net only has a 5-minute granularity of observations and no actual min-max data available outside those 5 minute 'chunks'.  The frequency can't be changed (AFAIK), so we're stuck with the instant observation at each time period (and not know the total min/max information.. sorry.



Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

 

anything