gpt4 book ai didi

azure - 将 IoTHub 设备遥测消息路由到存储帐户和 Power BI

转载 作者:行者123 更新时间:2023-12-03 03:36:54 25 4
gpt4 key购买 nike

我正在尝试为连接到 Azure IoTHub 的设备路由设备遥测数据。

我已在将消息路由到存储帐户时定义了自定义终结点,并将编码格式设置为 JSON,并将路由查询设置为 true。

这已成功将数据发送到存储帐户,但消息正文中的遥测数据采用 Base 64,如下所示

{"EnqueuedTimeUtc":"2022-07-13T13:03:28.4770000Z","Properties":{},"SystemProperties":{"connectionDeviceId":"SensorTile","connectionAuthMethod":"{\"scope\":\"device\",\"type\":\"sas\",\"issuer\":\"iothub\",\"acceptingIpFilterRule\":null}","connectionDeviceGenerationId":"6*********971","enqueuedTime":"2022-07-13T13:03:28.4770000Z"},"Body":"eyJBY2NlbGVyb21ldGVyIjp7IlkiOi0xNSwiWCI6MTAsIloiOjEwMzZ9LCJ0cyI6IjIwMjItMDctMTNUMTU6MDM6MjguNDAwKzAyMDAiLCJpZCI6IlNlbnNvclRpbGUifQ=="}

阅读documentation “使用 JSON 编码时,必须在消息系统属性中将 contentType 设置为 application/json,将 contentEncoding 设置为 UTF-8。这两个值都不区分大小写。如果未设置内容编码,则 IoT 中心将写入Base 64 编码格式的消息。”

我知道可以通过将 systemProperties contentType 设置为 application/json 并将 contentEncoding 设置为 UTF-8 将数据转换为 UTF-8 格式,但我不确定在哪里以及如何实际执行此操作,或者我可以使用其他服务(例如 Stream Analytics/Fuctions/EventHub)来实现此目的吗?

还可以通过路由查询过滤消息,以便仅路由遥测数据而忽略其余数据吗?

非常感谢任何帮助

最佳答案

发送消息时需要设置内容类型和内容编码。这意味着设备负责设置属性。以下是不同语言的一些示例。

C#

using var eventMessage = new Message(Encoding.UTF8.GetBytes(messagePayload))
{
ContentEncoding = Encoding.UTF8.ToString(),
ContentType = "application/json",
};

C

IOTHUB_MESSAGE_HANDLE message_handle = IoTHubMessage_CreateFromString(message);
(void)IoTHubMessage_SetContentTypeSystemProperty(message_handle, "application%2fjson");
(void)IoTHubMessage_SetContentEncodingSystemProperty(message_handle, "utf-8");

Java

Message msg = new Message(msgStr);
msg.setContentType("application/json");
msg.setProperty("temperatureAlert", temperature > 28 ? "true" : "false");

关于azure - 将 IoTHub 设备遥测消息路由到存储帐户和 Power BI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72981832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com