Florian Boehmak
Florian Boehmak

Reputation: 501

Create a IoT Edge device with C#

I am trying to create an IoT Edge device with C#, but I have difficulties finding the methods for the C# client.

Can someone point me in the right direction? Thank you.

Here is the place in the Azure REST API Reference: https://learn.microsoft.com/en-us/rest/api/iotcentral/devices/set

This is the pure REST call, which works:

PUT https://{{iotHubName}}.azure-devices.net/devices/{{edgeDeviceId}}?api-version={{iotApiVersion}}
{"deviceId": "client1", "capabilities": {"iotEdge": true} }

Upvotes: 0

Views: 430

Answers (1)

Matthijs van der Veer
Matthijs van der Veer

Reputation: 4085

You can use the registry manager in

https://www.nuget.org/packages/Microsoft.Azure.Devices/

See you code below, you have to create a device with the IoTEdge capability

class Program
{
    private static string s_connectionString = "HostName=your-iot-hub.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=sofakereally+HPuqIP1Wo72jvF8J6eh1o=";

    static async System.Threading.Tasks.Task Main(string[] args)
    {
        var registryManager = RegistryManager.CreateFromConnectionString(s_connectionString);
        var device = new Device("such-edge");
        device.Capabilities = new Microsoft.Azure.Devices.Shared.DeviceCapabilities() {
            IotEdge = true
        };
        await registryManager.AddDeviceAsync(device);
    }
}

Upvotes: 2

Related Questions