I have a device which is sending the binary data packet to the server. I want to migrate that to Azure IoT hub. I want to stick with binary data itself and parse binary data in the Azure function.
I have written the device simulator in .NET using Azure SDK and written the Azure function which gets triggered when message received on IoT Hub.
Code at the Device simulator:
double currentTemperature = 23.0;
byte[] temp= BitConverter.GetBytes(currentTemperature);
double currentHumidity = 24.0;
byte[] humidity= BitConverter.GetBytes(currentHumidity);
List<byte> bytes = new List<byte>();
bytes.AddRange(temp);
bytes.AddRange(humidity);
DeviceClient s_deviceClient; // Created device client here.
var message = new Microsoft.Azure.Devices.Client.Message(bytes.ToArray());
await s_deviceClient.SendEventAsync(message);
In Azure function - If I convert
public static void Run(string myIoTHubMessage, ILogger log)
{
byte[] dataArray = Encoding.ASCII.GetBytes(myIoTHubMessage);
}
Here I have tried different types of encoding to covert myIoTHubMessage to byte array, but it did not worked.