Microsoft provides a great IoT platform on Microsoft Azure. And next to the resources (IoTHub, StreamAnalytics, etc.) available on Azure, Microsoft also offers a great introduction named Azure IoT Suite. and they are very serious about it!
To be clear, The IoT Suites are not complete solutions to be used as-is or even to be sold as-is. They have to be handled as a reference architecture… Use them to get started, use them to demonstrate the capabilities of the Azure IoT platform or use them as a piece of discussion for your future solution. Microsoft even helps you by providing the inner logic as open source. So you can extend it yourself. And they even show some examples on how to extend these suites.
At this moment, there are three preconfigured solutions:
- Remote Monitoring
- Predictive Maintenance
- Connected Factory
These are all three great solutions. There are simulated devices and you can add your own devices too. For example, the Connected Factory can connect to real devices using the OPC technology.
Note: For now, Predictive Maintenance and Connected Factory are out of scope for this article.
But there is one issue: it’s ‘expensive’. For example, this is what’s generated for the Remote Monitoring example:
- 1 Azure Active Directory application
- 1 IoT Hub (S2 – Standard tier)
- 1 DocumentDB Account (S1)
- 2 Event Hubs (Basic throughput unit)
- 1 Storage account (Standard-GRS)
- 3 Stream Analytics jobs (1 streaming unit per job)
- 1 Azure App Service Web App for Website (P1 – Premium: 2 small)
- 1 Azure App Service Web App for Web jobs (S1 – Standard: 2 small) running 25 simulated devices by default
Here are some examples. The S2 IoT Hub itself costs 421 euros. The two App Service Plans behind the web services consume 250 euros together. And there are three Stream Analytics jobs, each will cost 75 euros.
So if you demonstrate or test this IoT Suite, you can burn your MSDN account in a couple of days. Is it possible to change this?
So here is a collection of easy changes you can do yourself on this particular Predictive maintenance IoT Suite.
The IoT Hub can run as good on an S1 and it costs only 42 euros. That’s a cost reduction of 350+ euros or more than ten euros per day. With the steps below, you can reduce the total costs to fifteen euros or so per day…
Create the suite
Most hacks are already described here. But there are even more ways to optimize it in a simple matter.
First, as usual, create a new IoT Suite:
This takes less than ten minutes. You get a nice progress view:
When ready, you can launch the portal of the IoT Suite:
Disable all device simulations
After creation, sign in into the IoT Suite portal. It’s a nice portal, isn’t it? There is already data coming in from simulated devices.
Go to the devices page. Disable all (25) simulated devices:
Sorry, you have to repeat this 25 times, there are actually two pages…
Scale down the IoT Hub
Go to your Azure portal and find your IoT Hub. Is is of size S2. Scale it down to S1 and save the change:
Scale down the App Service Plans
Scale both App Service Plans to a B1 tier:
Notice that the ‘-jobsplan’ was running on a Standard pricing tier. The ‘-plan’ was running on a whopping Premium pricing tier.
Scale in the app service plans
Both App Service Plans are running on two servers. Just assign one server for each of them and save the changed:
Note: Scaling in is the opposite of scaling out?
Stop the web job for the Device Simulator
Find the web job called ‘DeviceSimulator-WebJob’ within the ‘-JobHost’ App Service. Stop it:
Scale the Event Hub down
The Event Hub is scaled as Standard. Scale it down to Basic:
Scale Azure storage down
The Azure Storage is running with Geo-redundancy. Change it back to Local-redundancy. Do not forget to save:
We are done now with the changes.
Does everything still work?
All simulated devices are shut down now. But we can still work with actual devices.
At this page, we are shown how to add a NodeJs client. So add one and run it:
We see the start of the communication and the data is being sent by the device. This data arrives at the IoT Hub (using an extra tool named Device Explorer):
And we see the arrival of the data into the IoT Suite portal. So this works great:
And we can still execute the methods on the device:
[UPDATE 2017-06-16] Merging two Stream Analytics jobs into one and delete the now obsolete one
This is a more complex one but still easy to accomplish.
After an investigation, two Stream Analytics jobs can be merged into one. Just Add the input source and output sink from the ‘-deviceinfo’ job (to delete) into the ‘-telemetry’ job:
And change the query to (you will have to stop the job first):
WITH [StreamData] AS ( SELECT * FROM [IoTHubStream] WHERE [ObjectType] IS NULL -- Filter out device info and command responses ) SELECT IoTHub.ConnectionDeviceId AS DeviceId, Temperature, Humidity, ExternalTemperature, EventProcessedUtcTime, PartitionId, EventEnqueuedUtcTime, * INTO [Telemetry] FROM [StreamData] SELECT IoTHub.ConnectionDeviceId AS DeviceId, AVG (Humidity) AS [AverageHumidity], MIN(Humidity) AS [MinimumHumidity], MAX(Humidity) AS [MaxHumidity], 5.0 AS TimeframeMinutes INTO [TelemetrySummary] FROM [StreamData] WHERE [Humidity] IS NOT NULL GROUP BY IoTHub.ConnectionDeviceId, SlidingWindow (mi, 5) -- The part copied from the '-deviceinfo' job SELECT * INTO DeviceInfoEvents FROM DeviceDataStream Partition By PartitionId WHERE ObjectType = 'DeviceInfo'
Remove the (now) obsolete ‘-deviceifo’ job and save approx. 75 euro per month.
This is a quick win and it will save you a few days extra before you run out of Azure credits. Currently, the service is running for fifteen euros per day…
But there are still other, more complex, ways to optimize this IoT Suite. Perhaps merging the two service plans?
Please share your further optimizations in the comments.