Skip to content

Commit 2ca2c23

Browse files
authored
Merge pull request #91848 from baanders/10-14-iothub-tutorials
IoT Hub Tutorial 1
2 parents c3b1fc7 + 26eb23a commit 2ca2c23

9 files changed

+58
-46
lines changed
1.59 KB
Loading

articles/iot-hub/tutorial-routing-config-message-routing-CLI.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ If you want to view the finished script, download the [Azure IoT C# Samples](htt
2626

2727
## Use the Azure CLI to create your resources
2828

29+
Copy and paste the script below into Cloud Shell and press Enter. It runs the script one line at a time. This first section of the script will create the base resources for this tutorial, including the storage account, IoT Hub, Service Bus Namespace, and Service Bus queue. As you go through the rest of the tutorial, copy each block of script and paste it into Cloud Shell to run it.
30+
31+
> [!TIP]
32+
> A tip about debugging: this script uses the continuation symbol (the backslash `\`) to make the script more readable. If you have a problem running the script, make sure your Cloud Shell session is running `bash` and that there are no spaces after any of the backslashes.
33+
>
34+
2935
There are several resource names that must be globally unique, such as the IoT Hub name and the storage account name. To make this easier, those resource names are appended with a random alphanumeric value called *randomValue*. The randomValue is generated once at the top of the script and appended to the resource names as needed throughout the script. If you don't want it to be random, you can set it to an empty string or to a specific value.
3036

3137
> [!IMPORTANT]
3238
> The variables set in the initial script are also used by the routing script, so run all of the script in the same Cloud Shell session. If you open a new session to run the script for setting up the routing, several of the variables will be missing values.
3339
>
3440
35-
Copy and paste the script below into Cloud Shell and press Enter. It runs the script one line at a time. This first section of the script will create the base resources for this tutorial, including the storage account, IoT Hub, Service Bus Namespace, and Service Bus queue. As you go through the rest of the tutorial, copy each block of script and paste it into Cloud Shell to run it.
36-
37-
> [!TIP]
38-
> A tip about debugging: this script uses the continuation symbol (the backslash `\`) to make the script more readable. If you have a problem running the script, make sure there are no spaces after any of the backslashes.
39-
>
40-
4141
```azurecli-interactive
4242
# This command retrieves the subscription id of the current Azure account.
4343
# This field is used when setting up the routing queries.
@@ -151,7 +151,7 @@ To create a routing endpoint, use [az iot hub routing-endpoint create](/cli/azur
151151

152152
First, set up the endpoint for the storage account, then set up the route.
153153

154-
These variables are set:
154+
These are the variables used by the script that must be set within your Cloud Shell session:
155155

156156
**storageConnectionString**: This value is retrieved from the storage account set up in the previous script. It is used by the message routing to access the storage account.
157157

@@ -171,7 +171,7 @@ These variables are set:
171171

172172
**endpointName**: This field is the name identifying the endpoint.
173173

174-
**enabled**: This field defaults to `true`, indicating that the message route should be enabled after created.
174+
**enabled**: This field defaults to `true`, indicating that the message route should be enabled after being created.
175175

176176
**condition**: This field is the query used to filter for the messages sent to this endpoint. The query condition for the messages being routed to storage is `level="storage"`.
177177

@@ -253,7 +253,7 @@ sbqConnectionString=$(az servicebus queue authorization-rule keys list \
253253
echo "service bus queue connection string = " $sbqConnectionString
254254
```
255255

256-
Now set up the routing endpoint and the message route for the Service Bus queue. These variables are set:
256+
Now set up the routing endpoint and the message route for the Service Bus queue. These are the variables used by the script that must be set within your Cloud Shell session:
257257

258258
**endpointName**: This field is the name identifying the endpoint.
259259

articles/iot-hub/tutorial-routing-config-message-routing-PowerShell.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ Start by creating the resources with PowerShell.
3030

3131
### Use PowerShell to create your base resources
3232

33+
Copy and paste the script below into Cloud Shell and press Enter. It runs the script one line at a time. This first section of the script will create the base resources for this tutorial, including the storage account, IoT Hub, Service Bus Namespace, and Service Bus queue. As you go through the tutorial, copy each block of script and paste it into Cloud Shell to run it.
34+
3335
There are several resource names that must be globally unique, such as the IoT Hub name and the storage account name. To make this easier, those resource names are appended with a random alphanumeric value called *randomValue*. The randomValue is generated once at the top of the script and appended to the resource names as needed throughout the script. If you don't want it to be random, you can set it to an empty string or to a specific value.
3436

3537
> [!IMPORTANT]
3638
> The variables set in the initial script are also used by the routing script, so run all of the script in the same Cloud Shell session. If you open a new session to run the script for setting up the routing, several of the variables will be missing values.
3739
>
3840
39-
Copy and paste the script below into Cloud Shell and press Enter. It runs the script one line at a time. This first section of the script will create the base resources for this tutorial, including the storage account, IoT Hub, Service Bus Namespace, and Service Bus queue. As you go through the tutorial, copy each block of script and paste it into Cloud Shell to run it.
40-
4141
```azurepowershell-interactive
4242
# This command retrieves the subscription id of the current Azure account.
4343
# This field is used when setting up the routing queries.
@@ -136,7 +136,7 @@ First, set up the endpoint for the storage account, then create the message rout
136136

137137
[!INCLUDE [iot-hub-include-blob-storage-format](../../includes/iot-hub-include-blob-storage-format.md)]
138138

139-
These variables are set:
139+
These are the variables used by the script that must be set within your Cloud Shell session:
140140

141141
**resourceGroup**: There are two occurrences of this field -- set both of them to your resource group.
142142

@@ -158,7 +158,7 @@ These variables are set:
158158

159159
**condition**: This field is the query used to filter for the messages sent to this endpoint. The query condition for the messages being routed to storage is `level="storage"`.
160160

161-
**enabled**: This field defaults to `true`, indicating that the message route should be enabled after created.
161+
**enabled**: This field defaults to `true`, indicating that the message route should be enabled after being created.
162162

163163
Copy this script and paste it into your Cloud Shell window.
164164

@@ -228,7 +228,7 @@ $sbqkey = Get-AzServiceBusKey `
228228
-Name "sbauthrule"
229229
```
230230

231-
Now set up the routing endpoint and the message route for the Service Bus queue. These variables are set:
231+
Now set up the routing endpoint and the message route for the Service Bus queue. These are the variables used by the script that must be set within your Cloud Shell session:
232232

233233
**endpointName**: This field is the name identifying the endpoint.
234234

articles/iot-hub/tutorial-routing-config-message-routing-RM-template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ The files are uploaded to the share used by your Cloud Shell instance.
367367

368368
Run the script to perform the deployment. The last line of this script retrieves the variable that was set up to be returned -- the Service Bus queue connection string.
369369

370-
These variables are set in this script.
370+
The script sets and uses these variables:
371371

372372
**$RGName** is the resource group name to which to deploy the template. This field is created before deploying the template.
373373

articles/iot-hub/tutorial-routing-view-message-routing-results.md

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ ms.custom: mvc
1919

2020
## Rules for routing the messages
2121

22-
These are the rules for the message routing; these were set up in part 1 of this tutorial, and you see them work in this second part.
22+
These are the rules for the message routing; these were set up in Part 1 of this tutorial, and you see them work in this second part.
2323

24-
|value |Result|
24+
|Value |Result|
2525
|------|------|
2626
|level="storage" |Write to Azure Storage.|
2727
|level="critical" |Write to a Service Bus queue. A Logic App retrieves the message from the queue and uses Office 365 to e-mail the message.|
@@ -47,9 +47,11 @@ The Service Bus queue is to be used for receiving messages designated as critica
4747

4848
![The Create Logic App screen](./media/tutorial-routing-view-message-routing-results/create-logic-app.png)
4949

50-
Select **Create**.
50+
Select **Create**. It may take a few minutes for the app to deploy.
5151

52-
2. Now go to the Logic App. The easiest way to get to the Logic App is to select **Resource groups**, select your resource group (this tutorial uses **ContosoResources**), then select the Logic App from the list of resources. The Logic Apps Designer page appears (you might have to scroll over to the right to see the full page). On the Logic Apps Designer page, scroll down until you see the tile that says **Blank Logic App +** and select it. The default tab is "For You". If this pane is blank, select **All** to see all of the connectors and triggers available.
52+
2. Now go to the Logic App. The easiest way to get to the Logic App is to select **Resource groups**, select your resource group (this tutorial uses **ContosoResources**), then select the Logic App from the list of resources.
53+
54+
The Logic Apps Designer page appears (you might have to scroll over to the right to see the full page). On the Logic Apps Designer page, scroll down until you see the tile that says **Blank Logic App +** and select it. The default tab is "For You". If this pane is blank, select **All** to see all of the connectors and triggers available.
5355

5456
3. Select **Service Bus** from the list of connectors.
5557

@@ -71,7 +73,7 @@ The Service Bus queue is to be used for receiving messages designated as critica
7173

7274
![The queue options](./media/tutorial-routing-view-message-routing-results/logic-app-queue-options.png)
7375

74-
7. Now set up the action to send an e-mail when a message is received in the queue. In the Logic Apps Designer, select **+ New step** to add a step, then select **All** to see all of the options available. In the **Choose an action** pane, find and select **Office 365 Outlook**. On the triggers screen, select **Send an e-mail / Office 365 Outlook**.
76+
7. Now set up the action to send an e-mail when a message is received in the queue. In the Logic Apps Designer, select **+ New step** to add a step, then select **All** to see all of the options available. In the **Choose an action** pane, find and select **Office 365 Outlook**. On the Actions screen, select **Send an e-mail / Office 365 Outlook**.
7577

7678
![The Office365 options](./media/tutorial-routing-view-message-routing-results/logic-app-select-outlook.png)
7779

@@ -103,7 +105,9 @@ To see the data in a Power BI visualization, first set up a Stream Analytics job
103105

104106
![Create the stream analytics job](./media/tutorial-routing-view-message-routing-results/stream-analytics-create-job.png)
105107

106-
3. Select **Create** to create the job. To get back to the job, select **Resource groups**. This tutorial uses **ContosoResources**. Select the resource group, then select the Stream Analytics job in the list of resources.
108+
3. Select **Create** to create the job. It may take a few minutes to deploy.
109+
110+
To get back to the job, select **Resource groups**. This tutorial uses **ContosoResources**. Select the resource group, then select the Stream Analytics job in the list of resources.
107111

108112
### Add an input to the Stream Analytics job
109113

@@ -117,13 +121,13 @@ To see the data in a Power BI visualization, first set up a Stream Analytics job
117121

118122
**Subscription**: Select the Azure subscription you're using for this tutorial.
119123

120-
**IoT Hub**: Select the IoT Hub. This tutorial uses **ContosoTestHub**.
124+
**IoT Hub**: Select the IoT hub. This tutorial uses **ContosoTestHub**.
121125

122126
**Endpoint**: Select **Messaging**. (If you select Operations Monitoring, you get the telemetry data about the IoT hub rather than the data you're sending through.)
123127

124128
**Shared access policy name**: Select **service**. The portal fills in the Shared Access Policy Key for you.
125129

126-
**Consumer group**: Select the consumer group set up in step 1 of this tutorial. This tutorial uses **contosoconsumers**.
130+
**Consumer group**: Select the consumer group set up in Part 1 of this tutorial. This tutorial uses **contosoconsumers**.
127131

128132
For the rest of the fields, accept the defaults.
129133

@@ -173,20 +177,20 @@ To set up the Power BI report, you need data, so you'll set up Power BI after cr
173177

174178
## Run simulated device app
175179

176-
In the part 1 of this tutorial, you set up a device to simulate using an IoT device. In this section, you download the .NET console app that simulates that device sending device-to-cloud messages to an IoT hub, assuming you didn't already download the app and resources in part 1 of this tutorial.
180+
In Part 1 of this tutorial, you set up a device to simulate using an IoT device. In this section, you download the .NET console app that simulates that device sending device-to-cloud messages to an IoT hub (assuming you didn't already download the app and resources in Part 1).
177181

178182
This application sends messages for each of the different message routing methods. There is also a folder in the download that contains the complete Azure Resource Manager template and parameters file, as well as the Azure CLI and PowerShell scripts.
179183

180-
If you didn't download the files from the repository in step 1 of this tutorial, go ahead and download them now from [IoT Device Simulation](https://github.com/Azure-Samples/azure-iot-samples-csharp/archive/master.zip). Selecting this link downloads a repository with several applications in it; the solution you are looking for is iot-hub/Tutorials/Routing/IoT_SimulatedDevice.sln.
184+
If you didn't download the files from the repository in Part 1 of this tutorial, go ahead and download them now from [IoT Device Simulation](https://github.com/Azure-Samples/azure-iot-samples-csharp/archive/master.zip). Selecting this link downloads a repository with several applications in it; the solution you are looking for is iot-hub/Tutorials/Routing/IoT_SimulatedDevice.sln.
181185

182-
Double-click on the solution file (IoT_SimulatedDevice.sln) to open the code in Visual Studio, then open Program.cs. Substitute `{iot hub hostname}` with the IoT hub host name. The format of the IoT hub host name is **{iot-hub-name}.azure-devices.net**. For this tutorial, the hub host name is **ContosoTestHub.azure-devices.net**. Next, substitute `{device key}` with the device key you saved earlier when setting up the simulated device.
186+
Double-click on the solution file (IoT_SimulatedDevice.sln) to open the code in Visual Studio, then open Program.cs. Substitute `{your hub name}` with the IoT hub host name. The format of the IoT hub host name is **{iot-hub-name}.azure-devices.net**. For this tutorial, the hub host name is **ContosoTestHub.azure-devices.net**. Next, substitute `{your device key}` with the device key you saved earlier when setting up the simulated device.
183187

184188
```csharp
185-
static string myDeviceId = "contoso-test-device";
186-
static string iotHubUri = "ContosoTestHub.azure-devices.net";
189+
static string s_myDeviceId = "Contoso-Test-Device";
190+
static string s_iotHubUri = "ContosoTestHub.azure-devices.net";
187191
// This is the primary key for the device. This is in the portal.
188192
// Find your IoT hub in the portal > IoT devices > select your device > copy the key.
189-
static string deviceKey = "{your device key here}";
193+
static string s_deviceKey = "{your device key}";
190194
```
191195

192196
## Run and test
@@ -207,15 +211,17 @@ If everything is set up correctly, at this point you should see the following re
207211
* The Logic App retrieving the message from the Service Bus queue is working correctly.
208212
* The Logic App connector to Outlook is working correctly.
209213

210-
2. In the [Azure portal](https://portal.azure.com), select **Resource groups** and select your Resource Group. This tutorial uses **ContosoResources**. Select the storage account, select **Blobs**, then select the Container. This tutorial uses **contosoresults**. You should see a folder, and you can drill down through the directories until you see one or more files. Open one of those files; they contain the entries routed to the storage account.
214+
2. In the [Azure portal](https://portal.azure.com), select **Resource groups** and select your Resource Group. This tutorial uses **ContosoResources**.
215+
216+
Select the storage account, select **Containers**, then select the Container. This tutorial uses **contosoresults**. You should see a folder, and you can drill down through the directories until you see one or more files. Open one of those files; they contain the entries routed to the storage account.
211217

212218
![The result files in storage](./media/tutorial-routing-view-message-routing-results/results-in-storage.png)
213219

214220
This result means the following statement is true.
215221

216222
* The routing to the storage account is working correctly.
217223

218-
Now with the application still running, set up the Power BI visualization to see the messages coming through the default routing.
224+
Now, with the application still running, set up the Power BI visualization to see the messages coming through the default routing.
219225

220226
## Set up the Power BI visualizations
221227

@@ -245,11 +251,11 @@ Now with the application still running, set up the Power BI visualization to see
245251

246252
A line chart is created. The x-axis displays date and time in the UTC time zone. The y-axis displays temperature from the sensor.
247253

248-
6. Create another line chart to show real-time humidity over time. To set up the second chart, follow the same steps above and place **EventEnqueuedUtcTime** on the x-axis and **humidity** on the y-axis.
254+
6. Create another line chart to show real-time humidity over time. To set up the second chart, follow the same process for the first chart, placing **EventEnqueuedUtcTime** on the x-axis (**Axis**) and **humidity** on the y-axis (**Values**).
249255

250256
![The final Power BI report with the two charts](./media/tutorial-routing-view-message-routing-results/power-bi-report.png)
251257

252-
7. Select **Save** to save the report.
258+
7. Select **Save** to save the report, entering a name for the report if prompted.
253259

254260
You should be able to see data on both charts. This result means the following statements are true:
255261

@@ -261,7 +267,7 @@ You can refresh the charts to see the most recent data by selecting the Refresh
261267

262268
## Clean up resources
263269

264-
If you want to remove all of the resources you've created through both parts of this tutorial, delete the resource group. This action deletes all resources contained within the group. In this case, it removes the IoT hub, the Service Bus namespace and queue, the Logic App, the storage account, and the resource group itself.
270+
If you want to remove all of the Azure resources you've created through both parts of this tutorial, delete the resource group. This action deletes all resources contained within the group. In this case, it removes the IoT hub, the Service Bus namespace and queue, the Logic App, the storage account, and the resource group itself. You can also remove the Power BI resources and clear the emails sent during the tutorial.
265271

266272
### Clean up resources in the Power BI visualization
267273

@@ -283,6 +289,10 @@ To remove the resource group, use the [Remove-AzResourceGroup](https://docs.micr
283289
Remove-AzResourceGroup -Name $resourceGroup
284290
```
285291

292+
### Clean up test emails
293+
294+
You may also want to delete the quantity of emails in your inbox that were generated through the Logic App while the device application was running.
295+
286296
## Next steps
287297

288298
In this 2-part tutorial, you learned how to use message routing to route IoT Hub messages to different destinations by performing the following tasks.

0 commit comments

Comments
 (0)