You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this section, you create a .NET console app, using C#, that adds location metadata to the device twin associated with **myDeviceId**. The app queries IoT hub for devices located in the US and then queries devices that report a cellular network connection.
47
-
48
-
1. In Visual Studio, select **File > New > Project**. In **Create a new project**, select **Console App (.NET Framework)**, and then select **Next**.
49
-
50
-
1. In **Configure your new project**, name the project **AddTagsAndQuery**, the select **Next**.
51
-
52
-
:::image type="content" source="./media/iot-hub-csharp-csharp-twin-getstarted/config-addtagsandquery-app.png" alt-text="Screenshot of how to create a new Visual Studio project." lightbox="./media/iot-hub-csharp-csharp-twin-getstarted/config-addtagsandquery-app.png":::
53
-
54
-
1. Accept the default version of the .NET Framework, then select **Create** to create the project.
55
-
56
-
1. In Solution Explorer, right-click the **AddTagsAndQuery** project, and then select **Manage NuGet Packages**.
57
-
58
-
1. Select **Browse** and search for and select **Microsoft.Azure.Devices**. Select **Install**.
This step downloads, installs, and adds a reference to the [Azure IoT service SDK](https://www.nuget.org/packages/Microsoft.Azure.Devices/) NuGet package and its dependencies.
63
-
64
-
1. Add the following `using` statements at the top of the **Program.cs** file:
query =registryManager.CreateQuery("SELECT * FROM devices WHERE tags.location.plant = 'Redmond43' AND properties.reported.connectivity.type = 'cellular'", 100);
The**RegistryManager**classexposes all the methods required to interact with device twins from the service. The previous code first initializes the **registryManager** object, then retrieves the device twin for **myDeviceId**, and finally updates its tags with the desired location information.
108
-
109
-
After updating, it executes two queries: thefirstselectsonlythedevicetwinsofdeviceslocatedinthe **Redmond43** plant, andthesecondrefinesthequerytoselectonlythedevicesthatarealsoconnectedthroughcellularnetwork.
1. Runthisapplicationbyright-clickingonthe**AddTagsAndQuery**projectandselecting**Debug**, followedby**Startnewinstance**. Youshouldseeonedeviceintheresultsfor the query asking for all devices located in **Redmond43** and none for the query that restricts the results to devices that use a cellular network.
123
-
124
-

In this section, you create a .NET console app that connects to your hub as **myDeviceId**, and then updates its reported properties to confirm that it's connected using a cellular network.
1. In **Configure your new project**, name the project **ReportConnectivity**, then select **Next**.
135
53
136
54
1. In Solution Explorer, right-click the **ReportConnectivity** project, and then select **Manage NuGet Packages**.
137
55
56
+
1. Keep the default .NET Framework, then select **Create** to create the project.
57
+
138
58
1. Select **Browse** and search for and choose **Microsoft.Azure.Devices.Client**. Select **Install**.
139
59
140
60
This step downloads, installs, and adds a reference to the [Azure IoT device SDK](https://www.nuget.org/packages/Microsoft.Azure.Devices.Client/) NuGet package and its dependencies.
@@ -234,6 +154,88 @@ In this section, you create a .NET console app that connects to your hub as **my
Thisstepdownloads, installs, andaddsareferencetothe [AzureIoTserviceSDK](https://www.nuget.org/packages/Microsoft.Azure.Devices/) NuGet package and its dependencies.
query =registryManager.CreateQuery("SELECT * FROM devices WHERE tags.location.plant = 'Redmond43' AND properties.reported.connectivity.type = 'cellular'", 100);
The**RegistryManager**classexposes all the methods required to interact with device twins from the service. The previous code first initializes the **registryManager** object, then retrieves the device twin for **myDeviceId**, and finally updates its tags with the desired location information.
221
+
222
+
After updating, it executes two queries: thefirstselectsonlythedevicetwinsofdeviceslocatedinthe **Redmond43** plant, andthesecondrefinesthequerytoselectonlythedevicesthatarealsoconnectedthroughcellularnetwork.
1. Runthisapplicationbyright-clickingonthe**AddTagsAndQuery**projectandselecting**Debug**, followedby**Startnewinstance**. Youshouldseeonedeviceintheresultsfor the query asking for all devices located in **Redmond43** and none for the query that restricts the results to devices that use a cellular network.
236
+
237
+

0 commit comments