JHershey69 / OpenWeatherOneCall

Open Weather One Call library to gather current, hourly (48), and 7 day weather for your current location
GNU General Public License v3.0
38 stars 11 forks source link

Alerts only returns 1 alert when there can be many #30

Closed blackeneth closed 3 years ago

blackeneth commented 3 years ago

Today in the Philly area there are 3 alerts:

{"lat":39.87,"lon":-75.23,"timezone":"America/New_York","timezone_offset":-14400,"alerts":[{"sender_name":"NWS Philadelphia - Mount Holly (New Jersey, Delaware, Southeastern Pennsylvania)","event":"Heat Advisory","start":1626102000,"end":1626220800,"description":"...HEAT ADVISORY REMAINS IN EFFECT UNTIL 8 PM EDT TUESDAY...\n* WHAT...Heat index values between 100 to 105 expected.\n* WHERE...In New Jersey, Gloucester, Northwestern Burlington and\nCamden. In Pennsylvania, Delaware, Philadelphia, Eastern\nMontgomery and Lower Bucks. In Delaware, New Castle.\n* WHEN...From 11 AM this morning to 8 PM EDT Tuesday.\n* IMPACTS...Hot temperatures and high humidity may cause heat\nillnesses to occur.","tags":["Extreme temperature value"]},{"sender_name":"NWS Philadelphia - Mount Holly (New Jersey, Delaware, Southeastern Pennsylvania)","event":"Flash Flood Watch","start":1626103380,"end":1626166800,"description":"...FLASH FLOOD WATCH IN EFFECT THROUGH LATE TONIGHT...\nThe National Weather Service in Mount Holly has expanded the\n* Flash Flood Watch to include portions of New Jersey...and\nPennsylvania...including the following areas...in New Jersey...\nCamden, Gloucester, Mercer, Northwestern Burlington, and Western\nMonmouth. In Pennsylvania...Berks, Carbon, Delaware, Eastern\nChester, Eastern Montgomery, Lehigh, Lower Bucks, Monroe,\nNorthampton, Philadelphia, Upper Bucks, Western Chester, and\nWestern Montgomery.\n* Through late tonight.\n* A near stationary frontal boundary combined with a hot and humid\nair mass will cause one or more rounds of thunderstorms with heavy\nrain to affect the area from this afternoon into tonight. Rainfall\namounts could be highly variable, but a general 1 to 3 inches of\nrain with locally higher amounts is possible through tonight.\n* Heavy rain in a short period of time may cause streams and creeks\nto rise quickly out of their banks. There is also the potential\nfor flash flooding across more urbanized areas and those areas\nwith poor drainage.","tags":["Flood"]},{"sender_name":"NWS Philadelphia - Mount Holly (New Jersey, Delaware, Southeastern Pennsylvania)","event":"Flood Advisory","start":1626118200,"end":1626145200,"description":"The National Weather Service in Mount Holly has issued a\n* Flood Advisory for...\nNorthwestern Camden County in southern New Jersey...\nSoutheastern Delaware County in southeastern Pennsylvania...\nSouth Central Montgomery County in southeastern Pennsylvania...\nSouthwestern Philadelphia County in southeastern Pennsylvania...\n* Until 900 PM EDT.\n* At 526 PM EDT, Doppler radar indicated heavy rain due to\nthunderstorms. Minor flooding is ongoing or expected to begin\nshortly in the advisory area. Between 0.5 and 1 inch of rain has\nalready fallen in spots. An additional 1 to 2 inches of rain is\npossible.\n* Some locations that may experience flooding include...\nPhiladelphia, Camden, Gloucester City, Chester, Yeadon, Palmyra,\nFolcroft, Swarthmore, Narberth, National Park, and East Lansdowne.\nThis includes the following highways...\nInterstate 95 in Pennsylvania between mile markers 6 and 26.\nInterstate 76 in Pennsylvania between mile markers 339 and 351.\nInterstate 76 in New Jersey near mile marker 3.\nInterstate 676 in Pennsylvania between mile markers 0 and 1.\nInterstate 676 in New Jersey between mile markers 1 and 4.\nInterstate 476 in Pennsylvania between mile markers 0 and 7.","tags":["Flood"]}]}

OWOC will only return the first alert.

OWOC.alert->summary

An enhancement would be store all alerts, to allow them to be queried

OWOC.alert[x].event
OWOC.alert[x].description 
OWOC.alert[x].start
OWOC.alert[x].end
OWOC.alert[x].sender_name
OWOC.alert[x].tags

The ArduinoJson helper comes up with this structure:

for (JsonObject elem : doc["alerts"].as<JsonArray>()) {

  const char* sender_name = elem["sender_name"]; // "NWS Philadelphia - Mount Holly (New Jersey, Delaware, ...
  const char* event = elem["event"]; // "Heat Advisory", "Flash Flood Watch", "Flood Advisory"
  long start = elem["start"]; // 1626102000, 1626103380, 1626118200
  long end = elem["end"]; // 1626220800, 1626166800, 1626145200
  const char* description = elem["description"]; // "...HEAT ADVISORY REMAINS IN EFFECT UNTIL 8 PM EDT ...

  const char* tags_0 = elem["tags"][0]; // "Extreme temperature value", "Flood", "Flood"

}

Another field would be needed to let the programmer know the maximum "x" to retrieve alerts for.

Thank you for your consideration.

JHershey69 commented 3 years ago

Thank you, I initially entertained being able to store more than 1 alert. However, the number of areas with more than 1 alert at a time is very small given the area of the Earth, and the memory required to store full information for all alerts in areas with more than 2 would be prohibitive. However, I do continually monitor alerts and evaluate including said routine in the program.

JHershey69 commented 3 years ago

Available now in 3.1.5 Please see Addendum for info on new variable access format