ArduinoJson hangs if no data received

Hi,
I am using ArduinoJson in a sketch to get weather information from Weather Underground. All is well if WU sends the data. See bottom of this page for examples:

My problem is I would like to add weather alerts like flood warnings or tornado watches. My program works fine if there happens to be an active alert but most of the time there are no active alerts. Then Weather Underground doesn't sent data and my program hangs waiting for it.

Any experts with ArduinoJson know of a trap for such a situation?

Oldmicroguy

See bottom of this page for examples:

We don't want to see examples. We want to see YOUR code!

Any experts with ArduinoJson know of a trap for such a situation?

Pretty simple, really. Don't call the JSON parsing routines if there is nothing to parse.

The whole point of a weather alert is to alert you to something. If there were a way to know there weren't any active alerts without calling for alerts I would have done that.

Oldmicroguy

The whole point of a weather alert is to alert you to something. If there were a way to know there weren't any active alerts without calling for alerts I would have done that.

Oldmicroguy

If there were a way to know there weren't any active alerts without calling for alerts I would have done that.

You need to separate GETTING the data from PARSING the data. The library that you use does not appear to do that. Therefore, it is unlikely that that library is appropriate FOR YOUR NEEDS.

Write your own.

Use micros() and start a timer when you go to get data. If(data_collected OR timer_expired), then stop. Look up timers and get a feel for how they work.