Connect Intel Edison to Azure IoT Hub (Node.js)

In this tutorial, you begin by learning the basics of working with Intel Edison. You then learn how to seamlessly connect your devices to the cloud by using Azure IoT Hub.

Don't have a kit yet? Start here

What you do

  • Setup Intel Edison and and Grove modules.
  • Create an IoT hub.
  • Register a device for Edison in your IoT hub.
  • Run a sample application on Edison to send sensor data to your IoT hub.

Connect Intel Edison to an IoT hub that you create. Then you run a sample application on Edison to collect temperature and humidity data from a Grove temperature sensor. Finally, you send the sensor data to your IoT hub.

What you learn

  • How to create an Azure IoT hub and get your new device connection string.
  • How to connect Edison with a Grove temperature sensor.
  • How to collect sensor data by running a sample application on Edison.
  • How to send sensor data to your IoT hub.

What you need

What you need

  • The Intel Edison board
  • Arduino expansion board
  • An active Azure subscription. If you don't have an Azure account, create a free Azure trial account in just a few minutes.
  • A Mac or a PC that is running Windows or Linux.
  • An Internet connection.
  • A Micro B to Type A USB cable
  • A direct current (DC) power supply. Your power supply should be rated as follows:
    • 7-15V DC
    • At least 1500mA
    • The center/inner pin should be the positive pole of the power supply

The following items are optional:

  • Grove Base Shield V2
  • Grove - Temperature Sensor
  • Grove Cable
  • Any spacer bars or screws included in the packaging, including two screws to fasten the module to the expansion board and four sets of screws and plastic spacers.
Note

These items are optional because the code sample support simulated sensor data.

Create an IoT hub

  1. In the Azure portal, click New > Internet of Things > IoT Hub.

    Create an IoT hub in the Azure portal

  2. In the IoT hub pane, enter the following information for your IoT hub:

    Name: Enter the name of your IoT hub. If the name you enter is valid, a green check mark appears.

    Pricing and scale tier: Select the F1 - Free tier. This option is sufficient for this demo. For more information, see the Pricing and scale tier.

    Resource group: Create a resource group to host the IoT hub or use an existing one. For more information, see Use resource groups to manage your Azure resources.

    Location: Select the closest location to you where the IoT hub is created.

    Pin to dashboard: Select this option for easy access to your IoT hub from the dashboard.

    Enter information to create your IoT hub

    Important

    The IoT hub will be publicly discoverable as a DNS endpoint, so make sure to avoid any sensitive information while naming it.

  3. Click Create. Your IoT hub might take a few minutes to create. You can see progress in the Notifications pane.

    See progress notifications for your IoT hub

  4. After your IoT hub is created, click it on the dashboard. Make a note of the Hostname, and then click Shared access policies.

    Get the hostname of your IoT hub

  5. In the Shared access policies pane, click the iothubowner policy, and then copy and make a note of the Connection string of your IoT hub. For more information, see Control access to IoT Hub.

Note

You will not need this iothubowner connection string for this set-up tutorial. However, you may need it for some of the tutorials on different IoT scenarios after you complete this set-up.

Get your IoT hub connection string

Register a device in the IoT hub for your device

  1. In the Azure portal, open your IoT hub.

  2. Click Device Explorer.

  3. In the Device Explorer pane, click Add to add a device to your IoT hub. Then do the following:

    Device ID: Enter the ID of the new device. Device IDs are case sensitive.

    Authentication Type: Select Symmetric Key.

    Auto Generate Keys: Select this check box.

    Connect device to IoT Hub: Click Enable.

    Add a device in the Device Explorer of your IoT hub

    Important

    The device ID may be visible in the logs collected for customer support and troubleshooting, so make sure to avoid any sensitive information while naming it.

  4. Click Save.

  5. After the device is created, open the device in the Device Explorer pane.
  6. Make a note of the primary key of the connection string.

    Get the device connection string

Setup Intel Edison

Assemble your board

This section contains steps to attach your Intel® Edison module to your expansion board.

  1. Place the Intel® Edison module within the white outline on your expansion board, lining up the holes on the module with the screws on the expansion board.

  2. Press down on the module just below the words What will you make? until you feel a snap.

    assemble board 2

  3. Use the two hex nuts (included in the package) to secure the module to the expansion board.

    assemble board 3

  4. Insert a screw in one of the four corner holes on the expansion board. Twist and tighten one of the white plastic spacers onto the screw.

    assemble board 4

  5. Repeat for the other three corner spacers.

    assemble board 5

Now your board is assembled.

assembled board

Connect the Grove Base Shield and the temperature sensor

  1. Place the Grove Base Shield on to your board. Make sure all pins are tightly plugged into your board.

    Grove Base Shield

  2. Use Grove Cable to connect Grove temperature sensor onto the Grove Base Shield A0 port.

    Connect to temperature sensor

    Edison and sensor connection

Now your sensor is ready.

Power up Edison

  1. Plug in the power supply.

    Plug in power supply

  2. A green LED(labeled DS1 on the Arduino* expansion board) should light up and stay lit.

  3. Wait one minute for the board to finish booting up.

    Note

    If you do not have a DC power supply, you can still power the board through a USB port. See Connect Edison to your computer section for details. Powering your board in this fashion may result in unpredictable behavior from your board, especially when using Wi-Fi or driving motors.

Connect Edison to your computer

  1. Toggle down the microswitch towards the two micro USB ports, so that Edison is in device mode. For differences between device mode and host mode, please reference here.

    Toggle down the microswitch

  2. Plug the micro USB cable into the top micro USB port.

    Top micro USB port

  3. Plug the other end of USB cable into your computer.

    Computer USB

  4. You will know that your board is fully initialized when your computer mounts a new drive (much like inserting a SD card into your computer).

Download and run the configuration tool

Get the latest configuration tool from this link listed under the Installers heading. Execute the tool and follow its on-screen instructions, clicking Next where needed

Flash firmware

  1. On the Set up options page, click Flash Firmware.
  2. Select the image to flash onto your board by doing one of the following:
    • To download and flash your board with the latest firmware image available from Intel, select Download the latest image version xxxx.
    • To flash your board with an image you already have saved on your computer, select Select the local image. Browse to and select the image you want to flash to your board.
  3. The setup tool will attempt to flash your board. The entire flashing process may take up to 10 minutes.

Set password

  1. On the Set up options page, click Enable Security.
  2. You can set a custom name for your Intel® Edison board. This is optional.
  3. Type a password for your board, then click Set password.
  4. Mark down the password, which is used later.

Connect Wi-Fi

  1. On the Set up options page, click Connect Wi-Fi. Wait up to one minute as your computer scans for available Wi-Fi networks.
  2. From the Detected Networks drop-down list, select your network.
  3. From the Security drop-down list, select the network's security type.
  4. Provide your login and password information, then click Configure Wi-Fi.
  5. Mark down the IP address, which is used later.
Note

Make sure that Edison is connected to the same network as your computer. Your computer connects to your Edison by using the IP address.

Connect to temperature sensor

Congratulations! You've successfully configured Edison.

Run a sample application on Intel Edison

Prepare the Azure IoT Device SDK

  1. Use one of the following SSH clients from your host computer to connect to your Intel Edison. The IP address is from the configuration tool and the password is the one you've set in that tool.

    • PuTTY for Windows.
    • The built-in SSH client on Ubuntu or macOS.
  2. Clone the sample client app to your device.

    git clone https://github.com/Azure-Samples/iot-hub-node-intel-edison-client-app
    
  3. Then navigate to the repo folder to run the following command to install all packages, it may take serval minutes to complete.

    cd iot-hub-node-intel-edison-client-app
    npm install
    

Configure and run the sample application

  1. Open the config file by running the following commands:

    nano config.json
    

    Config file

    There are two macros in this file you can configurate. The first one is INTERVAL, which defines the time interval between two messages that send to cloud. The second one simulatedData,which is a Boolean value for whether to use simulated sensor data or not.

    If you don't have the sensor, set the simulatedData value to true to make the sample application create and use simulated sensor data.

  2. Save and exit by pressing Control-O > Enter > Control-X.

  3. Run the sample application by running the following command:

    sudo node index.js '<your Azure IoT hub device connection string>'
    
    Note

    Make sure you copy-paste the device connection string into the single quotes.

You should see the following output that shows the sensor data and the messages that are sent to your IoT hub.

Output - sensor data sent from Intel Edison to your IoT hub

Next steps

You’ve run a sample application to collect sensor data and send it to your IoT hub.

To continue to get started with Azure IoT Hub and to explore other IoT scenarios, see the following: