Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Intel Galileo Blueprints

You're reading from  Intel Galileo Blueprints

Product type Book
Published in Jun 2015
Publisher
ISBN-13 9781785281426
Pages 192 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Marco Schwartz Marco Schwartz
Profile icon Marco Schwartz

Table of Contents (19) Chapters

Intel Galileo Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Setting Up the Galileo Board and the Development Environment Creating a Weather Measurement and Data Logging Station Controlling Outputs Using the Galileo Board Monitoring Data Remotely Interacting with Web APIs Internet of Things with Intel Galileo Controlling Your Galileo Projects from Anywhere Displaying the Number of Unread Gmail E-mails on an LCD Screen Automated Remote Gardening with Intel Galileo Building a Complete Home Automation System Building a Mobile Robot Controlled by the Intel Galileo Board Controlling the Galileo Board from the Web in Real Time Using MQTT Index

Chapter 5. Interacting with Web APIs

In the previous chapter, you learned how to use the onboard Ethernet port, communicate locally with the board, and retrieve data from it.

In this chapter, we will perform a similar experiment. The only difference is that we will interface our board with web APIs. This gives us the option to broadcast our results through social media platforms, such as Twitter.

Here is a walk-through on how we are going to go about this:

  • We will structure our app using Express. Express is a flexible and minimalistic web app framework for Node.js, which provides a robust set of both mobile and web features. It integrates well with the Node.js platform.

  • Next, we will grab weather forecasts from the Internet and integrate them in our application.

  • Finally, we will use Twitter to post the data online. With this, we can regularly tweet weather updates through our Twitter account.

Let's proceed!

Using Express to structure our application


Firstly, we need to create a structure for our application. As previously mentioned, we are going to use Express to do this.

Through Express, we will separate the data acquisition from the interface. You can visit the official site given here to learn how Express works, how to use it for the first time, how to handle errors, and a lot more at http://expressjs.com/.

The measurement part will stay in Node.js. Since Node.js is an asynchronous event-driven type of framework, it can easily build fast and scalable net applications. This is what makes it efficient and lightweight to use, and a perfect choice if one wants to run real-time and data-intensive apps on multiple devices.

Meanwhile, the interface will use Jade, which is a Node.js templating engine created for HTML.

We will then link up both Node.js and Express to the Jade interface using JavaScript.

As for the hardware, we can reuse the one that we made for our data monitoring project - the one that...

Getting the current weather forecast


Once we structure our web application, we will configure Forecast.io. Forecast.io is a web API that returns weather forecasts of your exact location, and it updates them by the minute. The API has stunning maps, weather animations, temperature unit options, forecast lines, and more.

We will use this API to integrate global weather measurements with our local measurements.

To do so, first go to the following link:

http://forecast.io/

Then, look for the Forecast API link at the bottom of the page. It should be under the Developers section of the footer:

You need to create your own Forecast.io account. You can do so by clicking on the Register button on the top right-hand side portion of the page. It will take you to the registration page where you need to provide an e-mail address and a strong password.

Then, you will be required to get an API key, which will be displayed in the Forecast.io interface:

Write this down somewhere, as you will need it soon.

We will...

Posting data on Twitter


Finally, you will learn how to post the measured data on a Twitter account.

The first step is to go to the Twitter apps website:

https://apps.twitter.com/

Then, click on the Create New App button.

Fill up the form with the details regarding this app. You can copy the details that I've used in my form, which you can see in the following screenshot:

After filling this up, the next thing that you should do is to get the keys and the token. These additional details are required for the authentication of requests on behalf of Twitter. These are considered as passwords, so ensure that you do not share these things to untrusted people.

You should be able to see the interface as shown here:

Next, you will be required to set the permissions. This decision depends on the needs of your application. In my case, I have set it to Read and Write. I deem that accessing direct messages is not necessary for our experiment.

You will be able to see the interface as follows:

All the things that...

Summary


To make our Galileo board get the current weather measurements and broadcast it to Twitter, we have performed the following steps:

First, we organized and structured our web app with Express. Node.js was responsible for the data and measurement, while Jade was used to build the interface. We also use jQuery to handle the interface, and Bootstrap CSS to give a better look to the app.

Then, we learned to add an online forecast to the app. Finally, we learned how to interface our app with Twitter so we could tweet the data on our twitter accounts.

In the next chapter, we will continue with a more complex Internet of Things application. We will make the Galileo board into an online data-logging platform, so that we can access and plot the data from any web browser.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Intel Galileo Blueprints
Published in: Jun 2015 Publisher: ISBN-13: 9781785281426
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}