Skip to main content
All CollectionsConnect your Devices
Connect an Intel Edison to Ubidots over MQTT
Connect an Intel Edison to Ubidots over MQTT

Learn to setup and connect the Intel Edison to Ubidots over MQTT using the simplicity of the Arduino IDE.

Sergio M avatar
Written by Sergio M
Updated over 3 months ago

The Intel Edison is a tiny computer-on-module offered by Intel as a development system for the Internet of Things (IoT) Applications. The Edison features a dual-core Intel Quark x86 CPU at 400 MHz and communicates via Bluetooth and Wi-Fi. 

The Intel Edison offers an Arduino KIT with standard Arduino 1.0 pinouts and standard connectors and specifically designed to be compatible with hardware or software using the Arduino Uno R3 Shield.

This step-by-step guide will help you to:

  1. Assemble and connect cables to your Intel® Edison board.

  2. Run the setup tool to install USB drivers and flash to your Intel® Edison board's firmware.

  3. Set a device password and connect your development board to Wi-Fi.

  4. Collect, analyze, and organize your Ubidots dashboard for device and data management.

Requirements

The Intel® Edison compute module is meant to be used with a breakout board and is typically bought together with a kit containing the compute module and a breakout board.

Requirements:

  • Intel® Edison compute module

  • Arduino* expansion board

  • Micro-B USB to Standard-B USB cables (x 2)

  • Direct current (DC) power supply (see specs)

Step-by-Step

  1. Setting up the Intel Edison

  2. Setting the Arduino IDE

  3. Sending (PUBLISH) Data to Ubidots

  4. Receiving (SUBSCRIBE) Data from Ubidots

  5. Summary

1. Setting up the Intel Edison

  1. Assemble the Intel Edison Board. With the following link you will find all the specifications to assemble your hardware properly. 

2. Download the latest configuration tool for your Operating System (OS) to access the features of the Intel® IoT Developer Kit. 

3. Accept the terms of the license and follow step-by-step the instructions of the configurations tool.

4. Install the USB drivers.

IMPORTANT NOTE: The drivers allow your computer to recognize the boards as devices. For this reason, be sure all the driver are properly installed.  

5. Download the latest firmware and flash it to your Intel Edison. This will take a few minutes - please be patient.

 6. Once the download is finished, the below window should appear. Please ensure your board is properly connected to your PC and power to allow the flash and reboot.

7. Set a device name and password to enable SHH. A guide is not needed for this step, simply follow the on-screen setup.

8. Connect your board to Wi-Fi. The board will scan for the available networks and show you any detected networks. Select the one you wish to use; select the security of the network, and enter the Wi-Fi credentials and password. If you change any wifi setting, do not forget to write them down for next time you need them. 

9. Once your device is connected to the network, you will be provided with the IP address of the device.

10. Verify that all configurations are checked, and therefore completed. Click on the “Finish” button once confirmed. 

2. Setting up Arduino IDE 

1. Open the Arduino IDE, if you don’t have the IDE you can quickly download the latest version of Arduino's IDE here

2. To be able to work with the Intel platform in the Arduino IDE, you will need to install the Intel platform using the preconfigured Arduino Board Manager. If you are not familiar with adding a board with the Arduino IDE, please refer to this article for additional guidance.

  • Intel Platform to be installed:  Intel i868 Boards - Edison

3.  With the Intel platform installed, select the Intel device you are working with. In this case, we are working with a “Intel Edison”. To select your board from the Arduino IDE, select Tools > Board Intel Edison”. Then, select the board and choose the COM port assigned to the board.

4. Download and install the PubSubClient library. The library can be found in  the following link.

To learn how to install libraries using the Arduino IDE, refer to this guide.  

3. Sending (PUBLISH) Data to Ubidots

With the following sample code you will be able to post readings taken from ANALOG pins A0 and A1 of the Intel Edison Arduino Kit to your Ubidots account.

1. To post your first value in Ubidots, open the Arduino IDE and paste the sample code below. Once you have pasted the code, you will need to assign your unique Ubidots TOKEN, SSID (WiFi Name), and the Password of the available network. 

/****************************************
 * Include Libraries
 ****************************************/
#include <PubSubClient.h>
#include <SPI.h>
#include <WiFi.h>

/****************************************
 * Define Your Wi-Fi crendetials
 ****************************************/
char ssid[] = "xxxxx"; //  Your network SSID (name)
char password[] = "xxxxx";    // Your network password (use for WPA, or use as key for WEP)

/****************************************
 * Define Constants
 ****************************************/
#define TOKEN "xxxxx" // Your Ubidots TOKEN
#define DEVICE_LABEL "edison" // Your device label
#define VARIABLE_LABEL_1 "sensor-1"// Your variable label (1)
#define VARIABLE_LABEL_2 "sensor-2"// Your variable label (2)

#define MQTT_SERVER "industrial.api.ubidots.com"
#define sensor1 A0
#define sensor2 A1

char topic[150];

float sensorValue1;
float sensorValue2;

WiFiClient wifiClient;
PubSubClient client(wifiClient);

/****************************************
 * Auxiliar Functions
 ****************************************/
void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i=0;i<length;i++) {
    Serial.print((char)payload[i]);
  }
}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.println("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("intel-edison", TOKEN,"")) {
      Serial.println("connected");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 2 seconds");
      // Wait 2 seconds before retrying
      delay(2000);
    }
  }
}

/****************************************
 * Main Functions
 ****************************************/
void setup() {
    Serial.begin(115200);
    pinMode(sensor1, INPUT);
    pinMode(sensor2, INPUT);
    pinMode(RELAY, OUTPUT);
    delay(10);
   
     // We start by connecting to a WiFi network
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);
 
    WiFi.begin(ssid, password);
 
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
 
    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    client.setServer(MQTT_SERVER, 1883);
    client.setCallback(callback);
    sprintf(topic, "%s%s", "/v1.6/devices/", DEVICE_LABEL);    

}

void loop() {
    if (!client.connected()) {
      reconnect();
    }
    char* payload = (char *) malloc(sizeof(char) * 100);
    sensorValue1 = analogRead(sensor1);
    sensorValue2 = analogRead(sensor2);
   
    sprintf(payload, "{\"%s\": %f}", VARIABLE_LABEL_1, sensorValue1);    
    client.publish(topic, payload);
    //Serial.println((topic, payload));
    Serial.print("Sensor Value 1: ");
    Serial.println(sensorValue1);
     
    sprintf(payload, "{\"%s\": %f}", VARIABLE_LABEL_2, sensorValue2);    
    client.publish(topic, payload);
    //Serial.println((topic, payload));    
    Serial.print("Sensor Value 2: ");
    Serial.println(sensorValue2);

    free(payload);
    client.loop();
    delay(5000);
}

2. Verify your code within the Arduino IDE. To do this, in the top left corner of our Arduino IDE you will see the "Check Mark" icon; press it to verify your code. 

3. Upload the code into your “Intel Edison”. To do this, choose the "right-arrow" icon beside the "check mark" icon. 

4. To verify the connectivity of the device and the data sent, open the serial monitor by selecting the "magnifying glass" icon in the top right corner of the Arduino IDE to see the connectivity logs.

5. Confirm your data in Ubidots. Now you should see the posted data in your Ubidots account, located the device called "edison". 

4. Receiving (SUBSCRIBE) Data from Ubidots

With the following sample code you will be able to subscribe to a value from Ubidots to start controlling any asset you desire. 

1. To begin receiving values from Ubidots, open the Arduino IDE and paste the sample code below. Once you have pasted the code, be sure to assign the following parameters:

/****************************************
 * Include Libraries
 ****************************************/
#include <PubSubClient.h>
#include <SPI.h>
#include <WiFi.h>

/****************************************
 * Define Your Wi-Fi crendetials
 ****************************************/
char ssid[] = "xxxxx"; //  Your network SSID (name)
char password[] = "xxxxx";    // Your network password (use for WPA, or use as key for WEP)

/****************************************
 * Define Constants
 ****************************************/
#define TOKEN "xxxxx" // Your Ubidots TOKEN
#define DEVICE_LABEL "edison" // Your device label
#define VAR_SUBSCRIBE "relay" // Your variable label for subscribing
#define MQTT_SERVER "industrial.api.ubidots.com"
#define RELAY 3

char topic[150];

WiFiClient wifiClient;
PubSubClient client(wifiClient);

/****************************************
 * Auxiliar Functions
 ****************************************/
void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i=0;i<length;i++) {
    Serial.print((char)payload[i]);
  }
  if ((char)payload[0]=='1'){
    digitalWrite(RELAY, HIGH);
  }
  else{
    digitalWrite(RELAY, LOW);
  }
}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.println("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("intel-edison", TOKEN,"")) {
      Serial.println("connected");
      client.subscribe("/v1.6/devices/"DEVICE_LABEL"/"VAR_SUBSCRIBE"/lv");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 2 seconds");
      // Wait 2 seconds before retrying
      delay(2000);
    }
  }
}

/****************************************
 * Main Functions
 ****************************************/
void setup() {
    Serial.begin(115200);
    pinMode(RELAY, OUTPUT);
    delay(10);
   
     // We start by connecting to a WiFi network
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);
 
    WiFi.begin(ssid, password);
 
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    client.setServer(MQTT_SERVER, 1883);
    client.setCallback(callback);
    sprintf(topic, "%s%s", "/v1.6/devices/", DEVICE_LABEL);    
    client.subscribe("/v1.6/devices/"DEVICE_LABEL"/"VAR_SUBSCRIBE"/lv");

}

void loop() {
    if (!client.connected()) {
      reconnect();
      client.subscribe("/v1.6/devices/"DEVICE_LABEL"/"VAR_SUBSCRIBE"/lv");
    }
    client.loop();
}

2. Verify & Upload the code into the board following the same steps provided in the PUBLISH step above.

3. To verify the connectivity of the device and the data which is being received, open the serial monitor by selecting the "magnifying glass" icon in the top right corner of the Arduino IDE to see the connectivity logs. 

4. In the serial monitor, you will be able to see the last value received in Ubidots of the variable specified in the firmware.

5. Summary

With this simple tutorial you are able to PUBLISH & SUBSCRIBE data to/from Ubidots with the ease of the Arduino IDE and an Intel Edison. If you desire publish & subscribe at the same time, you can refer to this sample code.  

Now its time to create Ubidots Dashboards to visualize your data and deploy your IoT solution!  Happy Hacking! :) 

Other readers have also found useful...

Did this answer your question?