ThingPulse / esp8266-weather-station

ESP8266 Weather Station library supporting OpenWeatherMap, Aeris and other sources
MIT License
1.06k stars 360 forks source link

Would like to add alerts #30

Closed RogerSchaefer closed 8 years ago

RogerSchaefer commented 8 years ago

The weather station works fine for me HOWEVER I would like to add 'alerts' because i would like to add an alarm when there is bad weather nearby. I added alerts and it started to load but crashed when it got to the field "message". Perhaps because it is too large.

Can you help? Oldmicroguy

squix78 commented 8 years ago

Hi Roger Thanks for your request. Can you explain a bit more what alerts are? I assume they are part of the Wunderground API? Maybe paste the part of the json object that you are interested in here... Regards, Daniel

RogerSchaefer commented 8 years ago

Hello Daniel, Your Weather Station uses Wunderground “conditions” and “forecast10day”. “alerts” is another Data Feature. The problem is testing because you have to find a part of the county that is experiencing some sort of weather alert. Here is an example:

// 20160530145454 // http://api.wunderground.com/api/eceaa409b9a76e6c/alerts/q/AZ/Yuma.json

{ "response": { "version": "0.1", "termsofService": "http://www.wunderground.com/weather/api/d/terms.html", "features": { "alerts": 1 } }, "query_zone": "025", "alerts": [ { "type": "HEA", "description": "Excessive Heat Watch", "date": "4:48 am PDT on May 30, 2016/", "date_epoch": "1464608880", "expires": "8:00 PM MST on June 05, 2016", "expires_epoch": "1465182000", "tz_short": "PDT", "tz_long": "America/Los_Angeles", "message": "\n...Excessive heat watch in effect from Friday morning through\nSunday evening...\n\nThe National Weather Service in Phoenix has issued an excessive\nheat watch...which is in effect from Friday morning through\nSunday evening. \n\n* Affected area...the lower deserts of southwest and south-central\n Arizona and southeast California. \n\n* Temperature...highs of 108-112 degrees...hottest on Saturday.\n\n* Impacts...heat related illness will be likely for those doing\n strenuous activity outdoors...or those with health conditions that\n do not have adequate access to air conditioning. If\n untreated...some illness events could be fatal. \n\nPrecautionary/preparedness actions...\n\nNever leave kids or pets unattended in cars. Drink more water\nthan usual and avoid alcohol...sugar...and caffeine. When\noutdoors...wear light colored clothing and a wide-brimmed hat to\nkeep your head and body cooler. Take frequent rest breaks in\nshaded or air conditioned environments. Public places with air\nconditioning include libraries...community centers...government\nbuildings...malls...and special Refuge stations. \n\nRecognize the signs and symptoms of heat illness. Early symptoms\ninclude things such as headache...thirst...and muscle cramps.\nSerious symptoms include weakness...skin that is cool to the\ntouch...fast but weak pulse...nausea...and fainting. Severe\nsymptoms include hot and red dry skin...fast and strong\npulse...sweating that has stopped...and unconsciousness.\nUntreated heat illness can lead to fatal heat stroke. \n\nStay cool...stay hydrated...stay informed.\n\n\n\nAj\n\n\n\n", "phenomena": "EH", "significance": "A", "ZONES": [ { "state": "AZ", "ZONE": "020"

Your program crashes at the field “message” Roger

From: squix78 Sent: Monday, May 30, 2016 2:36 PM To: squix78/esp8266-weather-station Cc: RogerSchaefer ; Author Subject: Re: [squix78/esp8266-weather-station] Would like to add alerts (#30)

Hi Roger Thanks for your request. Can you explain a bit more what alerts are? I assume they are part of the Wunderground API? Maybe paste the part of the json object that you are interested in here... Regards, Daniel

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

squix78 commented 8 years ago

Hi Roger I assume you extended the WundergroundClient class to call the alerts URL and parse the message attribute and add it's content into? The problem is most probably in my json-streaming-parser class which limits the length of a value to 512 bytes: https://github.com/squix78/json-streaming-parser/blob/master/JsonStreamingParser.h If I remember correctly this was an issue I wanted to resolve later or at least make it possible to change. While the library is currently able of parse huge json objects for relatively small length of keys and values it has a problem with keys or values bigger than 512 bytes. I can offer a quick fix by just ommitting characters beyond that length. If you are not interested in the messages field that should solve the problem...

SCKStef commented 8 years ago

Hi Daniel,

I have the same issue, I have extended the parser too...

As example here an response from Germany which have more than one alert:

{ "response": { "version":"0.1", "termsofService":"http://www.wunderground.com/weather/api/d/terms.html", "features": { "alerts": 1 } } ,"query_zone": "999", "alerts": [ { "type": "WND", "wtype_meteoalarm": "1", "wtype_meteoalarm_name": "Wind", "level_meteoalarm": "4", "level_meteoalarm_name": "Red", "level_meteoalarm_description": "The weather is very dangerous. Exceptionally intense meteorological phenomena have been forecast. Major damage and accidents are likely, in many cases with threat to life and limb, over a wide area. Keep frequently informed about detailed expected meteorological conditions and risks. Follow orders and any advice given by your authorities under all circumstances, be prepared for extraordinary measures.", "description": "\u0009\u0009\u0009\u0009\u0009\u0009\u0009\u0009deutsch: Von Südosten ziehen wiederholt Gewitter auf. Dabei gibt es heftigen Starkregen mit Niederschlagsmengen um 40 l/m² pro Stunde sowie Windböen mit Geschwindigkeiten um 55 km/h (15m/s, 30kn, Bft 7) und kleinkörnigen Hagel.", "date": "2016-05-29 19:09:00 GMT", "date_epoch": "NA", "expires": "2016-05-29 20:30:00 GMT", "expires_epoch": "NA", "message": "\u0009\u0009\u0009\u0009\u0009\u0009\u0009\u0009deutsch: Von Südosten ziehen wiederholt Gewitter auf. Dabei gibt es heftigen Starkregen mit Niederschlagsmengen um 40 l/m² pro Stunde sowie Windböen mit Geschwindigkeiten um 55 km/h (15m/s, 30kn, Bft 7) und kleinkörnigen Hagel.)", "phenomena": "NA", "significance": "NA", "attribution": "Information provided by , EUMETNET - MeteoAlarm Note: Time delays between this website and Meteoalarm.eu are possible. For the most up-to-date information about alert levels as published by the participating National Meteorological Services, please visit Meteoalarm. For terms of use of this information, and copyright information, see Meteoalarm Terms of Use." } , { "type": "WRN", "wtype_meteoalarm": "3", "wtype_meteoalarm_name": "Thunderstorms", "level_meteoalarm": "4", "level_meteoalarm_name": "Red", "level_meteoalarm_description": "The weather is very dangerous. Exceptionally intense meteorological phenomena have been forecast. Major damage and accidents are likely, in many cases with threat to life and limb, over a wide area. Keep frequently informed about detailed expected meteorological conditions and risks. Follow orders and any advice given by your authorities under all circumstances, be prepared for extraordinary measures.", "description": "\u0009\u0009\u0009\u0009\u0009\u0009\u0009\u0009deutsch: Von Südosten ziehen wiederholt Gewitter auf. Dabei gibt es heftigen Starkregen mit Niederschlagsmengen um 40 l/m² pro Stunde sowie Windböen mit Geschwindigkeiten um 55 km/h (15m/s, 30kn, Bft 7) und kleinkörnigen Hagel.", "date": "2016-05-29 19:09:00 GMT", "date_epoch": "NA", "expires": "2016-05-29 20:30:00 GMT", "expires_epoch": "NA", "message": "\u0009\u0009\u0009\u0009\u0009\u0009\u0009\u0009deutsch: Von Südosten ziehen wiederholt Gewitter auf. Dabei gibt es heftigen Starkregen mit Niederschlagsmengen um 40 l/m² pro Stunde sowie Windböen mit Geschwindigkeiten um 55 km/h (15m/s, 30kn, Bft 7) und kleinkörnigen Hagel.)", "phenomena": "NA", "significance": "NA", "attribution": "Information provided by , EUMETNET - MeteoAlarm Note: Time delays between this website and Meteoalarm.eu are possible. For the most up-to-date information about alert levels as published by the participating National Meteorological Services, please visit Meteoalarm. For terms of use of this information, and copyright information, see Meteoalarm Terms of Use." } , { "type": "FLO", "wtype_meteoalarm": "10", "wtype_meteoalarm_name": "Rain", "level_meteoalarm": "4", "level_meteoalarm_name": "Red", "level_meteoalarm_description": "The weather is very dangerous. Exceptionally intense meteorological phenomena have been forecast. Major damage and accidents are likely, in many cases with threat to life and limb, over a wide area. Keep frequently informed about detailed expected meteorological conditions and risks. Follow orders and any advice given by your authorities under all circumstances, be prepared for extraordinary measures.", "description": "\u0009\u0009\u0009\u0009\u0009\u0009\u0009\u0009deutsch: Von Südosten ziehen wiederholt Gewitter auf. Dabei gibt es heftigen Starkregen mit Niederschlagsmengen um 40 l/m² pro Stunde sowie Windböen mit Geschwindigkeiten um 55 km/h (15m/s, 30kn, Bft 7) und kleinkörnigen Hagel.", "date": "2016-05-29 19:09:00 GMT", "date_epoch": "NA", "expires": "2016-05-29 20:30:00 GMT", "expires_epoch": "NA", "message": "\u0009\u0009\u0009\u0009\u0009\u0009\u0009\u0009deutsch: Von Südosten ziehen wiederholt Gewitter auf. Dabei gibt es heftigen Starkregen mit Niederschlagsmengen um 40 l/m² pro Stunde sowie Windböen mit Geschwindigkeiten um 55 km/h (15m/s, 30kn, Bft 7) und kleinkörnigen Hagel.)", "phenomena": "NA", "significance": "NA", "attribution": "Information provided by , EUMETNET - MeteoAlarm Note: Time delays between this website and Meteoalarm.eu are possible. For the most up-to-date information about alert levels as published by the participating National Meteorological Services, please visit Meteoalarm. For terms of use of this information, and copyright information, see Meteoalarm Terms of Use." } ] }

RogerSchaefer commented 8 years ago

Hi Daniel, Omitting characters beyond 512 bytes is exactly what I need. Will you issue a new version of the JsonStreamingParser? Roger

From: squix78 Sent: Tuesday, May 31, 2016 12:52 AM To: squix78/esp8266-weather-station Cc: RogerSchaefer ; Author Subject: Re: [squix78/esp8266-weather-station] Would like to add alerts (#30)

Hi Roger I assume you extended the WundergroundClient class to call the alerts URL and parse the message attribute and add it's content into? The problem is most probably in my json-streaming-parser class which limits the length of a value to 512 bytes: https://github.com/squix78/json-streaming-parser/blob/master/JsonStreamingParser.h If I remember correctly this was an issue I wanted to resolve later or at least make it possible to change. While the library is currently able of parse huge json objects for relatively small length of keys and values it has a problem with keys or values bigger than 512 bytes. I can offer a quick fix by just ommitting characters beyond that length. If you are not interested in the messages field that should solve the problem...

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

squix78 commented 8 years ago

I released a new version of the json-streaming-parser library. Can you update your local copy and make sure that you have version 1.0.3? Then please let me know if it fixes your issues...

RogerSchaefer commented 8 years ago

I just installed version 1.0.3 but unfortunately it did not fix the problem. The ESP8266 still crashes when it tries to load a large field into a 512 byte buffer. Roger

From: squix78 Sent: Tuesday, May 31, 2016 10:07 AM To: squix78/esp8266-weather-station Cc: RogerSchaefer ; Author Subject: Re: [squix78/esp8266-weather-station] Would like to add alerts (#30)

I released a new version of the json-streaming-parser library. Can you update your local copy and make sure that you have version 1.0.3? Then please let me know if it fixes your issues...

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

squix78 commented 8 years ago

Do you see an Exception when the ESP crashes? Can you copy here that exception? Or even better would be, if you could do the steps described here: https://github.com/esp8266/Arduino/issues/869#issuecomment-177146370

I am getting the ESP to crash with a big local json object but I am not sure if that is the same problem...

squix78 commented 8 years ago

There were some parsing problems for json containing unicode characters. I think they have been fixed. After the fix the json posted by @SCKStef could now be parsed, before it miserably crashed. Would you mind updating the json-streaming-parser library to 1.0.4 and test if you now can succesfuly read the alert json object?

RogerSchaefer commented 8 years ago

Yes json-streaming-parser ver 1.04 fixes the problem. Thank you. Roger

From: Daniel Eichhorn Sent: Sunday, June 05, 2016 8:13 AM To: squix78/esp8266-weather-station Cc: RogerSchaefer ; Author Subject: Re: [squix78/esp8266-weather-station] Would like to add alerts (#30)

There were some parsing problems for json containing unicode characters. I think they have been fixed. After the fix the json posted by @SCKStef could now be parsed, before it miserably crashed. Would you mind updating the json-streaming-parser library to 1.0.4 and test if you now can succesfuly read the alert json object?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.