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
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Reading pins via a web server


We are now going to see how to use a web server for useful things. For example, we will see here how to use a web server to read the pins of the Galileo board, and then how to display these readings on a web page.

Getting ready

For this chapter, you won't need to do much with your Galileo board, as we just want to see if we can read the state of a pin from a web server. I simply connected pin number 7 of the Galileo board to the VCC pin, as shown in this picture:

How to do it...

We are now going to see how to read the state from pin number 7, and display this state on a web page. This is the complete code:

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

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

// Set input on pin 7
var myDigitalPin = new m.Gpio(7);
myDigitalPin.dir(m.DIR_IN);

// Routes
app.get('/read', function (req, res) {
  var myDigitalValue =  myDigitalPin.read();
  res.send("Digital pin 7 value is: " + myDigitalValue...