Niobium.Device.IoTHub 4.2.66

dotnet add package Niobium.Device.IoTHub --version 4.2.66
                    
NuGet\Install-Package Niobium.Device.IoTHub -Version 4.2.66
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Niobium.Device.IoTHub" Version="4.2.66" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Niobium.Device.IoTHub" Version="4.2.66" />
                    
Directory.Packages.props
<PackageReference Include="Niobium.Device.IoTHub" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Niobium.Device.IoTHub --version 4.2.66
                    
#r "nuget: Niobium.Device.IoTHub, 4.2.66"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Niobium.Device.IoTHub@4.2.66
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Niobium.Device.IoTHub&version=4.2.66
                    
Install as a Cake Addin
#tool nuget:?package=Niobium.Device.IoTHub&version=4.2.66
                    
Install as a Cake Tool

Niobium.Device.IoTHub

Niobium.Device.IoTHub provides a ready-to-use implementation of the IIoTCommander interface for Azure IoT Hub, enabling .NET applications to send commands to IoT devices using Azure's secure, scalable device messaging infrastructure.

What is this project about?

  • Implements AzureIoTHubCommander, an IIoTCommander for Azure IoT Hub.
  • Provides dependency injection modules for easy integration.
  • Handles both direct method invocation and cloud-to-device messaging.
  • Supports fire-and-forget and request/response command patterns.
  • Integrates with the Niobium.Device abstraction for seamless device command execution.

Getting Started

1. Install the NuGet Package

Add the package to your .NET project:

dotnet add package Niobium.Device.IoTHub

2. Register Azure IoT Hub Commander in Dependency Injection

In your DI setup (e.g., Program.cs):

using Niobium.Device.IoTHub;
using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection();
services.AddDevice();

This registers AzureIoTHubCommander as the default IIoTCommander.

3. Configure Azure IoT Hub Connection

Set the IOT_HUB_CONN configuration key to your Azure IoT Hub connection string (e.g., via environment variable or appsettings):

IOT_HUB_CONN=HostName=your-iothub.azure-devices.net;SharedAccessKeyName=service;SharedAccessKey=...

4. Execute Commands on Devices

using Niobium.Device;

public class DeviceService
{
    private readonly IIoTCommander _commander;
    public DeviceService(IIoTCommander commander)
    {
        _commander = commander;
    }

    public async Task<bool> TurnOnDeviceAsync(string deviceId)
    {
        var command = new { Action = "TurnOn" };
        var result = await _commander.ExecuteAsync(deviceId, command, fireAndForget: false);
        if (result != null && result.Status == 200)
        {
            var payload = result.GetPayload<MyDeviceResponse>();
            // Use payload as needed
            return true;
        }
        return false;
    }
}

public class MyDeviceResponse
{
    public string Result { get; set; }
}

5. Fire-and-Forget Commands

await _commander.ExecuteAsync("device-id", new { Action = "Ping" }, fireAndForget: true);

6. Advanced: Handling Device Offline/Retry

AzureIoTHubCommander automatically retries on transient errors and logs device offline events. You can override OnDeviceOfflineAsync for custom handling in a derived class.

7. Extending/Customizing

  • You can inherit from AzureIoTHubCommander to customize retry logic, logging, or device offline handling.
  • You can register your own IIoTCommander implementation if you need to support other protocols or device types.

How Niobium.Device.IoTHub is Consumed

Consumer projects use Niobium.Device.IoTHub to:

  • Register and use Azure IoT Hub device command senders via DI.
  • Standardize command execution and result handling for Azure-connected IoT devices.
  • Rapidly prototype and deploy device integration features in business applications.

Contributing

Contributions are welcome! To contribute:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with clear commit messages
  4. Submit a pull request

Please ensure your code follows the existing style and includes appropriate tests and documentation.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.2.66 91 9/4/2026
4.0.60 86 8/30/2026
4.0.57 91 8/29/2026
4.0.53 96 8/27/2026
4.0.42 112 7/18/2026
4.0.37 101 7/17/2026
4.0.35 106 7/17/2026
4.0.34 100 7/17/2026
4.0.33 106 7/16/2026
4.0.32 114 7/2/2026
3.4.30 207 12/22/2025
3.4.29 305 11/11/2025
3.4.28 185 11/2/2025
3.4.27 147 11/1/2025
3.4.26 146 11/1/2025
3.4.25 150 11/1/2025
3.4.24 182 10/31/2025
3.2.23 133 10/18/2025
3.2.22 177 10/17/2025
3.2.21 168 10/17/2025
Loading failed