Issue
I am currently trying to display the weather forecast on my Raspberry Pi 3 using C++. I have tried to look everywhere for help but I couldn't find any.
So currently, I am trying to use this API https://openweathermap.org/forecast5
On this website, it states:
Forecast is available in JSON or XML format.
But, I am not sure how to use it. Can someone please tell me how to use it with C++ on my Raspberry Pi 3? Thanks in advance.
Solution
If you're going to do this in C++, then you will need to figure out at least three things:
- Making and processing an HTTP request
- Parsing the returned XML or JSON into something your program can output
- Formatting and displaying the output (console? GUI? LCD display...?)
You really, really don't want to be implementing much of this yourself from the ground up, unless you have an unlimited amount of time on your hands. There are libraries for making HTTP requests (e.g., libcurl), and libraries for parsing XML and JSON (libxml2, etc). What you do for the display depends, of course, on how you intend to implement the display.
So I would suggest that the first step is to look at some simple demo programs that work with libcurl and libxml2, and figure out how these libraries work.
FWIW I have some code that does what you need, based on the BBC UK weather feeds, and I'd be happy to share. But it's 4,000+ lines of C; while I don't claim to be the most efficient of programmers, that should give an idea of how non-trivial the application is, even with libraries doing most of the heavy lifting.
Answered By - Kevin Boone