Sample Wiring example code showing how to connect and send data to Microsoft Azure IoT Hub with a TI CC3200 Launchpad
Texas Instruments is one of the [Microsoft Azure Certified IoT partners] (https://azure.microsoft.com/en-us/marketplace/certified-iot-partners/) and TI CC3200 is listed in Microsoft Azure IoT Developer Center. Documentation in Azure IoT Developer Center includes an example for C code only. This document is prepared for TI CC3200 users who wants to connect to Azure IoT Hub using their Energia IDE to enter into IoT world quickly.
Please note that this is a device-to-cloud (D2C) scenario. If you want to extend this project by adding a feature for your CC3200 to receive "command" from cloud, which is called cloud-to-device C2D as well, you may need to implement MQTT instead of HTTP(s) which is used in this example. Built-in "PubSubClient" library (and examples) in your Energia IDE should help you connecting to IoT Hub using MQTT.
- TI CC3200 Launchpad
- Following (http://www.ti.com/cc3200start) if you're just starting to write code for TI CC3200 Launchpad XL using Energia(http://www.energia.nu)
- A Microsoft Account (if you have any @hotmail.com, @live.com etc. email you already have one)
- Microsoft Azure Subscription (Azure free trial is OK as well)
(P.S.: DreamSpark Azure Subscription won't work as it doesn't allow you creating Azue IoT Hub, Stream Analytics ) - A non-free email address to create a Power BI account (.edu email is ok as well)
By following this document (and the code in the repo) you will be able to,
- Connect your TI CC3200 to Azure IoT Hub
- Create an Azure free trial account
- Create an Azure IoT Hub
- Connect to your Azure IoT Hub using "Device Explorer" tool and create a "device"
- Program your CC3200 to connect your Azure IoT Hub
- Create your Microsoft Power BI account
- See how to get your telemetry data out of Azure Stream Analytics by creating an Azure Stream Analytics job, defining the input, output and query and running it
- Create your Power BI dashboard to show telemetry data in a realtime dashboard
-
Connect your TI CC3200 to Azure IoT Hub
-
Create an Azure free trial account Create a Microsoft Azure free trial account from here if you haven't used Microsoft Azure IoT Hub.
-
Create an Azure IoT Hub
- Go to http://portal.azure.com and login to the portal
- Click "New" as shown below :
- Select "Internet of Things" and then "Azure IoT Hub" as shown below :
- Give a "Name" to your IoT Hub being sure that you received check mark after typing your iot hub name, pick "Pricing and scale tier" as Free (you can have only one Free IoT Hub per each Azure subscription), keep "IoT Hub units" value as one and pick the lowes value for "Device-to-cloud partitions" as we will not put this system on production yet, give a name to your "Resource group", pick the right Azure Subscription in case if you have multiple Azure subscriptions, pick the "Location" and check the "Pin to dashboard" to be able to reach your Azure IoT Hub quickly through your portal dashboard.
- You will see that your IoT Hub started to be created :
- When your IoT Hub created, click on its tile and you should see its details similar to the shown below :
- Click on "Shared access policies", "iothubowner" to see the "Connection String"(s)
- Just copy and note either of primary/secondary connection strings somewhere which will be using in coming steps
-
Connect to your Azure IoT Hub using "Device Explorer" tool and create a "device" :
- Go ahead and download free tool Azure Device Explorer and install
- Copy/Paste the connection string you noted down in step 1/ii/h into "IoT Hub Connection String" textarea under "Management" tab in Device Explorer and click "Update" button. You should get "Settings updated succesfully" message as shown below :
- Switch to "Management" tab and click "Create" button to create a new "device" in your IoT hub :
- In the "Create Device" window, give any name to your device (like "myCC3200-01"). You should see "Device created" dialog box as shown below :
You will also see your device is added to your IoT hub: - Right-mouse click on your device in the "Devices" list and select "Copy connection string for selected device" from the context menu. Note this connection string down
-
Program your CC3200 to connect your Azure IoT Hub 1. Download all the .ino, .cpp and .h files from this repo to a folder in your machine 2. Run your Energia and open "TICC3200_AzureIoTHub_Client.ino" sketch and put your WiFi name and password in the lines below
// START: WiFi settings char SSID[] = "{YourWifiSSID}"; char PASSWORD[] = "{YourWifiPassword}"; // END: WiFi settings
3. Copy/paste your device connection string you noted down in Step 1/iii/e and paste in the same "TICC3200_AzureIoTHub_Client.ino" sketch :
````Arduino
//Azure IoT Hub connection string
String IoTHubConnectionString = "{PUT YOUR IOT HUB CONNECTION STRING HERE}";
//String IoTHubConnectionString = "HostName=youriothubname.azure-devices.net;DeviceId=TIcc3200-a;SharedAccessKey=8A0K1er45k5l3achAmda7UvVh6s4L7HTBdt/RnAdYuk=";
````
4. Save your sketch, compile and upload it to your TI CC3200 XL
5. Using Energia's "Serial Monitor", verify that your TI CC3200 XL is connected to your IoT Hub and started sending telemetry data
-
Create your free Microsoft Power BI account :
-
Go to http://www.powerbi.com and click "Start for free" button :
-
Use your non-free mail to sign up (You can use .edu email as well)
-
Click "Get Data" to see from which data sources you can get data
-
-
Get your telemetry data from IoT Hub using Azure Stream Analytics by creating an Azure Stream Analytics job, defining the "input", "output" and "query" and running it
-
Go to http://portal.azure.com and login to the portal
-
Click "New" and select "Internet of Things" and then "Stream Analytics job" as shown below :
-
Give any name to your job as shown above (Note that you should select the "Location" of your job same with your IoT Hub's location. In my example it's "North Europe")
-
When your Stream Analytics job created, click on your Stream Analytics job and scroll down to see the "Job Topology" for inputs,query and outputs
-
Give a name for your "Input Alias" to use in your query later. Select the "Source" as "IoT hub" and select "Use IoT hub from current subscription" for "Subscription" and find your "IoT hub". Leave the rest as in default values :
-
It's time to define an "Output" for "Power BI". As of this document is prepared, creating an output for Power BI in http://portal.azure.com is not ready yet and we should switch to Azure Classic Portal http://manage.windowsazure.com and login with our Azure credentials. Your services are listed on the left column in the classic portal. Find "Stream Analytics" and click to see your stream analytics jobs. Find your job you created in previous step and click to see its details as shown below :
-
Click on "Outputs" either from the top or click "3 Add an output" as shown below :
-
Now you will "Authorize" your stream analytics job to reach your Power BI account. Click on "Authorize Now" as shown below :
-
Login to your Power BI account using your non-free email address :
-
Authorization is completed. Now you will define your "Output Alias" to use in your stream analtyics "Query". Give a name to your output alias, give a name for your "DataSet" which will be shown in your Power BI acount, give a name to your "Table" which will again be shown in your Power BI when you started using your "DataSet", leave "Workspace" as default and check mark at the bottom right :
-
In the classic portal, operational messages are shown at the bottom. You will see that it will create your "output" and also will test the connection :
-
After successfuly passing the connection for your output for Power BI, you can click "Dismiss Completed" to clear those operational messages :
-
Now click on "Query" to write your simple Stream Analytics job :
-
As we are just trying to show the incoming telemetry in a realtime Power BI dashboard, we will not do a "filtering" in our query and it will be a simple "SELECT * INTO yourpowerbioutputalias FROM youriothubinputalias" query as shown below :
-
After writing your query, you will see that stream analytics asks when the output should start. Leave the default option "Job Start Time" and click check mark at the bottom right and wait for job to start (which may take several minutes) :
-
Create your Power BI dashboard to show telemetry data in a realtime dashboard
-
Login to your Power BI account in http://www.powerbi.com and click anywhere on the left to see "hamburger button" right below 9 dot logo :
-
Check your "Datasets" and you should see nothing or the "DataSet" name you set in step 3/xiii . If you see nothing be sure that your stream analytic job is running and you are not connected to your IoT Hub with "Device Explorer":
-
Click on your dataset and you should see your table name you set in step 3/xiii. Expand your table to see your "fields".
-
Under "Visualisations" select line chart icon as shown below :
-
Maximize the line chart and under your table, drag&drop the "EventEnqueuedUTCTime" field into "Axis" field and "temperature" field into "Values" field :
-
From "File" menu select "Save" and give any name to this "Report" and click "Save" button:
-
You will need to "Pin" this report into a "Dashboard" so you can see your line chart showing the telemetry in real-time. Click the "Pin" button on your reports top-right :
-
You will get "Pin to dashboard" screen. As you don't have any dashboard yet, select "New dashboard" and give any name to this dashboard as shown below :
-
On the left pane, you should see your dashboard is created under "Dashboards" with a "*" sign right next to it :
-
Click on your dashboard and you should see your report updates the temperature value in real-time :