Author Topic: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available  (Read 10135 times)

0 Members and 1 Guest are viewing this topic.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Saratoga templates use get-USNO-sunmoon.php to gather sun/moon data for display on the ajax-dashboard and wxastronomy.php pages (for all weather software except Weather-Display).

The US Naval Observatory has announced they will discontinue providing the data in the way used by V1.x of the script after July 31, 2015 and instead are offering a JSON feed of the data.  The V2.00 version of the script now uses the new JSON feed from them.

Template users: use the update tool with a query of (Base-*, Plugin-*, 29-Jul-2015) to get the updated script.

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 ValentineWeather

  • Forecaster
  • *****
  • Posts: 6368
    • Valentine Nebraska's Real-Time Weather
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #1 on: July 29, 2015, 11:27:21 AM »
Thanks once again Ken.  =D>
Randy

Offline wvdkuil

  • Wim van der kuil
  • Forecaster
  • *****
  • Posts: 1986
    • My PWS at Leuven Belgium Europe
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #2 on: July 29, 2015, 11:38:38 AM »
Thanks Ken for bringing this to our attention.

As there is no other source for moon-data when using some weather-programs, there are different scripts using the now nearly obsolete post-script.

For users having their own scripts, the API can be found at:   http://aa.usno.navy.mil/data/docs/api.php

Wim

Offline ValentineWeather

  • Forecaster
  • *****
  • Posts: 6368
    • Valentine Nebraska's Real-Time Weather
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #3 on: July 29, 2015, 11:43:07 AM »
Some may need to change cell padding with the new advforecast2.php line 1105, my web page is custom wider so went with 4. 
Code: [Select]
      <td align="center">&nbsp;
            <table width="100%" border="0" cellpadding="4" cellspacing="0">
              <tr valign ="top" align="center">
Randy

Offline McLouthWX

  • Member
  • *
  • Posts: 41
    • Jefferson County Weather Live
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #4 on: July 29, 2015, 06:07:51 PM »
Thanks, again, Ken, for your tireless efforts. A small token of appreciation for your work is headed your way via Pay Pal
Ken
If you aren't confused, then you weren't paying attention.

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 949
    • LexMAWeather
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #5 on: July 29, 2015, 08:07:08 PM »
I seem to have gummed something up...

I'm getting errors on the foreach() statements:

   foreach ($MoonJSON['sundata'] as $n => $d) {
   
   foreach ($MoonJSON['moondata'] as $n => $d) {
   
   foreach ($MoonJSON['nextmoondata'] as $n => $d) {
   
Warning: Invalid argument supplied for foreach() in [path]/get-USNO-sunmoon.php on line 340

Warning: Invalid argument supplied for foreach() in [path]/get-USNO-sunmoon.php on line 349

Warning: Invalid argument supplied for foreach() in [path]/get-USNO-sunmoon.php on line 356

PHP version thing? I'm running 5.3.29.
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #6 on: July 29, 2015, 08:16:25 PM »
After install, you may need to run wxastronomy.php?force=1 to fetch the new JSON cache file .. or let it sit an hour and the refresh will be automatic.

Thanks, again, Ken, for your tireless efforts. A small token of appreciation for your work is headed your way via Pay Pal
Ken
Thank you for your kind donation!
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 Jasiu

  • Forecaster
  • *****
  • Posts: 949
    • LexMAWeather
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #7 on: July 29, 2015, 08:37:34 PM »
After install, you may need to run wxastronomy.php?force=1 to fetch the new JSON cache file .. or let it sit an hour and the refresh will be automatic.

Thanks - the force cleared up the first two but not the reference to the 'nextmoondata' element.
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #8 on: July 29, 2015, 08:39:18 PM »
URL to your website is...?
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 Jasiu

  • Forecaster
  • *****
  • Posts: 949
    • LexMAWeather
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #9 on: July 29, 2015, 09:16:13 PM »
I have a sandbox where I've reproduced the error:

http://jjwebsites.com/wx

Thanks a lot!
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline SteveFitz1

  • Forecaster
  • *****
  • Posts: 521
    • Tyler Texas Weather
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #10 on: July 29, 2015, 09:16:52 PM »
Ken,

I'm seeing a similar error as Jasiu even after the force=1 : Warning: Invalid argument supplied for foreach() in /home/user/tylertexasweather.com/get-USNO-sunmoon.php on line 346

My URL is http://tylertexasweather.com/almanac.htm .

Thanks,

Steve
« Last Edit: July 29, 2015, 11:21:42 PM by SteveFitz1 »

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #11 on: July 29, 2015, 10:14:03 PM »
Got it... and fixed in V2.01

It seems that the next/prior moon data are not always present in the JSON feed.  Today, the prior was there, the next was not.

The script has been updated to handle both (without generating a warning message).

Please download again (same 29-Jul-2015 query on the update tool page).

Thanks for spotting the error!
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 Jasiu

  • Forecaster
  • *****
  • Posts: 949
    • LexMAWeather
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #12 on: July 29, 2015, 10:46:55 PM »
Thank YOU, Ken!  I also need to pony up with a donation - will do that soon!
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline SteveFitz1

  • Forecaster
  • *****
  • Posts: 521
    • Tyler Texas Weather
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #13 on: July 29, 2015, 10:56:21 PM »
Ken,

That took care of the error. Thanks for the quick response.

Steve

Offline PaulMy

  • Forecaster
  • *****
  • Posts: 5519
    • KomokaWeather
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #14 on: July 29, 2015, 11:03:30 PM »
I have also updated to v2.01 and looks fine.  Thanks Ken for your continued monitoring and keeping things up to date for us.

Paul

Offline BCJKiwi

  • Forecaster
  • *****
  • Posts: 302
    • Silver Acorn Weather - N.Z.
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #15 on: July 30, 2015, 11:57:14 PM »
A couple of Undefined indexes;

Our USNO-moondata.txt cached file:-
Code: [Select]
HTTP/1.1 200 OK
Date: Fri, 31 Jul 2015 02:50:56 GMT
Server: Apache
Access-Control-Allow-Origin: *
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

2ee
{
      "error":false,
      "apiversion":"1.0",
      "year":2015,
      "month":7,
      "day":31,"datechanged":false,
      "lon":174.77,
      "lat":-36.91,
      "tz":12,
     
   "sundata":[
   
            {"phen":"BC", "time":"06:53"},
            {"phen":"R", "time":"07:21"},
            {"phen":"U", "time":"12:27"},
            {"phen":"S", "time":"17:34"},
            {"phen":"EC", "time":"18:02"}
            ],
            "moondata":[
           
            {"phen":"S", "time":"06:35"},
            {"phen":"R", "time":"17:25"} ] , "nextmoondata": [ {"phen":"U","time":"00:27"}, {"phen":"S","time":"07:22"}]
      , "closestphase":{
         "phase":"Full Moon",
         "date":"July 31, 2015",
         "time":"22:43"
      } }
0
Undefined index curphase
and
Undefined index fraxcillum

We currently have a "Full Moon" and the there is no curphase or fracillum value in the cached file.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #16 on: July 31, 2015, 12:36:02 AM »
Ok, that is weird.. I have
Code: [Select]
{
      "error":false,
      "apiversion":"1.0",
      "year":2015,
      "month":7,
      "day":31,"datechanged":false,
      "lon":-122.02,
      "lat":37.27,
      "tz":-7,
     
   "sundata":[
   
            {"phen":"BC", "time":"05:43"},
            {"phen":"R", "time":"06:12"},
            {"phen":"U", "time":"13:14"},
            {"phen":"S", "time":"20:17"},
            {"phen":"EC", "time":"20:46"}
            ],
            "moondata":[
           
            {"phen":"U", "time":"01:04"},
            {"phen":"S", "time":"06:32"},
            {"phen":"R", "time":"20:26"} ]
               , "prevmoondata":[{"phen":"R","time":"19:40"}]
      , "closestphase":{
         "phase":"Full Moon",
         "date":"July 31, 2015",
         "time":"03:43"
      } }
which is also missing the two items.  Go figure.. USNO should not mess about with the JSON feed.

Their page (driven by the feed, they allege) shows
Quote
Saratoga, Santa Clara County, CA (Longitude W122° 1', Latitude N37° 16')
July 31, 2015    Pacific Daylight Time
Sun
Begin civil twilight   5:43 a.m.
Sunrise   6:12 a.m.
Sun transit   1:14 p.m.
Sunset   8:17 p.m.
End civil twilight   8:46 p.m.
Moon
Moonrise   7:40 p.m. on preceding day
Moon transit   1:04 a.m.
Moonset   6:32 a.m.
Moonrise   8:26 p.m.

Phase of the Moon on July 31, 2015: Full Moon at 3:43 a.m. (local daylight time)

So.. I guess a 2.02 version will be out tomorrow (31-Jul-2015).

Thanks for spotting the issue :)

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 wvdkuil

  • Wim van der kuil
  • Forecaster
  • *****
  • Posts: 1986
    • My PWS at Leuven Belgium Europe
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #17 on: July 31, 2015, 02:46:36 AM »
As today is the day of the closest moon phase those two fields are missing "by design"
Code: [Select]
"closestphase":{ "phase":"Full Moon", "date":"July 31, 2015","time":"06:43"}
Their API now (?) reads for the two missing fields:
Quote
  • "fracillum," which is the fraction of the Moon's apparent surface which is lit (if "closestphase" occurs on date requested, "fracillum" will not be in JSON)
  • "curphase," which is the phase of the Moon on the date requested (if "closestphase" occurs on date requested, "curphase" will not be in JSON)
I do not remember that this (italic) text was in the API description before yesterday, or my old eys/brain is getting lazy.

Wim

Offline BCJKiwi

  • Forecaster
  • *****
  • Posts: 302
    • Silver Acorn Weather - N.Z.
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #18 on: July 31, 2015, 06:37:00 AM »
OK,

Anyhow, the old feed is still working for me so have reverted to that for now.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #19 on: July 31, 2015, 11:56:23 AM »
Ok, got at 2.02 version up on the distribution.

It adds some code to check for missing fracillum/curphase data.  If the "closestphase"/"phase" is present, it is used as the output 'moonphase'.  If 'fracillum' is missing, there's no alternate source for percent illumination, so the output data will be missing that value.

Thanks Wim for the highlight about how that works in the API.. I must have missed the fine print about that.
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 wvdkuil

  • Wim van der kuil
  • Forecaster
  • *****
  • Posts: 1986
    • My PWS at Leuven Belgium Europe
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #20 on: July 31, 2015, 12:02:26 PM »
Ok, got at 2.02 version up on the distribution.

It adds some code to check for missing fracillum/curphase data.  If the "closestphase"/"phase" is present, it is used as the output 'moonphase'.  If 'fracillum' is missing, there's no alternate source for percent illumination, so the output data will be missing that value.

Thanks Wim for the highlight about how that works in the API.. I must have missed the fine print about that.
I think that print was extremely small,  as I did not see it either.
For  illumination, I added a test for the four phases and use for now:  0% for newmoon,  100% for fullmoon and 50% for the other two phases.

Wim

Offline BCJKiwi

  • Forecaster
  • *****
  • Posts: 302
    • Silver Acorn Weather - N.Z.
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #21 on: August 01, 2015, 12:51:21 AM »
It took somewhere between 9.5 and 12 hours for USNO data to update from the day before's data thus finally achieving a datafile with curphase and fracillum.

It also started to provide transit correctly. Before that my output script was showing the moon transit of 00:27 1 Aug 2015 as happening on the 2 Aug. As this output script is set up to display prior, current and next day data which did require some "finessing" of duplicate transit data.
However, now that the source is OK, the transit is as well.

While this was going on I was generating (once the webserver stopped complaining about undefined indexes) correct phase and illumination output - presumably from that generated by common.php

So the temporary fix I applied was to simply rem out the curphase and fracillum lines in get-USNO-sunmoon.php

Have now implemented v2.02 so will be interesting to see if the feed gets more timely and if there are any other funny things with it over the next month.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #22 on: August 01, 2015, 01:08:02 PM »
Ok, last change (I hope) with V2.03 01-Aug-2015:

I added Wim's suggestion to default the Illumination values when the fracillum is missing from the JSON (along with 'curphase') such as happened with yesterday's Full Moon.  The update now sets illumination as follows:

'New Moon' -> 0%
'First/Last Quarter' -> 50%
'Full Moon' -> 100%

We'll see if it all works as planned on the Last Quarter moon expected on 06 Aug 2015, and the New Moon on 14 Aug 2015.
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 jay_hoehn

  • WxElement panel
  • Forecaster
  • *****
  • Posts: 656
    • Jay's Woodcrafts
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #23 on: August 02, 2015, 02:44:32 PM »
Ken,  Trying to figure this out.  My friend Andy installed this update and now can't get his index page to load.  It stops before the ajax-dashboard.  There is also this error on the wxastronomy page after force update.
Quote
Fatal error: Call to undefined function json_last_error() in /home/content/35/6589235/html/thompsonfarms/get-USNO-sunmoon.php on line 584

If I delete the get-USNO-sunmoon.php file then the page works.

Here is the URL

http://www.madeliasliveweather.com/thompsonfarms/

Any help is appreciated

Thanks,

Jay
Davis Vantage Pro2 Plus
VVP
Weather Display


Offline wvdkuil

  • Wim van der kuil
  • Forecaster
  • *****
  • Posts: 1986
    • My PWS at Leuven Belgium Europe
Re: USNO changes API to JSON.. get-USNO-sunmoon.php V2.00 available
« Reply #24 on: August 02, 2015, 02:51:14 PM »
Ken,  Trying to figure this out.  My friend Andy installed this update and now can't get his index page to load.  It stops before the ajax-dashboard.  There is also this error on the wxastronomy page after force update.
Quote
Fatal error: Call to undefined function json_last_error() in /home/content/35/6589235/html/thompsonfarms/get-USNO-sunmoon.php on line 584

If I delete the get-USNO-sunmoon.php file then the page works.

Here is the URL

http://www.madeliasliveweather.com/thompsonfarms/

Any help is appreciated

Thanks,

Jay
For the json functions, at least level 5.4 of PHP is needed.
So upgrading to that php level will solve both issues.
Wim