Book Image

Intel Galileo Networking Cookbook

By : Marco Schwartz
Book Image

Intel Galileo Networking Cookbook

By: Marco Schwartz

Overview of this book

Table of Contents (15 chapters)
Intel Galileo Networking Cookbook
About the Author
About the Reviewers

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 =;

  // Return...