Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼


Building an IoT Project with Intel Galileo and Node.js

Intel XDK IoT Edition provides an IDE that enables you to use JavaScript with Node.js to build Internet of Things (IoT) projects that target specific Intel boards and interact with Arduino shields and modules. In this first article of a two-part series on IoT solutions with Node.js, I explain how to configure an Intel Galileo Gen 2 board to work with the IDE and write JavaScript code that interacts with the device hardware.

Up and Running with the Board

You don't need to be an electronics engineer to develop IoT prototypes with an Intel Galileo Gen 2 board and the Intel XDK IoT Edition IDE. In fact, I'm going to use examples featuring JavaScript code and Node.js libraries that are easy to understand if you know any modern programming language. However, you should know at least some basics about embedded hardware: electronic components, power sources, digital I/O, analog-to-digital converters, pulse-width modulation (PWM), Universal Asynchronous Receiver/Transmitter (UART), breadboards, wiring, decoupling, input protection, sensors, and actuators. Without this basic knowledge, you should follow step-by-step tutorials very carefully while working with the board in order to reduce the risk of damaging it. A wire connected to the wrong place can harm the hardware.

Any previous experience with embedded systems platforms will make your path towards IoT prototyping much more direct. In addition, in order to interact with more complex devices or shields, you should know how the Inter-Integrated Circuit (I2C) bus and Serial Peripheral Interface (SPI) bus work. Some shields that you connect to the Galileo board require you to use either I2C or SPI buses to communicate with them, and the Node.js libraries provide only a high-level abstraction to send and receive messages through these buses. If you don't meet these knowledge requirements, don't worry — you can still read along and follow my examples. However, you will need to learn about those electronics and hardware topics before you actually start work on more complex IoT prototypes.

There are many starter kits that provide a collection of modules, which you can easily plug in to your Galileo board for rapid prototyping. I won't be working with additional modules, so the Intel Galileo Gen 2 board will be enough to run my examples. The Intel XDK IoT Edition IDE requires the board to boot a specific Yocto Linux meta distribution from a microSD card that must be plugged in to the board. The meta distribution includes additional libraries and resources that aren't included in the Yocto Linux available in the board when you unbox it without a microSD card. The specific meta distribution includes Intel IoT Development Kit software, Node.js, GCC, Python, and many Node.js hardware interface libraries, among other packages. Thus, the first thing you need to know is that you cannot unbox a board and start working with the IDE without a few additional steps and some configuration preliminaries.

Intel XDK IoT Edition is a free multiplatform IDE that runs on Windows, Mac OS X, and Linux. You must sign in with an Intel Developer Zone account in order to start working with the IDE. If you don't have an account, you can register for free when you start the IDE for the first time.

After you unbox an Intel Galileo Gen 2, you will find the following elements:

  • Intel Galileo Gen 2 board
  • 12 VDC, 1.5 A power supply

I initially worked with Intel XDK IoT Edition version 52 without updating the original on-board firmware. In some cases, you might need an update and it is a good idea to make sure that the board has the latest available firmware before you work with the IDE. Thus, it is necessary to follow the instructions explained here to use the Galileo Arduino IDE to update the onboard firmware to the latest available version. You must remove all the connections from the board and the microSD card before running the firmware update. You need to connect a USB Type A to Micro-B USB cable from your computer to the micro USB connector labeled as USB CLIENT in the board after the board has finished the boot process. Notice that you cannot power the board off USB. Just make sure you follow all the instructions explained to update the firmware in order to avoid damaging the board. (Sadly, the cable isn't included within the board's box.)

After you finish updating the on-board firmware and testing that it works correctly, make sure you disconnect the USB cable and unplug the board's power supply. There is still more work to be done before you start working with the IDE. You need the following additional elements that aren't included within the board's box:

  • A microSD card of at least 4GB with a maximum capacity of 32GB. It is convenient to use a speed class 4 or greater microSD card.
  • An Ethernet cable.
  • An Ethernet switch or a WiFi router with a free Ethernet port. (You will connect the board to your LAN.)

You need to download the latest version of the Yocto boot image (iot-devkit-latest-mmcblkp0.direct.bz2), decompress the downloaded image file, and write the extracted image (iot-devkit-latest-mmcblkp0.direct) to the microSD card. You can download the latest compressed boot image from the Intel repository.

For Windows, you can use 7-Zip to extract the contents from the bz2 file and Win32 Disk Imager to write the image to the microSD card.

For Mac OS X and Linux, you can use bunzip2 to extract the contents from the bz2 file, diskutil to unmount the microSD card, and dd to write the image to the microSD card. For example, the following dd command writes the image in the input file named iot-devkit-latest-mmcblkp0.direct to the previously unmounted microSD card in /dev/disk1. Be careful with the commands to avoid erasing the wrong device (such as your hard drive!):

sudo dd if=iot-devkit-latest-mmcblkp0.direct of=/dev/disk1 bs=8m

Note that it will quite a while to write the image to the microSD card. Wait until the command finishes and the terminal displays the prompt again before closing the terminal window.

Make sure that the board is unplugged and place the microSD card with the Yocto image in the microSD card slot on the board (see Figure 1). Next, connect the board to your LAN with the Ethernet cable and plug in the board's power supply to turn on the board and start it up. You will notice the onboard LED labeled SD indicates that there is activity with the microSD card. Wait approximately 1 minute to make sure that the board finishes the boot process. The LED labeled SD will stop blinking after the boot process finished.

IoT with Intel Galileo
Figure 1: An Intel Galileo Gen 2 board with the microSD card and connected to a LAN with an Ethernet cable.

Configuring the IDE

Now, launch Intel XDK IoT edition. At the bottom of the window, you will find a panel with a dropdown, labeled IoT Device, and a few buttons. The following list shows the commands for each of these controls from left to right (see Figure 2). I will use the command names included in this list in my explanations.

  • IoT device dropdown.
  • Upload.
  • Install/Build.
  • Stop.
  • Run.
  • Debug.
  • Manage your daemon/IoT device.
  • Toggle console window.

Figure 2: The IDE control located at the bottom of the main window.

Click on Toggle console window. You will be able to check what the IDE is doing when you execute the different commands and interact with the board. You will see two new buttons at the right-hand side of the bottom panel that allow you to copy the console contents and clear the output.

After the board finished booting, it will be running the Intel XDK app daemon. The IDE uses Bonjour, also known as short for Zero-configuration networking (Zeroconf ), which is a multicast DNS service to automatically detect the compatible devices connected on the LAN. In Windows, you can download and install Bonjour here. However, you might have problems in certain versions, such as Windows 8.1. If you have trouble, you can use the Bonjour Browser developed by Hobbyist Software for Windows to discover the board's assigned IP. In Mac OS X, you can use the Bonjour Browser application developed by Kevin Ballard for Mac OS X to achieve the same goal.

Click on the IoT device dropdown. If you don't see an IP address and a port after a separator, click [%] Rescan for devices and the IDE will try to find the device in the network. If you see an IP address and a port (the default port is 58888), select it and the IDE will display a dialog box indicating that it can establish a connection with the Galileo Gen 2 board (the device).

If you don't see the device listed, make sure you've waited the necessary time to let the process finish. If you cannot see the device IP listed after rescanning for devices, you can use the MAC address included in a label on the board's Ethernet port, and check your DHCP client list to obtain the IP address assigned to the board. Your LAN administrator might help if you are using a corporate LAN. Then, click on the IoT device dropdown, select [+] Add Manual Connection and enter the IP address and the port number. Remember that the default port for the Intel XDK app daemon is 58888. Once you know the IP address, you can use a terminal to connect, run ssh, and log in to the remote device. The root user doesn't have a password.

Make sure the device is selected in the IoT device dropdown. Then, click Manage your daemon/IoT device | Set IoT device name/alias and enter the desired alias to easily identify your board. The IDE will display the alias to identify your board within the IoT device dropdown.

Click Manage your daemon/IoT device | Sync PC time with clock on target device. Notice that the IDE will display information about the latest command after it finishes in the console window.

Click Manage your daemon/IoT device and activate the following checkboxes below Build Settings. This way, whenever you deploy any new node module added to the package, it is going to be installed on the board.

  • Clean node_modules before building
  • Run npm install directly on IoT Device (requires Internet connection on device)

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.