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

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...

lock icon The rest of the chapter is locked
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}