Book Image

Intel Galileo Blueprints

By : Marco Schwartz
Book Image

Intel Galileo Blueprints

By: Marco Schwartz

Overview of this book

Table of Contents (19 chapters)
Intel Galileo Blueprints
About the Author
About the Reviewers
Free Chapter
Setting Up the Galileo Board and the Development Environment

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);
  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;
      // Apply state
      // Send answer
      json_answer = {};
      json_answer.message = "OK";
  3. In this code, we determine the state of the relay from the query. Then, we will write...