AzureIoTHub : How to send telemetry data in JSON format?

标签 azure azure-iot-hub arduino-esp8266 azure-iot-sdk

我使用 Azure 的示例存储库来发送遥测数据:https://github.com/Azure/azure-iot-arduino/tree/master/examples/esp8266/iothub_ll_telemetry_sample

我没有修改任何代码。这是重要的部分:

const char* telemetry_msg = "test_message";
message_handle = IoTHubMessage_CreateFromString(telemetry_msg);
result = IoTHubDeviceClient_LL_SendEventAsync(device_ll_handle, message_handle, send_confirm_callback, NULL);

为什么我的 body-result 看起来像一个 ASCII 数组? (注:使用Azure IoT资源管理器)

它应该是这样的数组吗?我必须在另一侧解压该数组吗?

enter image description here

我希望能够像 azure 设备模拟器那样以 JSON 格式发送数据:

enter image description here

最佳答案

没关系,想通了。以下示例将以 JSON 格式发送数据:

char telemetry_msg_buffer[80];
sprintf(telemetry_msg_buffer, "{\"temperature\":11.11,\"humidity\":12.12,\"scale\":\"13.13\"}");
message_handle = IoTHubMessage_CreateFromString(telemetry_msg_buffer);

关于AzureIoTHub : How to send telemetry data in JSON format?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66625334/

相关文章:

c# - 使用 C# 在 azure iot hub 上批量导入注册设备不起作用?

c++ - 从串行数据读取的长度始终为1

Arduino esp8266中的c++函数修改了c文件中生成的 float ,c++函数退出后在c文件中看到乱码

.net - 将 ADF json 文件上传到我的数据工厂

c# - ASP.Net Web Api响应未经授权的访问

azure - 未从 Azure IoT MQTT 代理接收订阅主题的消息

c# - Azure IoT 中心中的 TCP 支持

arduino - ESP8266/Arduino : Why is it necessary to add the ICACHE_RAM_ATTR macro to ISRs and functions called from there?

Azure B2C SSO 配置选项差异

Azure APIM 策略 : Set default value for requestParameter