The following instructions describe the steps for connecting an mbed-enabled Freescale FRDM-K64F device to Azure IoT Hub.
-
SSH client on your desktop computer, such as PuTTY, so you can remotely access the command line on the Freescale FRDM-K64F.
-
Required hardware: mbed-enabled Freescale K64F.
Before you begin you will need to create and configure an IoT hub to connect to.
- Set up your IoT Hub.
- With your IoT hub configured and running in Azure, follow the instructions in Connecting your device to an IoT hub.
- Make note of the Connection String for your device from the previous step.
Note: You can skip this step if you just want to build the sample application without running it.
-
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 FRDM-K64F 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, proton-c-mbed), 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.
- Now your device is sending event data to Azure IoT Hub and you can monitor this data and send messages to your device using the device explorer tool.