The steps for this recipe are as follows:
- Import the libraries:
#device.py
import time
from azure.iot.device import IoTHubDeviceClient, Message
from sense_hat import SenseHat
import json
- Declare the variables:
client = IoTHubDeviceClient.create_from_connection_string("your device key here")
sense = SenseHat()
sense.set_imu_config(True, True, True)
- Get a joined device value:
def combined_value(data):
return float(data['x'])+float(data['y'])+float(data['z'])
- Get and send the data:
while True:
gyro = combined_value(sense.gyro_raw)
accel = combined_value(sense.accel_raw)
msg_txt_formatted = msg.format(gyro=gyro, accel=accel)
message = Message(msg_txt_formatted)
client.send_message(message)
time.sleep(1)
- Create a SQL query that uses the AnomalyDetection_SpikeAndDip algorithm to detect anomalies:
SELECT
EVENTENQUEUEDUTCTIME AS time,
CAST(gyro AS float) AS gyro,
AnomalyDetection_SpikeAndDip...