The steps for this recipe are as follows:
- In the main.py file, import the necessary libraries:
import time
import os
import sys
import asyncio
from six.moves import input
import threading
from azure.iot.device.aio import IoTHubModuleClient
from azure.iot.device import Message
import uuid
- Create a stub for your ML code:
def MLCode():
# You bispoke ML code here
return True
- Create a message-sending function:
async def send_d2c_message(module_client):
while True:
msg = Message("test machine learning ")
msg.message_id = uuid.uuid4()
msg.custom_properties["MachineLearningBasedAlert"]=\
MLCode()
await module_client.send_message_to_output(msg,
"output1")
- Create a message-receiving function:
def stdin_listener():
while True:
try:
selection = input("Press Q to quit\n")
if selection...