1

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.

  • You need to connect to their server and using HTTP protocol send request specifying one of supported URLs then server will send response containing JSON or XML document that you need to parse to extract requested data. – user7860670 Sep 30 '17 at 05:32
  • @VTT sorry but I don't understand what you mean as i am a noob. Could you please explain a bit more. Thanks –  Sep 30 '17 at 07:26
  • Then you need to move out of noob category: read some [C++ books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list), study networking in general and HTTP protocol in particular, check JSON and XML formats specifications to figure out how to deal with them. If you just need to make it work somehow then you may want to use some noob-friendly language, such as javascript or go. – user7860670 Sep 30 '17 at 07:40

1 Answers1

0

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.

Kevin Boone
  • 4,092
  • 1
  • 11
  • 15