Git Product home page Git Product logo

azure-iot-pal-simplelink's Introduction

Run a simple C sample on a SimpleLink device


Table of Contents

Introduction

About this document

This document describes how to connect a TI SimpleLink device to Microsoft Azure using the Azure IoT SDK. This multi-step process includes:

  • Configuring Azure IoT Hub
  • Registering your IoT device
  • Build and deploy Azure IoT SDK on device

The instructions in this file apply specifically to a user who has directly cloned or downloaded the "azure-iot-pal-simplelink" PAL repository. Please note that it is highly recommended to alternatively install the TI Azure SDK Plugin, versus cloning or downloading this repository directly. The repository by itself only provides a basic example running on TI-RTOS with makefiles for the TI compiler. Full support for TI, GCC and IAR toolchains and FreeRTOS is provided via the Plugin installation.

If you have installed the Azure SDK Plugin (i.e. did not just clone/download this repository), then please refer to the Quick Start Guide that is included with your Plugin installation (you should be able to access this via the "docs" folder of the Azure SDK Plugin installation). The Quick Start Guide provides more accurate instructions that apply specifically to the Plugin installation.

Step 1: Prerequisites

Please ensure that your device has been updated with the latest firmware and or service pack (instructions for updating the firmware and/or service pack are included with the SimpleLink SDK installation).

These instructions refer to the folder that contains the Azure PAL repository on your local machine as <AZURE_PAL_INSTALL_DIR>.

While not strictly required, we recommend that you install the following tools from TI in the same directory and that you use directory names without any whitespace. This documentation assumes that you install everything in C:\ti.

Step 2: Build and Run the sample

Build the Azure PAL and SDK libraries

  1. Edit the products.mak file in <AZURE_PAL_INSTALL_DIR>\build_all using your favorite text editor. The variables XDC_INSTALL_DIR and SIMPLELINK_<YOUR DEVICE>_SDK_INSTALL_DIR must point to the locations where you installed these products. The variable ti.targets.arm.elf.M4 for CC32xx or ti.targets.arm.elf.M4F for MSP432E4 should point to the installation location of the TI ARM compiler, which can be found in CCS. After modification, these variable definitions should look similar to the following. Note the use of "/" in the path.
XDC_INSTALL_DIR ?= c:/ti/xdctools_3_50_07_20_core
SIMPLELINK_CC32XX_SDK_INSTALL_DIR   ?= C:/ti/simplelink_cc32xx_sdk_2_20_00_10
ti.targets.arm.elf.M4  ?= C:/CCSv8.1.0/ccsv8/tools/compiler/ti-cgt-arm_18.1.2.LTS

It is also recommended that you add the xdc tools folder (C:/ti/xdctools_3_50_07_20_core) to your path in order to avoid errors related to finding gmake.exe during the build process.

  1. Open a Windows command prompt.

  2. In the Windows command prompt, run the following commands (be sure to replace the paths with your installation paths).

cd <AZURE_PAL_INSTALL_DIR>\build_all
C:\ti\xdctools_3_50_07_20_core\gmake.exe clean
C:\ti\xdctools_3_50_07_20_core\gmake.exe all

Build the OS

  1. Update the settings in the imports.mak file of your device's SDK in <SIMPLELINK_CC32XX_SDK_INSTALL_DIR> or <SIMPLELINK_MSP432E4_SDK_INSTALL_DIR> with the appropriate paths if you have not done so previously.

  2. In the Windows command prompt, navigate to the OS directory corresponding to your OS of choice. For example, <SIMPLELINK_CC32XX_SDK_INSTALL_DIR>/kernel/tirtos/builds/CC3220SF_LAUNCHXL/release/ccs for tirtos on CC3220SF.

  3. In the Windows command prompt, enter the following commands to build the OS:

C:\ti\xdctools_3_50_07_20_core\gmake.exe clean
C:\ti\xdctools_3_50_07_20_core\gmake.exe

Build a sample application

The following instructions refer to the simplesample_http sample application, but they could be similarly applied to other sample applications found in the SDK. Before building the application, complete the following steps:

  1. Open the simplesample_http.c file from the directory <AZURE_PAL_INSTALL_DIR>\sample in a text editor and replace the value of the "connectionString" variable with the device connection string you noted earlier.

  2. (For CC32xx only) Open the file CC3220S_LAUNCHXL/wificonfig.h or CC3220SF_LAUNCHXL/wificonfig.h depending on the LaunchPad you have. Search for "USER STEP" and update the WIFI SSID and SECURITY_KEY macros.

  3. In the Windows command prompt, enter the following commands to build the application (replace CC3220SF_LAUNCHXL with your platform name):

cd <AZURE_PAL_INSTALL_DIR>\sample\CC3220SF_LAUNCHXL\tirtos\ccs
C:\ti\xdctools_3_50_07_20_core\gmake.exe clean
C:\ti\xdctools_3_50_07_20_core\gmake.exe all

Flash the root certificate

For CC32xx devices

Note: In the sample applications, the root CA certificate - "Baltimore CyberTrust Root" is flashed to CC32XX Launchpad to the location /cert/ms.pem. This location must match SL_SSL_CA_CERT in <AZURE_PAL_INSTALL_DIR>\pal\inc\cert_sl.h, and is used by SimpleLink TLS stack.

Here's why you need the Baltimore root CA - it's the root CA for *.azure-devices.net, the IoT Hub endpoint and it's the only way for the device to verify the chain of trust:

image

The default behavior of the sample application is to automatically write the certificate to flash if it does not exist. This prevents the file from being written unnecessarily to the file system each time the program is run. If you wish to override this behavior, or if you wish to use a new certificate file, you can force the certificate to be flashed by passing "-DOVERWRITE_CERTS" to the compiler in the makefile.

For MSP432E4 devices

The root CA certificate is simply loaded into memory as a security object with the name /cert/ms.pem to match SL_SSL_CA_CERT in <AZURE_PAL_INSTALL_DIR>\pal\inc\cert_sl.h, and used later when connecting to the IoT Hub endpoint.

Setting Up Code Composer Studio Before Running The Examples

We show the procedure for CC32xx devices below, but the same procedure can be followed for MSP432E4 by replacing CC32xx with MSP432E4.

  1. Plug the Launchpad into a USB port on your PC

  2. Open Code Composer Studio.

  3. In Code Composer Studio, open the CCS Debug Perspective - Windows menu -> Open Perspective -> CCS Debug

  4. Open the Target Configurations View - Windows menu -> Show View -> Target Configurations

  5. Right-click on User Defined. Select New Target Configuration.

  6. Use CC32xx.ccxml as "File name". Hit Finish.

  7. In the Basic window, select "Texas Instruments XDS110 USB Debug Probe" as the "Connection", and then type "CC3220" in the "Board or Device" text field. Check the box next to "CC3220SF" or "CC3220S" (depending on your launchpad). Hit Save.

  8. Right-click "CC32xx.ccxml" in the Target Configurations View. Hit Launch Selected Configuration.

  9. Under the Debug View, right-click on "Texas Instruments XDS110 USB Debug Probe_0/Cortex_M4_0". Select "Connect Target".

Running An Example

  1. Disconnect and reconnect the LaunchPad's USB cable to power cycle the hardware, and then reconnect in CCS.

  2. Select Run menu -> Load -> Load Program..., and browse to the file simplesample_http.out in <AZURE_PAL_INSTALL_DIR>\sample\CC3220SF_LAUNCHXL\tirtos\ccs (replace CC3220SF_LAUNCHXL depending on your board). Hit OK. This will load the program onto the board.

  3. Run the application by pressing F8. The output will appear in your CCS console window, similar to the following:

Starting the simplesample_http example
Current time: Fri Jul 20 20:56:27 2018

CC32XX has connected to AP and acquired an IP address.
IP Address: 192.168.1.172
Flashing certificate file ...successfully wrote file /cert/ms.pem to flash
IoTHubClient accepted the message for delivery
Message Id: 1 Received.
Result Call Back Called! Result is: IOTHUB_CLIENT_CONFIRMATION_OK

The Device Explorer can be used to monitor the data sent by the application. Under the "Data" tab in Device Explorer, "Monitor" option should be selected before running the application. Later when the application is run, a message similar to the following message is displayed on "Event Hub Data" window.

5/19/2017 5:26:44 PM> Device: [devicee43522cd755d463b9331e55d1cab2f13], Data:[{"DeviceId":"myFirstDevice", "WindSpeed":12, "Temperature":23.000000, "Humidity":68.000000}]Properties:'temperatureAlert': 'false'

Next Steps

You have now learned how to run a sample application that collects sensor data and sends it to your IoT hub. To explore how to store, analyze and visualize the data from this application in Azure using a variety of different services, please click on the following lessons:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.