Giter VIP home page Giter VIP logo

openweathermap-spark-lib's Introduction

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

  • You have to download the HttpClient.cpp/HttpClient.h files from HttpClient library to your project.
  • As well download the library https://github.com/bblanchon/ArduinoJsonParser with the .cpp and .h files. Put the files in the utility directory also in a the utility directory in your project.
  • Download the files .cpp/.h files from this project page.

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!

openweathermap-spark-lib's People

Contributors

synox avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.