fowlerk / ESP8266-Color-Weather-Station-v8

Enhanced ESP8266 Color Weather Station w/ On-Demand Configuration
GNU General Public License v3.0
29 stars 5 forks source link

Combine multiple WU API calls into one WU API call #2

Open taogeek opened 7 years ago

taogeek commented 7 years ago

Reading the Weather Underground documentation tells me that multiple API calls can be aggregated into one call. It looks like the weather station makes three API calls: conditions, forecasts, and astronomy. To combine the calls each needs to be catenated in the URL request.

For instance the example below combines 1) geolookup 2) conditions and 3) forecast into one call:

http://api.wunderground.com/api/YOUR_API_KEY/geolookup/conditions/forecast/q/CA/San_Francisco.json?_ga=1.117405509.2138126299.1483772697

The format is so easy to understand that I overlooked the solution several times when reading the documentation. I'm going to build on top of your mods this weekend to see if I can get this working. I'm unfamiliar with json and it's implementation in the weather station so I might be stumbling along. I'll let you know how I fare, I'm using your mods as a starting place because the alerts you enabled are important to me and I want to use them.

Update: Wow. This was incredible easy to do. I added one line to boththe WU cpp and h with the aggregate statements and bam! bob's my uncle. Sorry to have bothered you.

fowlerk commented 7 years ago

@taogeek ... No bother at all. I'd actually been considering this as a possible change to the existing approach but hadn't convinced myself of the advantage yet. It could be a way to reduce the API calls, on the other hand, not all the info needs to be updated frequently. Perhaps the current conditions and alerts? Combining those might save some calls, but neither the 10-day forecast data or astronomy info changes that often? In any case, I like the concept and would be interested how it works for you after you run it awhile. BTW... I've been running with the alerts for about 3 weeks now and love the additional information, especially during some of our recent winter weather.

taogeek commented 7 years ago

I agree, the alerts are a big win (thx for that tweak!). I changed to landscape orientation and the alerts really benefit from the extra length. I also break the alerts into sentences and cycle through the set of sentences, changing every 3 seconds or so. Really nifty.

I'll let you know how the single call works after running it for awhile. I like it so far and it's only making 1/3 of the API calls. Some slower changing information is being updated unnecessarily, but I think it's worthwhile. Adding different kind of calls on a schedule is much more work; good to do of course, just much more work.