Skip to content

danielbernard/openweathermap-spark-lib

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weather Library for Spark-Core

This is a simple library to load weather information from openweathermap.com, made for spark core (http://spark.io) (Arduino compatible).

It's free, you just have to sign up for an api-key at: http://openweathermap.org/appid

This library should be considered alpha tested software. Please report any problems, I am happy to help.

Installation

If you are building locally, change the file build.mk and add the .cpp files.

Usage

See the following code, replace the location and the api key.

#include "openweathermap.h"
#include "HttpClient.h"


Weather* weather;
HttpClient* httpClient;

void setup() {		
	httpClient = new HttpClient();
	weather = new Weather("London,UK", httpClient,
			"INSERT your api key here!");
	weather->setCelsius();
	// or weather->setFahrenheit();
}

void loop() {
	weather_response_t resp = weather->cachedUpdate();
	if (resp.isSuccess) {
		Serial.print(resp.temp_low);
		Serial.print("-");
		Serial.print(resp.temp_high);
		Serial.println(resp.descr);
	}
}

There is also a non-cached method, if you want to handle caching yourself:

		weather_response_t resp = weather->update();

Also see the example in the project directory.

Weather data

Currently the library loads the high and low temperature for today, including a short description. You can see the list of Condition-Codes at: http://openweathermap.org/wiki/API/Weather_Condition_Codes

Can I extend it to include other data?

Sure! Look at the data: http://api.openweathermap.org/data/2.5/forecast/daily?q=London&mode=xml&units=metric&cnt=2

then change the method Weather::parse and extend the weather_response_t.

How could I help? (TODO)

  • test in Spark web ide
  • make two distribution files (cpp and h) including everything, to make it easier to include in a project

Have fun! Share!

About

openweathermap.com implementation for Spark-Core

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published