Azure-Samples / iot-hub-node-intel-edison-getstartedkit

Get started with Intel Edison Azure IoT Starter Kit
MIT License
7 stars 19 forks source link

Get Started with Microsoft Azure IoT Starter Kit - Intel Edison

Note: this article has been archived and it is not longer updated. Instructions may not be totally up to date.

This page contains technical information to help you get familiar with Azure IoT using the Azure IoT Starter Kit - Intel Edison. You will find two tutorials that will walk you through different scenarios. The first tutorial will show you how to connect your Azure IoT Starter kit to our Remote Monitoring preconfigured solution from Azure IoT Suite. In the second tutorial, you will leverage Azure IoT services to create your own IoT solution.

You can choose to start with whichever tutorial you want to. If you've never worked with Azure IoT services before, we encourage you to start with the Remote Monitoring solution tutorial, because all of the Azure services will be provisioned for you in a built-in preconfigured solution. Then you can explore how each of the services work by going through the second tutorial.

We hope you enjoy the tutorials! Please provide feedback if there's anything that we can improve.


Don't have a kit yet?: Click here


Running a Simple Remote Monitoring Solution with the Intel Edison

This tutorial describes the process of taking your Intel Edison Grove kit, and using it to develop a temperature, humidity and pressure reader that can communicate with the cloud using the  Microsoft Azure IoT SDK. 

Table of Contents

1.1 Tutorial Overview

In this tutorial, you'll be doing the following:

  • Setting up your environment on Azure using the Microsoft Azure IoT Suite Remote Monitoring preconfigured solution, getting a large portion of the set-up that would be required done in one step.
  • Setting your device and sensors up so that it can communicate with both your computer, and Azure IoT.
  • Updating the device code sample to include our connection data and send it to Azure to be viewed remotely.

1.2 Before Starting

1.2.1 Required Software

1.2.2 Required Hardware

  • Intel Edison Grove kit
    • Two USB Mini cables

1.3 Create a New Azure IoT Suite Remote Monitoring solution and Add Device


Note: For first time users, click here to get your Azure free trial which gives you 200USD of credit to get started.



Note: Make sure to copy down the names and connection strings mentioned into a text document for reference later.



Note: You may be asked to log back in. This is to ensure your solution has proper permissions associated with your account.



Warning: The Remote Monitoring solution provisions a set of Azure IoT Services in your Azure account. It is meant to reflect a real enterprise architecture and thus its Azure consumption is quite heavy. To avoid unnecessary Azure consumption, we recommend you delete the preconfigured solution in azureiotsuite.com once you are done with your work (since it is easy to recreate). Alternatively, if you want to keep it up and running you can do several things to reduce consumption:

1) Visit this guide to run the solution in demo mode and reduce the Azure consumption.

2) Disable the simulated devices created with the solution (Go to Devices>>Select the device>> on the device details menu on the right, clich on Disable Device. Repeat with all the simulated devices).

3) Stop your remote monitoring solution while you are working on the next steps. (See: Troubleshooting)


If this is the first time you use your Intel Edison board, you will have to follow some steps to assemble it.

1.5 Connect the Grove Sensor Module to your Device

Edison Port Component
A0 Temperature

At the end of your work, your Intel Edison should be connected with a working sensor. We'll test it in the next sections.

1.6 Modify, build and run the Remote Monitoring sample

  • In your Edison boards command line, type the following command to transfer the files to your board:
wget https://raw.githubusercontent.com/Azure-Samples/iot-hub-node-intel-edison-getstartedkit/master/remote_monitoring/remote_monitoring.js
wget https://raw.githubusercontent.com/Azure-Samples/iot-hub-node-intel-edison-getstartedkit/master/remote_monitoring/package.json
  • Open the file remote_monitoring.js in a text editor using the command:
nano remote_monitoring.js
  • Nano is generally not installed with Yocto build. If you don't have it installed already, here are the instructions to install nano on your intel edision:
mkdir nano-installer
cd nano-installer
wget http://www.nano-editor.org/dist/v2.2/nano-2.2.6.tar.gz 
tar xvf nano-2.2.6.tar.gz 
cd nano-2.2.6 
./configure && make && make install
  • Locate the following code in the file and update your connection data:
var hostName = '<IOTHUB_HOST_NAME>';
var deviceId = '<DEVICE_ID>';
var sharedAccessKey = '<SHARED_ACCESS_KEY>';
  • Save your changes by pressing Ctrl+O and when nano prompts you to save it as the same file, just press ENTER.

  • Press Ctrl+X to exit nano.

  • Run the sample application using the following commands:

npm install
node remote_monitoring.js

1.7 View the Sensor Data from the Remote Monitoring Portal

  • Once you have the sample running, visit your dashboard by visiting azureiotsuite.com and clicking “Launch” on your solution
  • Make sure the “Device to View” in the upper right is set to your device
  • If the demo is running, ou should see an output on your command window that shows your device details and the sensor data. Also, check out how the graph changes in real time as your data updates!

Note: Make sure you delete or stop your remote monitoring solution once you have completed this to avoid unnecesary Azure consumption! Check out the troubleshooting section for more details.


1.8 Next steps

Please visit our Azure IoT Dev Center for more samples and documentation on Azure IoT.

Using Microsoft Azure IoT Services to Identify Temperature Anomalies

This tutorial describes the process of taking your Microsoft Azure IoT Starter Kit for the Intel Edison, and using it to develop a temperature and humidity reader that can communicate with the cloud using the Microsoft Azure IoT SDK.

Table of Contents

2.1 Tutorial Overview

This tutorial has the following steps:

  • Provision an IoT Hub instance on Microsoft Azure and adding your device.
  • Prepare the device, get connected to the device, and set it up so that it can read sensor data.
  • Configure your Microsoft Azure IoT services by adding Event Hub, Storage Account, and Stream Analytics resources.
  • Prepare your local web solution for monitoring and sending commands to your device.
  • Update the sample code to respond to commands and include the data from our sensors, sending it to Microsoft Azure to be viewed remotely.

The end result will be a functional command center where you can view the history of your device's sensor data, a history of alerts, and send commands back to the device.

2.2 Before Starting

2.2.1 Required Software

2.2.2 Required Hardware

  • Intel Edison Grove kit
    • Two USB Mini cables

2.3 Connect the Sensor Module to your Device

Edison Port Component
A0 Temperature
D8 LED Socket Kit

At the end of your work, your Intel Edison should be connected with a working sensor. We'll test it in the next sections.

2.4 Create a New Microsoft Azure IoT Hub and Add Device


Note: Make sure to copy down the names and connection strings mentioned into a text document for reference later.


2.5 Create an Event Hub

Event Hub is an Azure IoT publish-subscribe service that can ingest millions of events per second and stream them into multiple applications, services or devices.

2.6 Create a Storage Account for Table Storage

Now we will create a service to store our data in the cloud.

2.7 Create a Stream Analytics job to Save IoT Data in Table Storage and Raise Alerts

Stream Analytics is an Azure IoT service that streams and analyzes data in the cloud. We'll use it to process data coming from your device.

SELECT
    DeviceId,
    EventTime,
    MTemperature as TemperatureReading
INTO
    TemperatureTableStorage
from TempSensors
WHERE
   DeviceId is not null
   and EventTime is not null

SELECT
    DeviceId,
    EventTime,
    MTemperature as TemperatureReading
INTO   
    TemperatureAlertToEventHub
FROM
    TempSensors
WHERE MTemperature > 25 

Note: You can change the 25 to 0 when you're ready to generate alerts to look at. This number represents the temperature in degrees celsius to check for when creating alerts. 25 degrees celsius is 77 degrees fahrenheit.



Note: Make sure to stop your Command Center jobs once you have when you take a break or finish to avoid unnecessary Azure consumption! (See: Troubleshooting)


2.8 Node Application Setup

sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
git clone https://github.com/Azure-Samples/iot-hub-node-intel-edison-getstartedkit.git
npm install -g bower
npm install
bower install
{
    "port": "3000",
    "eventHubName": "event-hub-name",
    "ehConnString": "Endpoint=sb://name.servicebus.windows.net/;SharedAccessKeyName=readwrite;SharedAccessKey=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=",
    "deviceId": "iot-hub-device-name",
    "iotHubConnString": "HostName=iot-hub-name.azure-devices.net;SharedAccessKeyName=service;SharedAccessKey=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=",
    "storageAcountName": "aaaaaaaaaaa",
    "storageAccountKey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa==",
    "storageTable": "TemperatureRecords"
} 
node server.js

To deploy this project to the cloud using Azure, you can reference Creating a Node.js web app in Azure App Service.

Next, we will update your device so that it can interact with all the things you just created.

2.9 Modify Device Sample

  • In your Edison boards command line, type the following command to transfer the files to your board:
wget https://raw.githubusercontent.com/Azure-Samples/iot-hub-node-intel-edison-getstartedkit/master/command_center/command_center.js
wget https://raw.githubusercontent.com/Azure-Samples/iot-hub-node-intel-edison-getstartedkit/master/command_center/package.json
  • Open the file command_center.js in a text editor using the command:
nano command_center.js
  • Nano is generally not installed with Yocto build. If you don't have it installed already, here are the instructions to install nano on your intel edision:
mkdir nano-installer
cd nano-installer
wget http://www.nano-editor.org/dist/v2.2/nano-2.2.6.tar.gz 
tar xvf nano-2.2.6.tar.gz 
cd nano-2.2.6 
./configure && make && make install
var connectionString = '<IOT_HUB_DEVICE_CONNECTION_STRING>';
npm install
node command_center.js

2.10 View Your Command Center Application

Head back to your Node application and you will have a fully functional command center, complete with a history of sensor data, alerts that display when the temperature got outside a certain range, and commands that you can send to your device remotely.


Note: Make sure to stop your Command Center jobs once you have when you finish to avoid unnecessary Azure consumption! (See: Troubleshooting)


2.11 Next steps

Please visit our Azure IoT Dev Center for more samples and documentation on Azure IoT.

Troubleshooting

Stopping Provisioned Services