【发布时间】:2020-10-09 20:34:07
【问题描述】:
我有这个传感器:
https://cdn.antratek.nl/media/wysiwyg/pdf/RM_Sound_Level_Sensor_20200319_BQW_02_0011.pdf
我正在使用 Azure IoT Hub 从设备流式传输消息。
由于这是一个 lorawan 传感器,我需要使用自定义解码器对有效载荷进行解码。
我在这里找到了这个很棒的文档: https://github.com/Azure/iotedge-lorawan-starterkit/blob/9124bc46519eccd81a9f0faf0bc8873e410d31a6/Samples/DecoderSample/ReadMe.md
我有一些代码:
internal static class LoraDecoders
{
private static string DecoderValueSensor(string devEUI, byte[] payload, byte fport)
{
// EITHER: Convert a payload containing a string back to string format for further processing
var result = Encoding.UTF8.GetString(payload);
// OR: Convert a payload containing binary data to HEX string for further processing
var result_binary = ConversionHelper.ByteArrayToString(payload);
// Write code that decodes the payload here.
// Return a JSON string containing the decoded data
return JsonConvert.SerializeObject(new { value = result });
}
}
现在问题是基于上面第 4.1.2 节的文档
这行之后我应该在 .net 中做什么:
var result_binary = ConversionHelper.ByteArrayToString(payload);
// Write code that decodes the payload here.
【问题讨论】:
-
我会使用字符串结果。尝试添加 Console.WriteLine(result);
标签: c# json .net-core decode azure-iot-hub