The IoT simulator can easily be containerized in order to simplify its delivery and use. Also, .NET 6 includes interesting capabilities to build lighter and/or selfsufficient applications (ex: selfcontained with trim build options).
If you need detailed documentation about what Azure IoT Device Simulator is, you can find additional information at:
Ports used by the simulator:
- 8883 (MQTT)
- 5671 (AMQP)
- 443 (HTTPS) Ports required to communicate with Microsoft Azure IoT Hub.
The Azure IoT Device Simulator needs two basic prerequisites before starting:
- settings (do not forget to update the connection strings)
- the referenced DTDL models have to be reachable (from the device as well as from the cloud solution)
Settings are based on 3 files:
For details and explanations, see help.
Tip
The solution takes into account settings depending on the environment. It can be set trough the environment variable ENVIRONMENT. The solution looks for settings files following the pattern file.ENVIRONMENT.json (similar to the former transformation files). Default setting files will be loaded first in case no environment file is found.
This file allows configuring system related items (logs, etc).
Release
Minimal logs settings.
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
}
}
Development (appsettings.Development.json)
Detailed logs settings.
{
"Logging": {
"Debug": {
"LogLevel": {
"Default": "Trace"
}
},
"Console": {
"IncludeScopes": true,
"LogLevel": {
"Default": "Trace"
}
},
"LogLevel": {
"Default": "Trace",
"System": "Trace",
"Microsoft": "Trace"
}
}
}
This file allows to configure the device simulation settings.
{
"connectionString": "[IOT HUB NAME].azure-devices.net;DeviceId=[DEVIVE ID];SharedAccessKey=[SHARED KEY]",
"defaultModelId": "dtmi:com:example:thermostat;1",
"supportedModels": [
{
"modelId": "dtmi:com:example:thermostat;1",
"modelPath": "[HTTP path or local physical path to the model definition]",
"modelType": "Telemetry" //Telemetry, Error, Warning
},
{
"modelId": "dtmi:com:jmi:simulator:devicemessages;1",
"modelPath": "[HTTP path or local physical path to the model definition]",
"modelType": "Telemetry" //Telemetry, Error, Warning
}
],
"simulationSettings": {
"enableLatencyTests": false,
"latencyTestsFrecuency": 30,
"enableDevice": true,
"enableModules": false,
"enableTelemetryMessages": true,
"telemetryFrecuency": 10,
"enableErrorMessages": false,
"errorFrecuency": 20,
"enableCommissioningMessages": false,
"commissioningFrecuency": 30,
"enableTwinReportedMessages": false,
"twinReportedMessagesFrecuency": 60,
"enableReadingTwinProperties": false,
"enableC2DDirectMethods": true,
"enableC2DMessages": true,
"enableTwinPropertiesDesiredChangesNotifications": true
}
}
This file allows to configure the module(s) simulation settings.
{
"modules":[
{
"connectionString": "[IOT HUB NAME].azure-devices.net;DeviceId=[DEVIVE ID];ModuleId=[MODULE ID];SharedAccessKey=[SHARED KEY]",
"defaultModelId": "dtmi:com:example:thermostat;1",
"supportedModels": [
{
"modelId": "dtmi:com:example:thermostat;1",
"modelPath": "./DTDLModels/thermostat.json",
"modelType": "Telemetry"
}
],
"simulationSettings": {
"enableTelemetryMessages": true,
"telemetryFrecuency": 20,
"enableTwinReportedMessages": false,
"twinReportedMessagesFrecuency": 60,
"enableReadingTwinProperties": true,
"enableC2DDirectMethods": true,
"enableC2DMessages": true,
"enableTwinPropertiesDesiredChangesNotifications": true
}
},
{
"connectionString": "[IOT HUB NAME].azure-devices.net;DeviceId=[DEVIVE ID];ModuleId=[MODULE ID];SharedAccessKey=[SHARED KEY]",
"defaultModelId": "dtmi:com:example:thermostat;1",
"supportedModels": [
{
"modelId": "dtmi:com:example:thermostat;1",
"modelPath": "./DTDLModels/thermostat.json",
"modelType": "Telemetry"
}
],
"simulationSettings": {
"enableTelemetryMessages": true,
"telemetryFrecuency": 20,
"enableTwinReportedMessages": false,
"twinReportedMessagesFrecuency": 60,
"enableReadingTwinProperties": true,
"enableC2DDirectMethods": true,
"enableC2DMessages": true,
"enableTwinPropertiesDesiredChangesNotifications": true
}
}
]
}
Important
Do not forget to set your own values for the connectionString
parameter.
Regular
dotnet IoT.Simulator.dll
Changing the environment
Linux
export ENVIRONMENT=Development
dotnet IoT.Simulator.dll
Windows
set ENVIRONMENT=Development
dotnet IoT.Simulator.dll