| title | description | services | keywords | author | manager | ms.author | ms.date | ms.topic | ms.service |
|---|---|---|---|---|---|---|---|---|---|
Deploy Azure Stream Analytics with Azure IoT Edge | Microsoft Docs |
Deploy Azure Stream Analytics as a module to an edge device |
iot-edge |
msebolt |
timlt |
v-masebo |
10/05/2017 |
article |
iot-edge |
IoT devices can produce large quantities of data. Sometimes this data has to be analyzed or processed before reaching the cloud to reduce the size of uploaded data or to eliminate the round-trip latency of an actionable insight.
Azure Stream Analytics (ASA) provides a richly structured query syntax for data analysis both in the cloud and on IoT Edge devices. For more information about ASA on IoT Edge, see ASA documentation.
This tutorial walks you through the creation of an Azure Stream Analytics job, and its deployment on an IoT Edge device in order to process a local telemetry stream directly on the device, and generate alerts to drive immediate action on the device. You learn how to:
[!div class="checklist"]
- Create an ASA job to process data on the Edge
- Connect the new ASA job with other IoT Edge modules
- Deploy the ASA job to an IoT Edge device
- An IoT Hub
- An IoT Edge runtime
- Docker
Note
Note your IoT Hub connection string, device connection string, and edge device ID will be necessary for this tutorial. For a tutorial on installing IoT Hub and IoT Edge runtime see Install Azure IoT Edge and deploy a module
IoT Edge takes advantage of pre-built Azure Service IoT Edge modules for quick deployment and Azure Stream Analytics (ASA) is one such module. You can create an ASA job from its portal, then come to IoT Hub portal to deploy it as an IoT Edge Module.
For more information on Azure Stream Analytics, see the Overview section of the Stream Analytics Documentation. If you want to learn how to create your solution-specific IoT Edge Module, instead of using Azure Service provider, see Create an IoT Edge module.
In this section, you create an Azure Stream Analytics job to take data from your IoT hub, query the sent telemetry data from your device, and forward the results to an Azure Storage Container (BLOB). For more information, see the Overview section of the Stream Analytics Documentation.
Note
An Azure Storage account is required to provide an endpoint to be used as an output in your ASA job. The example below uses the BLOB storage type. For more information, see the Blobs section of the Azure Storage Documentation.
-
In the Azure portal, navigate to Create a resource -> Storage, click See all, and click Storage account - blob, file, table, queue.
-
Enter a name and use the remaining default values. Click Create. Note the name for later.
[!NOTE] Make sure the Location you use is the same as your IoT Hub Location else additional fees may apply.
-
In the Azure portal, navigate to the storage account that you just created. Click Browse blobs under Blob Service. Create a new container for the ASA module to store data. Set the access level to Container. Click OK.
-
In the Azure portal, navigate to Create a resource -> Internet of Things and click Stream Analytics Job.
[!NOTE] For 11-09 bug bash, please create your ASA job under location Canada East.
-
Enter a name, choose "Edge" as Hosting environment and use the remaining default values. Click Create.
-
Go into the created job, under Job Topology, select Inputs, click Add.
-
Enter name "temperature", choose Data stream as "Source Type" and use defaults for the other parameters, click Create.
[!NOTE] Additional inputs can include IoT Edge specific endpoints.
-
Under Job Topology, select Outputs, click Add.
-
Enter name "alert" and use defaults. Click Create.
-
Under Job Topology, select Query, and enter the following:
SELECT 'reset' AS command INTO alert FROM temperature TIMESTAMP BY timeCreated GROUP BY TumblingWindow(second,30) HAVING Avg(machine.temperature) > 100
You are now ready to deploy the ASA job on your IoT Edge device.
-
In the Azure portal, in your IoT Hub, navigate to IoT Edge Explorer and open your {deviceId}'s blade.
-
Select Set modules, then select Import Azure Service IoT Edge Module.
-
Select the subscription and the ASA Edge job that you created. Then select your storage account. Click Save.
[!NOTE] For 11-09 bug bash, there is a known issue that you can't use long module name. Click edit button for this ASA module, rename the module with any three characters. Then save.
-
Click Add IoT Edge Module to add the temperature sensor module. Enter tempSensor for name,
edgepreview.azurecr.io/azureiotedge/simulated-temperature-sensor:1.0-previewfor Image URL. Leave the other settings unchanged, and click Save. -
Copy the name of the ASA module. Click Next to configure routes.
-
Copy the following to Routes. Replace {moduleName} with the module name you copied:
{ "routes": { "telemetryToCloud": "FROM /messages/modules/tempSensor/* INTO $upstream", "alertsToCloud": "FROM /messages/modules/{moduleName}/* INTO $upstream", "alertsToReset": "FROM /messages/modules/{moduleName}/* INTO BrokeredEndpoint(\"/modules/tempSensor/inputs/reset\")", "telemetryToAsa": "FROM /messages/modules/tempSensor/* INTO BrokeredEndpoint(\"/modules/{moduleName}/inputs/temperature\")" } } -
Click Next.
-
In the Review Template step, click Submit.
-
Return to the device details page and click Refresh. You should see the new {moduleName} module running along with the IoT Edge agent module and the IoT Edge hub.
-
At a command prompt, run the following command to see the modules running:
docker ps -
Run the command to see all system logs and metrics data. Use the module name from above:
docker logs -f {moduleName} -
In the Azure portal, in your Storage account, under Blob Service, click Browse blobs, select your container, and select newly created JSON file.
-
Click Download and view the results.
In this tutorial, you configured an Azure Storage container and a Streaming Analytics job to analyze data from your IoT Edge device. You then loaded a custom ASA module to move data from your device, through the stream, into a BLOB for download. You can continue on to other tutorials to further see how Azure IoT Edge can create solutions for your business.
[!div class="nextstepaction"] Create a custom module









