platform | device | language |
---|---|---|
mbed |
SadeIoTCloudGateway |
c |
- Introduction
- Step 1: Prerequisites
- Step 2: Prepare your Device
- Step 3: Build and Run the Sample
- Tips
About this document
This document describes the steps for connecting an mbed-SADEIotCloudGateway device to Azure IoT Hub. This multi-step process includes:
- Configuring Azure IoT Hub
- Registering your IoT device
- Build and deploy Azure IoT SDK on device
You should have the following items ready before beginning the process:
- Computer with Git client installed and access to the azure-iot-sdks GitHub public repository.
- SSH client on your desktop computer, such as PuTTY, so you can remotely access the command line on the SadeIOTCloudGateway.
- Required hardware: mbed-SADEIotCloudGateway, SADETemperatureExtensionBoard
- Setup your IoT hub
- Provision your device and get its credentials
-
Connect the board to your network using an Ethernet cable. This step is required, as the sample depends on Internet access.
-
Plug the device into your computer using a micro-USB cable. Be sure to attach the cable to the USB port next to the reset button on the SADEIoTCloudGateway device.
-
Follow the instructions on the mbed handbook to set up the serial connection with your device from your development machine. If you are on Windows, install the Windows serial port drivers located here.
-
In your web browser, go to the mbed.org developer site. If you haven't signed up, you will see an option to create a new account (it's free). Otherwise, log in with your account credentials. Then click on Compiler in the upper right-hand corner of the page. This should bring you to the Workspace Management interface.
-
Make sure the hardware platform you're using appears in the upper right-hand corner of the window, or click the icon in the right-hand corner to select your hardware platform.
-
Click Import on the main menu. Then click the Click here to import from URL link next to the mbed globe logo.
-
In the popup window, enter the link for the sample code https://developer.mbed.org/users/AzureIoTClient/code/iothub_client_sample_amqp/ (note that if you want to try the sample using HTTP instead of AMQP, you can import this other sample: https://developer.mbed.org/users/AzureIoTClient/code/iothub_client_sample_http/
-
You can see in the mbed compiler that importing this project imported various libraries. Some are provided and maintained by the Azure IoT team (azureiot_common, iothub_client, iothub_amqp_transport, iothub_http_transport, azure-uamqp-c), while others are third party libraries available in the mbed libraries catalog.
-
Open iothub_client_sample_amqp/iothub_client_sample_amqp.c, and replace "[device connection string]" with the device connection string you noted earlier:
-
Save the changes.
-
Click Compile to build the program. You can safely ignore any warnings, but if the build generates errors, fix them before proceeding.
-
If the build is successful, a .bin file with the name of your project is generated. Copy the .bin file to the device. Saving the .bin file to the device causes the current terminal session to the device to reset. When it reconnects, reset the terminal again manually, or start a new terminal. This enables the mbed device to reset and start executing the program.
-
Connect to the device using an SSH terminal program, such as PuTTY. You can determine which serial port your device uses by checking the Windows Device Manager:
-
In PuTTY, click the Serial connection type. The device most likely connects at 115200, so enter that value in the Speed box. Then click Open:
The program starts executing. You may have to reset the board (press CTRL+Break or press on the board's reset button) if the program does not start automatically when you connect.
- See Manage IoT Hub to learn how to observe the messages IoT Hub receives from the application and how to send cloud-to-device messages to the application.