问题描述
我正在尝试创建从 IoT 中心到 Power BI 的流分析作业,但我的输入数据接缝无效。开始作业后,我收到此错误代码: InputDeserializerError.InvalidData 。我的事件序列化格式是 JSON。 我通过 azure shell 监控我的消息,它们看起来像这样:
"event": {
"origin": "Projektpi","module": "","interface": "","component": "","payload": "{\"Time\": 19/04/2021,13:22:33,\"Critical vibration\": No,\"Temperature\": 20.812,\"RPM\": 0.0}"
}
每 11 秒我通过此代码从我的 pi 发送消息:
client = IoTHubDeviceClient.create_from_connection_string(CONNECTION_STRING)
async def send_to_azure(payload):
# await internet connection
awaitConnection()
# payload looks like this: payload = '{{"Time": {Now},"Critical vibration": {azurevibration},"Temperature": {azuretemp},"RPM": {azurerpm}}}'
message = Message(payload)
# Send a message to the IoT hub
print(f"Sending message: {message}")
try:
print('Status: Trying to send data to Azure IoT Hub...')
await client.connect()
await client.send_message(message)
print('Status: Data sent ...')
except:
print('Status: Problem sending data to Azure IoT Hub...')
我必须如何更改我的代码,以便流分析作业可以使用我的 pi 传感器数据作为输入? 如果您知道 Python 教程等,那就太好了。 我对 azure 和一般编程很陌生,所以非常感谢您的帮助!
解决方法
您的负载包含一些无效的 JSON。流分析将尝试反序列化您的 JSON 负载并遇到错误。错误的有效载荷由两个属性引起:
- “时间”
- “临界振动”
两者都缺少值周围的双引号,文本字段需要这些,而不是数字字段。这应该是正确的格式:
"event": {
"origin": "Projektpi","module": "","interface": "","component": "","payload": "{\"Time\": \"19/04/2021,13:22:33\",\"Critical vibration\": \"No\",\"Temperature\": 20.812,\"RPM\": 0.0}"
}
为清楚起见,我将包含您的有效载荷的未转义版本:
{
"Time":"19/04/2021,13:22:33","Critical vibration":"No","Temperature":20.812,"RPM":0.0
}