Book Image

Intel Galileo Blueprints

By : Marco Schwartz
Book Image

Intel Galileo Blueprints

By: Marco Schwartz

Overview of this book

Table of Contents (19 chapters)
Intel Galileo Blueprints
About the Author
About the Reviewers
Free Chapter
Setting Up the Galileo Board and the Development Environment

Writing the code for the project

We will now look at the code for the project. Once again, we will use Node.js as the base of our application, and we will code it inside the Intel XDK software that we already used in previous chapters.

Here is the complete code for this part:

// Includes
var mraa = require("mraa");
var util = require('util');

// Sensors & relay pins
var light_sensor_pin = new mraa.Aio(0);

var motion_sensor_pin = new mraa.Gpio(8);

var relay_pin = new mraa.Gpio(7);

// PubNub client
var pubnub = require("pubnub")({
    ssl           : true,  // <- enable TLS Tunneling over TCP
    publish_key   : "your_publish_key",
    subscribe_key : "your_subscribe_key"

// Function to publish light level
function send_light_level() {

  // Measure light level
  var a =;
  var light_level = a/1024*100;
  light_level = light_level.toPrecision(4);

  // Send it to PubNub
  var message = {...