This repo can be used as a template repo to create new MQTT devices using MQTTnet.Extensions.MultiCloud
dotnet new install IoTModels.MqttDevice.Template
dotnet new mqtt-device -o myDevice
- A dotnet 6.0 worker project
- With references to MQTTnet MultiCloud extensions
- A sample device template model
- The C# interface representing the device model
- Implementations for Azure IoT Hub and any MQTT Broker
- Sample Device implementation
- Default launch settings for different endpoints
The device implements:
sdkInfo
as a reported property of typestring
interval
as a desired property of typeint
temp
as a telemetry of typedouble
(uses random values)echo
a command that receives astring
and returns anotherstring
The dotnet project contains a launchSettings.json
with some pre-configured profiles.
To connect to a local MQTT broker like mosquitto, you can use the mosquitto-local Docker image. To connect with TLS you have to provide the CA certificate.
docker run -it --rm -p 8080:8080 -p 1883:1883 -p 8883:8883 -p 8884:8884 -p 8443:8443 ridomin/mosquitto-local:dev
To use Azure IoT Hub, create a device identity and provide the device connection string To use DPS, or Central, provide IdScope and enrollment details.
-
When targeting a MQTT broker, you can use iotux-mqtt and connect to the broker configured
-
When targeting Azure IoT Hub, you can use IoT Explorer
-
When targeting Azure IoT Central, create a device template based on the DTDL sample model