Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Intel Galileo Networking Cookbook

You're reading from   Intel Galileo Networking Cookbook Over 50 recipes that will help you use the Intel Galileo board to build exciting network-connected projects

Arrow left icon
Product type Paperback
Published in Aug 2015
Publisher
ISBN-13 9781785281198
Length 174 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Marco Schwartz Marco Schwartz
Author Profile Icon Marco Schwartz
Marco Schwartz
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Intel Galileo Networking Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Installing and Configuring Linux FREE CHAPTER 2. Connecting External Sensors 3. Controlling Hardware Devices 4. Creating a Web Server 5. Hosting Applications on the Galileo Board 6. Local Network Monitoring 7. Cloud Data Monitoring 8. Building a Home Automation System Index

Creating an API to control Galileo


In the previous recipes, we created a simple web server application to read data from a given pin on the board, or to control a given pin. However, this is not convenient, as you always need to change the code every time you change the pin you want to control.

Here, we are going to learn how to create an API so that you can control any pin on the board from a web browser.

Getting ready

You don't need anything specific for this recipe, apart from an up-and-running Galileo board with the IoT image, which is connected to your local network.

How to do it...

In this recipe, we are going to define an API for our Galileo board that will allow us to control any pin on the board, just from a web browser. This is the complete code:

// Required modules
var m = require("mraa");
var util = require('util');

var express = require('express');
var app = express();

// API routes
app.get('/api/read', function (req, res) {

  // Get pin
  var pin = req.query.pin;

  // Return...
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
Visually different images