(Updated) Control your Intel Edison in Realtime with Websockets!
Published: 2020-08-22 19:18:07

***(Note: these posts are migrated from my previous [medium.com](https://medium.com/@monkeytypewritr) blog)***

The Intel Edison is an excellent platform for prototyping your next IoT project. This small little device is powered by an Intel® Atom™ SoC dual-core CPU and includes an integrated WiFi, Bluetooth LE module. In this tutorial, we will go over the “Hello World” equivalent to get started with the Intel Edison: Blinking an LED. We will then take it one step further and control the LED with a web interface via Websockets. Lets go!

### 1. Setting up your Intel Edison Board

For this tutorial, we will be using the Intel® Edison and Arduino Breakout Kit. To assemble and setup your Intel Edison board, you can follow this guide here: [https://communities.intel.com/docs/DOC-23147](https://communities.intel.com/docs/DOC-23147) .

This is an important step as we’ll need Internet connectivity to download all the necessary libraries, as well as communicating with the outside world (The I in IoT!). Check your connectivity by visiting its IP address once Wi-Fi has been setup:

![Once Wi-Fi has been setup, visit the IP address of the Intel Edison.](https://cdn-images-1.medium.com/max/3032/1*xiuj-oED_s0Yvll9tfnAPA.png)

![Visiting the IP address in a browser should show a configuration page](https://cdn-images-1.medium.com/max/6204/1*bhLutTBptyQ-iCYB7uu2Qw.png)

*Note: After the Wi-Fi configuration was complete, the configuration page did not load for me when I visited the IP address in the browser. I had to manually start the server on the Intel Edison by entering the following command in the terminal:*

    configure_edison --server

### 2. Interfacing with the board I/O pins

The Intel Edison Arduino breakout board has 20 I/O pins, 6 of which are Analog, and 14 of which are digital. These can be used for any sensor inputs (i.e. potentiometers, photodiodes, temperature, etc.) or outputs (e.g. controlling motors/servos with a PWM signal with the digital pins). The following table lists the I/O pins and their numbers:

![](https://cdn-images-1.medium.com/max/2204/1*MkPsSQqRid0wMO0R7Qw_bw.png)

To interface with these I/O pins, we will need to install a library that provides us with an API. Intel provides a library for its IoT dev boards called **MRAA, **which is a “Low Level Skeleton Library for IO Communication on GNU/Linux platforms”. The library is open source and is available on github: [https://github.com/intel-iot-devkit/mraa](https://github.com/intel-iot-devkit/mraa)

Installing the library is simply running these commands on the Intel Edison:

    echo "src mraa-upm http://iotdk.intel.com/repos/1.1/intelgalactic" > /etc/opkg/mraa-upm.conf
    opkg update
    opkg install libmraa0

![](https://cdn-images-1.medium.com/max/2408/1*VE5lwvK9gBOAIhSNdAk0oQ.png)

Once the library has been installed, try running the blinking LED example found in the github repo:

{% gist https://gist.github.com/w4ilun/6ed2976d71d8f48e760d %}

 1. Save the above snippet to a file (e.g. blink.js)

 2. Run it with Node!

        node blink.js

![Hurray!](https://cdn-images-1.medium.com/max/2000/1*RKczEGE4OyxMOySE5X4FXg.gif)

### 3. Installing Express/Socket.IO for Websocket communication

We’ll be installing the **Express** and **Socket.IO** libraries to allow Websocket communication with our Intel Edison. **Express** is a web framework for NodeJS, it will be serving our static assets (web page with control interface) and provide an HTTP server instance. **Socket.IO **will be the Websocket library of choice.

 1. Install these libraries by running the following commands (the save flag adds these libraries to the package.json file):

        npm install express --save
        npm install socket.io --save

2. Create and save the following two code snippets in the same directory:

***blinkWithSockets.js***

{% gist https://gist.github.com/w4ilun/41b9959e98f3eeac5aa6 %} 

***index.html***

{% gist https://gist.github.com/w4ilun/ae5445bec820d086ef7b %}

*Note: Remember to replace your IP address in index.html. Also, feel free to use any port other than 3000.*

3. Run the code and visit your browser:

        node blinkWithSockets.js

![](https://cdn-images-1.medium.com/max/6204/1*pGYmrweL7twwjjiAUx0Cdw.png)

4. Move the slider around and see the LED blink faster and slower!

![](https://cdn-images-1.medium.com/max/2000/1*w8pG2bJz9MqKNIDf4sUT8g.gif)

5. *Please see this [post](https://medium.com/p/529d50ac3fd3) on how to control your device from outside your LAN!*

And that’s it! With the current setup, you can send data to your Intel Edison via Websockets. The Socket.IO library allows bi-directional communication, which means you can also relay sensor data from the I/O pins back to the client in real-time as well! In a future tutorial, I will describe how this can be accomplished and perhaps integrate with a third party API as well.

Please feel free to reach out for any questions or suggestions ☺