Hi @GuidoL Greetings! I have looked into the code sample and could extract a simplified version to simulate the same data. Please refer the following code sample
using System;
using Microsoft.Azure.Devices.Client;
using System.Text;
using Newtonsoft.Json;
namespace MyApp // Note: actual namespace depends on the project name.
{
internal class SimpleApp
{
private const string ModelId = "dtmi:digitaltwins:org:archive:download:rfidsmartlibrary:RfidSmartLibraryowl:LibraryItemGateCheckSensor;1";
public static string DeviceId = "<DeviceId";
public static string DeviceSymmetricKey = "<DevicePrimaryKey>";
public static string hostname = "<IoTCentralHostname>";
static async Task Main(string[] args)
{
Console.WriteLine("Hello World!");
var authMethod = new DeviceAuthenticationWithRegistrySymmetricKey(DeviceId, DeviceSymmetricKey);
var options = new ClientOptions
{
ModelId = ModelId,
};
DeviceClient deviceClient = DeviceClient.Create(hostname, authMethod, TransportType.Mqtt, options);
var cts = new CancellationTokenSource();
List<string> ItemID = new List<string>() { "Item1", "Item2", "Item3", "Item4" };
List<string> Description = new List<string>() { "Des 1", "Des 2", "Des 3", "Des 4", "Des 5", "Des 6", "Des 7" };
List<string> Location = new List<string>() { "Downingtown", "Midtown", "Redmond", "Hyderabad" };
Random randNum = new Random();
while (true)
{
string telemetryName = "ItemId";
int index = randNum.Next(ItemID.Count);
Encoding messageEncoding = Encoding.UTF8;
IDictionary<string, object> telemetryPairs = new Dictionary<string, object> { { telemetryName, ItemID[index] } };
telemetryName = "Description";
index = randNum.Next(Description.Count);
telemetryPairs.Add(telemetryName, Description[index]);
telemetryName = "Location";
index = randNum.Next(Location.Count);
telemetryPairs.Add(telemetryName, Location[index]);
telemetryName = "DateTimeGateEvent";
DateTime time = DateTime.Now;
telemetryPairs.Add(telemetryName, time);
string payload = JsonConvert.SerializeObject(telemetryPairs);
var message = new Message(messageEncoding.GetBytes(payload))
{
ContentEncoding = messageEncoding.WebName,
ContentType = "application/json",
};
await deviceClient.SendEventAsync(message, cts.Token);
Console.WriteLine("Message delivered");
Thread.Sleep(30000);
}
}
}
}
Please replace the ModelId, DeviceId, DeviceSymmetricKey, hostname in the code with the appropriate values. Note that the easiest way to obtain the hostname is by putting a break point on the line 165 in Program.cs file of TemperatureController project
DeviceClient deviceClient = DeviceClient.Create(hostname, authenticationMethod, TransportType.Mqtt, options);
Running this code would simulate the data on to IoT Central without any issues. Please refer the following image.
Hope this helps. Please let us know if you have any additional questions or need further assistance.
If the response helped, please do click Accept Answer and Yes. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.