Author Topic: Notice: Undefined index:  (Read 544 times)

0 Members and 1 Guest are viewing this topic.

Offline yamiacaveman

  • Forecaster
  • *****
  • Posts: 412
    • Penn Lake Weather
Notice: Undefined index:
« on: September 21, 2020, 06:35:22 AM »
pennlake.us

This happens if you go to pennlake.us  -- Forecast - then Select Richfield Springs.

Not at all sure what is happening.

Thanks for any help.

yamiacaveman

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 929
    • LexMAWeather
Re: Notice: Undefined index:
« Reply #1 on: September 21, 2020, 11:17:24 AM »
Two problems here, but one fix should get you going again.  Doing a view-source:http://pennlake.us/wxforecast.php?z=1 helps to debug these things.

1) The call to fetch the meta data is failing.

Code: [Select]
!-- advforecast2.php (JSON) - V5.17 - 15-Jul-2020 on PHP 7.3.22-->
<!-- RAW NWS URL: http://forecast.weather.gov/MapClick.php?lat=42.8534&lon=-74.9854&unit=0&lg=english&FcstType=text&TextType=2  zone=NYC043 -->
<!-- meta info re: point='42.8534,-74.9854' zone='zones' metacache= './cache/forecast-NYC043-1-geojson-meta.txt' -->
<!-- metaZoneURL='https://api.weather.gov/zones/forecast/NYC043' -->
<!-- meta cache ./cache/forecast-NYC043-1-geojson-meta.txt age=4:47:23 h:m:s -->
<!-- loaded meta info from ./cache/forecast-NYC043-1-geojson-meta.txt age=4:47:23 h:m:s -->
<!-- getting metadata for forecast zone from https://api.weather.gov/zones/forecast/NYC043 -->
<!-- logged 'Fetch fail' to './cache/advforecast2-log-2020-09-21.txt' -->
<!-- curl fetching 'https://api.weather.gov/zones/forecast/NYC043' -->
<!-- HTTP stats:  RC=404 dest=184.84.228.8 port=443 (from sce=173.230.251.210)
      Times: dns=0.029 conn=0.039 pxfer=0.077 get=0.119 total=0.196 secs -->
<!-- headers returned:
HTTP/2 404
server: nginx/1.16.1
content-type: application/problem+json
access-control-allow-origin: *
access-control-allow-headers: Feature-Flags
x-request-id: 1f87c9f5-ba1c-4e7f-bf1e-446f6d7663bd
x-correlation-id: 1e934810
x-server-id: vm-bldr-nids-apiapp5.ncep.noaa.gov
pragma: no-cache
content-length: 264
x-akamai-request-id: 1e934810.b59f7ae
cache-control: private, must-revalidate, max-age=2591944
expires: Wed, 21 Oct 2020 14:54:21 GMT
date: Mon, 21 Sep 2020 14:55:17 GMT
x-cache: TCP_MISS from a96-17-11-212.deploy.akamaitechnologies.com (AkamaiGHost/10.1.5-30889964) (-)
x-edge-request-id: b59f7ae
vary: Accept,Feature-Flags,Accept-Language
strict-transport-security: max-age=31536000 ; includeSubDomains ; preload
 -->

The code doesn't explicitly handle such errors - just assumes you got good data.

Code: [Select]
  if (!isset($META['zoneName'])) { // no zone data.. load it
    $Status.= "<!-- getting metadata for forecast zone from $metaZoneURL -->\n";
    $rawhtml = ADV_fetchUrlWithoutHanging($metaZoneURL);
    $stuff = explode("\r\n\r\n",$rawhtml); // maybe we have more than one header due to redirects.
    $content = (string)array_pop($stuff); // last one is the content
    $headers = (string)array_pop($stuff); // next-to-last-one is the headers
    $rawPJSON = json_decode($content, true); // parse the JSON into an associative array
    $PJSON  = $rawPJSON['properties'];       // geojson format
 

So when you get to that last line there, you encounter the error because "properties" is not set.

2) The reason it is failing is because you have a county code there instead of a zone code. It needs to be a zone code. You can fix this in Settings.php

Code: [Select]
$SITE['NWSforecasts']   = array( // for the advforecast2.php V3.xx version script
// use "Zone|Location|Point-printableURL",  as entries .. first one will be the default forecast.
"PAZ047|Penn Lake Park |http://forecast.weather.gov/MapClick.php?lat=41.1131&lon=-75.7749&unit=0&lg=english&FcstType=text&TextType=2",
"NYC043|Richfield Springs|http://forecast.weather.gov/MapClick.php?lat=42.8534&lon=-74.9854&unit=0&lg=english&FcstType=text&TextType=2",
"PAZ055|Stroudsburg|http://forecast.weather.gov/MapClick.php?lat=40.9868&lon=-75.1946&unit=0&lg=english&FcstType=text&TextType=2",
"PAZ006|Coudersport|http://forecast.weather.gov/MapClick.php?lat=41.7748&lon=-78.0206&unit=0&lg=english&FcstType=text&TextType=2",
);

Just plug in the correct zone code for Richfield as you've done for the others.
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline yamiacaveman

  • Forecaster
  • *****
  • Posts: 412
    • Penn Lake Weather
Re: Notice: Undefined index:
« Reply #2 on: September 21, 2020, 11:23:49 AM »
Thank you all for your help!!!
I'll have to look up the code and plug it in and see what happens. Is this something that changed recently? It's been working for years or have I just been lucky, lol.

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 929
    • LexMAWeather
Re: Notice: Undefined index:
« Reply #3 on: September 21, 2020, 12:06:18 PM »
Did you change recently from the v4.xx code to v5.xx? In any case, yeah, it should be a zone code for all.
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2274
    • CNYWeather
Re: Notice: Undefined index:
« Reply #4 on: September 21, 2020, 12:12:44 PM »
pennlake.us

This happens if you go to pennlake.us  -- Forecast - then Select Richfield Springs.


yamiacaveman

OT: but Richfield Springs? Thats not too far from me. The zone is NYZ046 for Otsego County.
Tony




Offline yamiacaveman

  • Forecaster
  • *****
  • Posts: 412
    • Penn Lake Weather
Re: Notice: Undefined index:
« Reply #5 on: September 21, 2020, 01:07:26 PM »
Thanks Tony.

Offline yamiacaveman

  • Forecaster
  • *****
  • Posts: 412
    • Penn Lake Weather
Re: Notice: Undefined index:
« Reply #6 on: September 21, 2020, 01:10:44 PM »
Yes Jasiu, a few weeks ago I updated a lot of things -- and I don't believe I checked that part of the forecast out, again thanks you are always a great help.

Offline yamiacaveman

  • Forecaster
  • *****
  • Posts: 412
    • Penn Lake Weather
Re: Notice: Undefined index:
« Reply #7 on: September 21, 2020, 01:33:00 PM »
Well I changed to the correct zone in the Settings which seemed to correct some things but not all -- does anyone know what else I need to change?

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9011
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Notice: Undefined index:
« Reply #8 on: September 21, 2020, 01:39:40 PM »
You have a typo... 'NYZ04'  instead of 'NYZ046' in
Code: [Select]
"NYZ04|Richfield Springs|http://forecast.weather.gov/MapClick.php?lat=42.8534&lon=-74.9854&unit=0&lg=english&FcstType=text&TextType=2",
in Settings.php
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 yamiacaveman

  • Forecaster
  • *****
  • Posts: 412
    • Penn Lake Weather
Re: Notice: Undefined index:
« Reply #9 on: September 21, 2020, 08:31:21 PM »
Thanks Ken and thanks to all!

Boy, it's getting bad when I can't even copy and past right!

Again Thanks!