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

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