Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# Azure IoT imports
from azure.iot.device.aio import IoTHubModuleClient
from azure.iot.device import Message
async def send_iot_message_doorState(action, doorState, doorStateDesc):
# send iot messages
# send message reference
global module_client
MSG_TXT = '{{"action": "{action}","doorState": "{doorState}","doorStateDesc": "{doorStateDesc}"}}'
msg_txt_json_formatted = MSG_TXT.format(action=action, doorState=doorState, doorStateDesc=doorStateDesc)
message = Message(msg_txt_json_formatted)
message.custom_properties['action'] = action
message.custom_properties['doorState'] = doorState
message.custom_properties['doorStateDesc'] = doorStateDesc
await module_client.send_message(message)
except Exception as e:
return 'Error sending IoT message', 500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment