【发布时间】:2019-05-21 08:08:07
【问题描述】:
我有一个将二进制数据包发送到服务器的设备。我想将它迁移到 Azure IoT 中心。我想坚持使用二进制数据本身并在 Azure 函数中解析二进制数据。
我使用 Azure SDK 在 .NET 中编写了设备模拟器,并编写了在 IoT Hub 上收到消息时触发的 Azure 函数。
设备模拟器上的代码:
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);
在 Azure 函数中 - 如果我转换
public static void Run(string myIoTHubMessage, ILogger log)
{
byte[] dataArray = Encoding.ASCII.GetBytes(myIoTHubMessage);
}
在这里我尝试了不同类型的编码来将 myIoTHubMessage 转换为字节数组,但没有成功。
【问题讨论】:
-
它是否显示任何错误?可以打印日志吗?
标签: azure azure-iot-hub