title | description | services | documentationcenter | author | manager | tags | keywords | ms.assetid | ms.service | ms.devlang | ms.topic | ms.tgt_pltfrm | ms.workload | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Use an IoT gateway to connect a device to Azure IoT Hub | Microsoft Docs |
Learn how to use Intel NUC as an IoT gateway to connect a TI SensorTag and send sensor data to Azure IoT Hub in the cloud. |
iot-hub |
shizn |
timlt |
iot gateway connect device to cloud |
cb851648-018c-4a7e-860f-b62ed3b493a5 |
iot-hub |
c |
article |
na |
na |
06/25/2017 |
xshi |
Note
Before you start this tutorial, make sure you've completed Set up Intel NUC as an IoT gateway. In Set up Intel NUC as an IoT gateway, you set up the Intel NUC device as an IoT gateway.
You learn how to use an IoT gateway to connect a Texas Instruments SensorTag (CC2650STK) to Azure IoT Hub. The IoT gateway sends temperature and humidity data collected from the SensorTag to Azure IoT Hub.
- Create an IoT hub.
- Register a device in the IoT hub for the SensorTag.
- Enable the connection between the IoT gateway and the SensorTag.
- Run a BLE sample application to send SensorTag data to your IoT hub.
- Tutorial Set up Intel NUC as an IoT gateway completed in which you set up Intel NUC as an IoT gateway.
-
- An active Azure subscription. If you don't have an Azure account, create a free Azure trial account in just a few minutes.
- An SSH client that runs on your host computer. PuTTY is recommended on Windows. Linux and macOS already come with an SSH client.
- The IP address and the username and password to access the gateway from the SSH client.
- An Internet connection.
-
Sign in to the Azure portal.
-
Select New > Internet of Things > IoT Hub.
-
In the IoT hub pane, enter the following information for your IoT hub:
- Name: Create a name for your IoT hub. If the name you enter is valid, a green check mark appears.
Important
The IoT hub will be publicly discoverable as a DNS endpoint, so make sure to avoid any sensitive information while naming it.
-
Pricing and scale tier: For this tutorial, select the F1 - Free tier. 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.
-
Pin to dashboard: Check this option for easy access to your IoT hub from the dashboard.
![IoT hub window][2]
- Click Create. Your IoT hub might take a few minutes to create. You can monitor the progress in the Notifications pane.
Now that you have created an IoT hub, locate the important information that you use to connect devices and applications to your IoT hub.
-
After your IoT hub is created, click it on the dashboard. Make a note of the Hostname, and then click Shared access policies.
-
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.
-
In the Azure portal, open your IoT hub.
-
Click Device Explorer.
-
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.
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.
-
Click Save.
-
After the device is created, open the device in the Device Explorer pane.
-
Make a note of the primary key of the connection string.
Note
Here you register this new device for your SensorTag
In this section, you perform the following tasks:
- Get the MAC address of the SensorTag for Bluetooth connection.
- Initiate a Bluetooth connection from the IoT gateway to the SensorTag.
-
On the host computer, run the SSH client and connect to the IoT gateway.
-
Unblock Bluetooth by running the following command:
sudo rfkill unblock bluetooth
-
Start the Bluetooth service on the IoT gateway and enter a Bluetooth shell to configure Bluetooth by running the following commands:
sudo systemctl start bluetooth bluetoothctl
-
Power on the Bluetooth controller by running the following command at the Bluetooth shell:
power on
-
Start scanning for nearby Bluetooth devices by running the following command:
scan on
-
Press the pairing button on the SensorTag. The green LED on the SensorTag flashes.
-
At the Bluetooth shell, you should see the SensorTag is found. Make a note of the MAC address of the SensorTag. In this example, the MAC address of the SensorTag is
24:71:89:C0:7F:82
. -
Turn off the scan by running the following command:
scan off
-
Connect to the SensorTag by running the following command:
connect <MAC address>
-
Disconnect from the SensorTag and exit the Bluetooth shell by running the following commands:
disconnect exit
You've successfully enabled the connection between the SensorTag and the IoT gateway.
The Bluetooth Low Energy (BLE) sample application is provided by Azure IoT Edge. The sample application collects data from BLE connection and send the data to you IoT hub. To run the sample application, you need to:
- Configure the sample application.
- Run the sample application on the IoT gateway.
-
Go to the folder of the sample application by running the following command:
cd /usr/share/azureiotgatewaysdk/samples/ble_gateway
-
Open the configuration file by running the following command:
vi ble_gateway.json
-
In the configuration file, fill in the following values:
IoTHubName: The name of your IoT hub.
IoTHubSuffix: Get IoTHubSuffix from the primary key of the device connection string that you noted down. Ensure that you get the primary key of the device connection string, not the primary key of your IoT hub connection string. The primary key of the device connection string is in the format of
HostName=IOTHUBNAME.IOTHUBSUFFIX;DeviceId=DEVICEID;SharedAccessKey=SHAREDACCESSKEY
.Transport: The default value is
amqp
. This value shows the protocol during transpotation. It could behttp
,amqp
, ormqtt
.macAddress: The MAC address of the SensorTag that you noted down.
deviceID: ID of the device that you created in your IoT hub.
deviceKey: The primary key of the device connection string.
-
Press
ESC
and type:wq
to save the file.
-
Make sure the SensorTag is powered on.
-
Run the following command:
./ble_gateway ble_gateway.json
Use IoT gateway for sensor data transformation with Azure IoT Edge