Book Image

Intel Galileo Networking Cookbook

By : Marco Schwartz
Book Image

Intel Galileo Networking Cookbook

By: Marco Schwartz

Overview of this book

Table of Contents (15 chapters)
Intel Galileo Networking Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Accessing weather data remotely


In this recipe, we are going to see how to interact with a simple web API—a weather data service called Forecast.io. Using this API, we are going to grab the weather data from the service and get it back to our board.

Getting ready

We need to register with the Forecast.io website, https://developer.forecast.io/register, before we can code our project.

The goal is to get an API key that you will find inside your Account tab:

Keep this key handy; you will need it soon enough.

How to do it...

Let's now look at the code. The goal is to connect to the Forecast.io server, send a request to get local weather data, and then print the data inside the console. This is the complete code (this code was taken from the example code in the Forecast.io Node.js module):

// Require the module
var Forecast = require('forecast');

// Initialize
var forecast = new Forecast({
  service: 'forecast.io',
  key: 'your_api_key', // Should be replaced with your key 
  units: 'celcius', // Only...