根据文档,在azure IoT Hub中,发送超过256KB的设备到云消息没有引发任何错误.如何



我正在从注册设备发送一个约720 KB的遥测数据,该数据超过了设备到云消息传递所允许的最大消息大小,如下文所示。

使用Microsoft 提供的IoT Hub nodejs sdk发送

MS文档

文件中如下所述

设备到云消息:最大消息大小256 KB

那么这个限制是多少?我的理解错了吗?

我测量了字节计数,并在发送之前将其记录下来,以找出大小。

查看Azure IoT C#SDK抛出超过256KB的错误消息我想你对720 KB的假设是错误的,请检查我的屏幕截图和代码,我将数据批量处理到500 KB以上,设备SDK发现消息超出了允许的限制。

// Async method to send simulated telemetry
private static async Task SendDeviceToCloudMessagesAsync(CancellationToken ct)
{
// Initial telemetry values
double minTemperature = 20;
double minHumidity = 60;
var rand = new Random();
while (!ct.IsCancellationRequested)
{
double currentTemperature = minTemperature + rand.NextDouble() * 15;
double currentHumidity = minHumidity + rand.NextDouble() * 20;
JArray a = new JArray();
string messageBody = null;
bool messageSize = true;
// Create JSON message
while (messageSize)
{
messageBody = JsonSerializer.Serialize(
new
{
temperature = currentTemperature,
humidity = currentHumidity,
vibration = rand.NextDouble() * 15,
moisture = rand.NextDouble() * 15,
O2 = rand.NextDouble() * 15
});
// messageCollectionBody = messageCollectionBody + messageBody + ",";
a.Add(messageBody);
int msgSize = System.Text.ASCIIEncoding.Unicode.GetByteCount(a.ToString());
if (msgSize >= 556000)   // set anything above 270 KB to observe the error!
{
messageSize = false;
}
}
using var message = new Message(Encoding.ASCII.GetBytes(a.ToString()))
{
ContentType = "application/json",
ContentEncoding = "utf-8",
};
// Add a custom application property to the message.
// An IoT hub can filter on these properties without access to the message body.
message.Properties.Add("temperatureAlert", (currentTemperature > 30) ? "true" : "false");
// Send the telemetry message
await s_deviceClient.SendEventAsync(message);
Console.WriteLine($"{DateTime.Now} > Sending message: {a.ToString()}");
await Task.Delay(1000);
}
}

最新更新