Hello Bashar, greetings! Welcome to Microsoft Q&A forum. Thank you for posting the question. We would be glad to assist you on this issue.
Could you please help us understand your workflow here. You have stated that you are using an IoT device called "eWon Flexy" to push the real time data directly to Azure IoT. The code sample you have provided uses EventHubProducerClient which is used to push data the Event Hub and not IoT Hub. Is there another part of the application that uses DeviceClient and pushes data to the Azure IoT Hub. Ideally, you would want the data to be pushed to IoT Hub and then routed to Event Hub using Message Routing Please let us know if you are trying to use this approach.
Looking at the information provided by AVEVA, the data propably needs to be in JSON format. If you were using a Device client SDK to send the data to IoT Hub, you would need to include the Encoding type as UTF8 and Content type as application/json before you deliver the message. Please refer the below code to find an example using Device Client
using System.Text;
using Microsoft.Azure.Devices.Client;
using Newtonsoft.Json;
namespace HelloWorld
{
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Hello World!");
string deviceKey1 = "<DeviceKey>";
string deviceId1 = "<DeviceName>";
string iotHubHostName = "<HostName>";
var deviceAuthentication1 = new DeviceAuthenticationWithRegistrySymmetricKey(deviceId1, deviceKey1);
DeviceClient deviceClient1 = DeviceClient.Create(iotHubHostName, deviceAuthentication1, TransportType.Mqtt);
Random Rand = new Random();
var _messageId1 = 1;
string[] channel = { "Channel", "Function" };
while (true)
{
double currentTemperature = 20 + Rand.NextDouble() * 15;
double currentHumidity = 60 + Rand.NextDouble() * 20;
var telemetryDataPoint1 = new
{
messageId = _messageId1++,
deviceId = deviceId1,
source = channel[Rand.Next(0,2)],
temperature = currentTemperature,
humidity = currentHumidity
};
string messageString = JsonConvert.SerializeObject(telemetryDataPoint1);
Message message = new Message(Encoding.ASCII.GetBytes(messageString));
message.ContentEncoding = "utf-8";
message.ContentType = "application/json";
message.Properties.Add("temperatureAlert", (currentTemperature > 30) ? "true" : "false");
await deviceClient1.SendEventAsync(message);
Console.WriteLine("{0} > Sending message: {1}", DateTime.Now, messageString);
await Task.Delay(10000);
}
}
}
}
Let us know if the above share information is useful. Please do not hesitate to reach out to us if you have any additional questions on this.