I am trying to create a stream analytics job from my IoT Hub to Power BI but my Input data seams to be invalid. After starting the Job I get this Error Code: InputDeserializerError.InvalidData . My Event serialization format is JSON. I monitored my messages via the azure shell and they look like this:
"event": {
"origin": "Projektpi",
"module": "",
"interface": "",
"component": "",
"payload": "{\"Time\": 19/04/2021, 13:22:33, \"Critical vibration\": No, \"Temperature\": 20.812, \"RPM\": 0.0}"
}
Every 11 seconds I send messages from my pi via this code:
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...')
How do I have to change my code so that the Stream Analytics Job can use my pi sensor data as Input? If you know of a python tutorial etc. that would be great. I am quite new to azure and programming in general so thank you very much for your help!
Your payload contains some invalid JSON. Stream Analytics will try to deserialize your JSON payload and run into an error. The faulty payload is caused by two properties:
Both are missing double quotes around the value, these are needed for text fields, not for numerical fields. This should be the correct format:
"event": {
"origin": "Projektpi",
"module": "",
"interface": "",
"component": "",
"payload": "{\"Time\": \"19/04/2021, 13:22:33\", \"Critical vibration\": \"No\", \"Temperature\": 20.812, \"RPM\": 0.0}"
}
For clarity, I'll include the unescaped version of your payload:
{
"Time":"19/04/2021, 13:22:33",
"Critical vibration":"No",
"Temperature":20.812,
"RPM":0.0
}