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 7. Controlling Your Galileo Projects from Anywhere

In the previous chapter, we integrated our Galileo board with an IoT framework. We measured data on the board and sent the data through online services.

Furthermore, we enabled the data to be stored and visualized online through the cloud.

In this chapter, you will learn how to develop the software that will control your board from anywhere. For instance, you will learn how to switch the state of the relay from a remote browser.

Here is an overview of how we will do this:

  • Plug a relay to the board

  • Make a local interface to control this relay

  • Set up our system so that we can access it from anywhere

We will discuss several ways to do this, so you can have an overview of what works best. We will use a little software running on our computer to relay the information from the web to the Galileo board. We will also see how to modify our router settings to do the same without the use of a computer.

Hardware and software requirements


We won't have trouble with this project's requirements as we will use the same hardware and software that we used in the previous chapter. The details about the hardware requirements and configurations are given in Chapter 4, Monitoring Data Remotely.

All we need to do is to add a 5V relay on the board.

Note

For more information about the relay, you can refer to its product link:

Pololu 5V relay module (http://www.pololu.com/product/2480)

The Pololu relay is a single-pole double-throw (SPDT) relay and is rated up to 10A under most conditions. SPDT relays are commonly used in electronics. They have two input pins for the coil, and three output pins to control electrical devices. SPDT utilizes a Zener diode for fast current decay. It also has two LED lights as coil actuation indicators.

Hardware configuration


Let's take a look at the hardware configuration just to refresh our memory.

Here is the schematic used for this project:

We used the same configuration in Chapter 3, Controlling Outputs Using the Galileo Board. This is the relay that we will use in this chapter:

If you want to go back to the specific instructions as to how to do this, you can go back to Chapter 3, Controlling Outputs Using the Galileo Board.

The following picture will show you my final configuration:

Building an interface to control the relay


The next thing that we need to do is to build an interface to control the relay.

The On and Off buttons will serve as our trigger controls.

Just a note: the code that we will use here is similar to the code that we used in Chapter 5, Interacting with Web APIs. Nevertheless, we will still go over the code that we will be using:

  1. First, we define the relay pin object:

    var relay_pin = new mraa.Gpio(7);
    relay_pin.dir(mraa.DIR_OUT);
  2. Then, we will use the same API we built in the previous chapter, and add functionalities to it. Create a new API call for the relay using the following code:

    app.get('/api/relay', function(req,res){
        
      // Get desired state    
      var state = req.query.state;
      console.log(state);
        
      // Apply state
      relay_pin.write(parseInt(state));       
        
      // Send answer
      json_answer = {};
      json_answer.message = "OK";
      res.json(json_answer);
    });
  3. In this code, we determine the state of the relay from the query. Then, we will write...

Accessing the interface from anywhere


Now that we have successfully controlled the relay through the interface, we will explore ways to access this interface from anywhere.

For this, we will use Ngrok. This is a simple utility that enables its users to test local hosts with remote APIs. Through Ngrok, collaborators can overcome firewalls and access TLS connections.

It is an easy-to-use service, which requires no sign ups.

The Ngrok service will open up a tunnel between your local board and the Web. Then, you can access the interface from anywhere, anytime! It should be noted, however, that it doesn't work with the Galileo as of the time of this writing.

So, we will use our own computer as a relay instead, establishing the connection between the Web and your Galileo board:

  1. To do so, we first download the Ngrok files from the following URL:

    https://ngrok.com/download

  2. Now, if you are using Windows, double-click on the file to unzip it. If you are using Linux or OS X, go to the folder where you have...

Removing the need for a third party


In the last section, we saw how to access our interface from anywhere in the world by running software on our computer, called Ngrok. However, we will see that there are other ways to do the same without using Ngrok: but these other ways are a bit more complicated.

One way is to use the parameters of your internet router to automatically forward the connections from outside to your local Galileo board. For this, you need to perform the following steps:

  1. First, you need to know the IP address of your router.

    Note

    Note that this is not the IP address of your local computer, but the one of your router. Visit the following link:

    http://www.whatismyip.com/

    Your IP address will immediately be printed on the screen:

  2. Now, we need to modify our router settings to forward connections from this external IP to our Galileo board. We'll use a given port for this, such as 3001.

  3. First, you need to know the local IP address of your router. This can be done in most systems by...

Summary


In this chapter, you learned how to control a device such as a relay remotely, from anywhere in the world.

Here is a summary of what we did:

First, we attached a relay to our board just as we did in Chapter 3, Controlling Outputs Using the Galileo Board. Then, we built an interface to control the relay via simple buttons. Finally, we integrated the interface through Ngrok, which enabled us to access the controls from any place where there is an internet connection. We also looked at another way to access the interface, which is to modify the router settings and forward the incoming connections to the router.

In the next chapter, we are going to build a wireless security camera just using a USB webcam. Stay tuned!

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}