In this blog I want to expand on the Windows Core IOT project, by presenting the data which is presently being stored in Microsoft Azure IoT Hub data and presenting this live to a Azure Website.
Step 1 Create a Service Bus Consumer Group in Microsoft Azure
In order to allow several consumer applications to read data from the IoT Hub independently at their own pace a Consumer Group must be configured for each one. If all of the consumer applications (the Device Explorer, Stream Analytics / Power BI, the Web site you will configure in the next section) read the data from the default consumer group, one application will block the others.
To create a new Consumer Group for the IoT Hub that will be used by the Stream Analytics job you are about to configure, follow these steps:
- Open the Azure Portal (https://portal.azure.com/), and select the IoT Hub you created.
- From the settings blade, click on Messaging
- At the bottom of the Messaging blade, type the name of the new Consumer Group “WebSiteI” and “local”
- From the top menu, click on the Save icon
Setting the data source
- local (used when debugging)
Also take note of the Event Hub-compatible name and Event Hub-compatible endpoint values in the Messaging blade
Browse to the Assets/WebSite folder and open the Web Site project (ConnectTheDotsWebSite.sln) in Visual Studio.
Edit the Web.config file and add the corresponding values for the following keys:
- Microsoft.ServiceBus.EventHubDevices: Event hub-compatible name.
Microsoft.ServiceBus.ConnectionStringDevices: Event hub-compatible connection string which is composed by the Event hub-compatible endpoint and the iothubowner Shared access policy Primary Key
Microsoft.Storage.ConnectionString: Storage account endpoint, in this case use the storage account name and storage account primary key to complete the endpoint.
Deploy the website to an Azure Web Site. To do this, perform the following steps.
- In Visual Studio, right-click on the project name and select Publish.
Select Microsoft Azure Web Apps.
Selecting Publish target
Click New and use the following configuration.
- Web App name: Pick something unique.
- App Service plan: Select an App Service plan in the same region used for Stream Analytics or create a new one using that region.
- Region: Pick same region as you used for Stream Analytics.
- Database server: No database.
Click Create. After some time the website will be created in Azure.
Creating a new Web App on Microsoft Azure
Note: You might need to install WebDeploy extension if you are having an error stating that the Web deployment task failed. You can find WebDeploy here.
After you deployed the site, it is required that you enable Web sockets. To do this, perform the following steps:
- Browse to https://portal.azure.com and select your _Azure Web App.
- Click All settings.
- Click Applicattion settings
Then set Web sockets to On and click Save.
Enabling Web Sockets in your website
Browse to your recently deployed Web Application. You will see something like in the following screenshot. There will be 2 real-time graphics representing the values read from the temperature and light sensors. Take into account that the Universal app must be running and sending information to the IoT Hub in order to see the graphics.
Web Site Consuming the IoT Hub data
Note: At the bottom of the page you should see “Connected.”. If you see “ERROR undefined” you likely didn’t enable WebSockets for the Azure Web Site.
check step 5
If your interested in learning more about IOT Hub and Raspberry head over to https://github.com/MsftImagine and there are number of Repos which contain IOT resources.