This example provide everything you need to develop an end to end IoT system utilising Microsoft Azure Cloud Technology and an embedded device, the Texas Instruments CC3200 LaunchPad (Single Chip Wi-Fi MCU).
Included are all the components you would expect in a typical telemetry based sensor scenario. For example a wireless sensor network utilised in machine health monitoring.
The architecture allows for a hyperscaled ingestion system (millions of messages a second) that also provides near real-time streaming analytics, and machine learning capabilities.
Web Site: http://ssmlwf.azurewebsites.net/
Original Setup Instructions: https://github.com/remixed123/IoT/wiki (Or Below)
Figure 1: Solution Architecture:
Color Code: Blue - Code and Steps Included. Orange - Example or Architecture Only. Grey - External Components
The above image outline the solution architecture of the end to end IoT proof of concept. Some parts are yet to be detailed in this step by step example, however all the main components from the CC3200 LaunchPad through to Event Hubs and then to Stream Analytics, with data stored in SQL Database and viewed from a Website are complete. Details on mobile services and machine learning are yet to be included.
The CC3200 LaunchPad sends telemetry that has been created from its onboard temperature sensor, alternatively telemetry can be produced via an Azure Web Site webpage using a fake telemetry generator. The telemetry is then ingested by Azure Event Hub and processed by Azure Stream Analytics in near real time, the processed telemetry is then stored in an Azure SQL Server Table. One table stores telemetry that has just been cleaned, where as another table stores averaged temperature and humidity data, along with the data count for a 5 minute tumbling window.
Newly stored processed telemetry can be viewed as it arrives via an Azure Websites webpage. While an Azure Mobile Service sends a push notification to a Smart Phone App should certain triggers indicate that a system has failed.
A predictive model is created using Azure Machine Learning and made available as a web service. The model can be queried from an Azure Website webpage to determine whether a system requires maintenance. In future, as Azure Stream Analytics is improved, it is expected that you will be able to query predictive models via the Azure Machine Learning Web Service and hence provide near real-time predictions for many different scenarios.
You will find below detailed instructions for reproducing the end to end IoT proof of concept, built on Microsoft Azure Cloud Platform and the Texas Instruments CC3200 LaunchPad development board.
View Working Example
You can view a working example at the following links.
These instructions provide the details required to setup a reproduction of the end to end IoT example. However it is assumed that you are familiar with Microsoft Azure and the Texas Instruments CC3200 LaunchPad Developer Environments.
Setting Up The Examples
There are 2 main technologies to setup to get this example working
If you are only interested in the CC3200 LaunchPad side of the example, you can use the default settings provided in the source code. This will then communicate with the Azure Cloud I have setup and you can then view the telemetry you send here to determine if your have everything working. There is also a binary provided, which you can flash the CC3200 LaunchPad with.
The following resources will help you learn more about Microsoft Azure and the Texas Instruments CC3200 LaunchPad.
Texas Instruments CC3200 LaunchPad
Azure Event Hubs
Azure Stream Analytics
Azure Machine Learning
Azure Mobile Services
Azure SQL Database
Azure Setup Steps
It is preferable to setup all services at the same data center, so as to avoid incurring performance hit and data transfer charges.
This can be performed from the Azure Management Portal or from within Visual Studio:-
Create SQL Server Tables
Create an Azure SQL Database and then create 2 tables using the below sql statements.
SQL to Create Processed Telemetry Table
CREATE TABLE [dbo].[ProcessedTelemetry]( [MessageType] [nvarchar](50) NULL, [Temp] [float] NULL, [Humidity] [int] NULL, [Location] [nvarchar](50) NULL, [Room] [nvarchar](50) NULL, [Info] [nvarchar](100) NULL, [EventEnqueuedUtcTime] [datetime2](7) NULL )
CREATE CLUSTERED INDEX [ProcessedTelemetry] ON [dbo].[ProcessedTelemetry]([Location] ASC)
SQL to Create Averaged Telemetry Table
CREATE TABLE [dbo].[AverageTelemetry]( [ID] [int] IDENTITY(1,1) NOT NULL,[StartTime] [datetime2](7) NULL, [EndTime] [datetime2](7) NULL, [AverageTemp] [float] NULL, [AverageHumidity] [float] NULL, [LogCount] [int] NULL, CONSTRAINT [PrimaryKey_a97a20a9-3d36-4d59-82af-e5cb075a0b73] PRIMARY KEY CLUSTERED ( [ID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) )
Create Event Hub
Create an event hub, making sure you create a Shared access policy with Managed, Send, Listen selected and call it EventHubPublisher.
Create Stream Analytics Jobs
Create 2 Stream Analytics' Jobs with the following Input, Query and Output.
Both the inputs will be the same, they need to obtain data from the Event Hub created in the previous step.
A different query is required for each job.
Processed Telemetry Job Query
SELECT EventEnqueuedUtcTime, MessageType, Location, Room, Temp, Humidity, Info FROM input1
Averaged Telemetry Job Query
SELECT DateAdd(minute,-5,System.TimeStamp) as StartTime, system.TimeStamp as EndTime, Avg(Temp) as AverageTemp, Avg(Humidity) as AverageHumidity, Count(*) as LogCount FROM input2 GROUP BY TumblingWindow(minute, 5)
Both outputs will be to the appropriate SQL Table, either ProcessedTelemetry or AveragedTelemetry tables.
CC3200 Setup Steps
Generate Shared Access Token
You will need to generate a SAS Token, this can be done using one of the following methods
- Build the Visual Studio Project that contains a Windows Form Application with C# code available from here
- Install and use the already built and published application from here
Edit main.c to reflect your Azure setup and Shared Access Token details
- Open the SendToEventHub project in Code Composure Studio so that you can edit source code.
#define EH_SERVER_NAME to
#define POSTHEADER "POST /swiftsoftware-eh/messages HTTP/1.1\r\n" to
#define POSTHEADER "POST /Your_EH_Server_Name/messages HTTP/1.1\r\n"
#define HOSTHEADER "Host: swiftsoftware-ns.servicebus.windows.net\r\n"to
#define HOSTHEADER "Host: Your_Service_Bus_Name_Space.servicebus.windows.net\r\n"
#define AUTHHEADER "Authorization: SharedAccessSignature sr=swiftsoftware-ns.servicebus.windows.net&sig=6sIkgCiaNbK9R0XEpsKJcQ2Clv8MUMVdQfEVQP09WkM%3d&se=1733661915&skn=EventHubPublisher\r\n" to
#define AUTHHEADER "Authorization: SharedAccessSignature sr=Your_Service_Bus_Name_Space.servicebus.windows.net&sig=Your_Shared_Access_Token&se=1733661915&skn=Your_Eventhub_Shared_Access_Policy\r\n"
Note: You can choose not to make any changes, and the telemetry generated by the CC3200 will be sent to my Event Hub, you can then view the Telemetry here.
Edit main.c to select a NTP Server in your geography
To create a secure TLS socket the current time is required, this is obtained from an NTP Server. It is best to use one close to your geographically. The code includes some suggestions, you can also perform an Internet search to find one in your location.
Search on "g_acSNTPserver" in main.c to find where in the code the NTP Server details can be modified
Edit common.h to reflect your WiFi Router Settings
Change the defines in the common.h of the CC3200 SDK to reflect your WiFi Router settings. common.h can be found in the common example in the example folder of the CC3200 SDK.
#define SSID_NAME "YourWifiRouterSSID" /* AP SSID */
#define SECURITY_TYPE SL_SEC_TYPE_WPA /* Security type (OPEN or WEP or WPA*/
#define SECURITY_KEY "YourSecurePassword" /* Password of the secured AP */
Save the Certificate Authority on the CC3200 Flash
- Use the certificate authority file "azurecacert.cer" which is located here.
- Start UniFlash for the CC3200/CC3100
- In Uniflash, click the "add file" option.
- Name the file to /cert/azurecacert.der
- In the Url field browser to the location of were you have stored azurecacert.cer
- Select the Erase and Update check boxes
- Select the top of the tree (CC31x Flash Setup Control) and then press program.
Additional Assistance: UniFlash Quick Start Guide.
Note: You can download your own Certificate from a browser or from the Certificate Manager in Windows. Azure uses the Baltimore CyberTrust Root. Details on how to perform these steps can be found here, at the bottom of the page.
You can connect via serial port and receive debug output. This is recommended should you have any issues as the debug output is quite comprehensive.