how can I send data from a smart door lock to Azure IoT Hub?

@Middleware & OS Hey guys, how can I send data from a smart door lock device(lock status, access attempts, etc)running on a Raspberry Pi Zero W with Raspbian OS to Microsoft Azure IoT Hub?
Solution:
Firstly you need to create an account on there official site install necessary libraries then your good to go, your code should look like 👇 ```python import time from azure.iot.device import IoTHubDeviceClient...
Jump to solution
1 Reply
Solution
Enthernet Code
Enthernet Code•3w ago
Firstly you need to create an account on there official site install necessary libraries then your good to go, your code should look like 👇
import time
from azure.iot.device import IoTHubDeviceClient

CONNECTION_STRING = "<your device connection string>"
MSG_TXT = '{{"lockStatus": {0}, "accessAttempts": {1}}}'

def send_message(lock_status, access_attempts):
try:
client = IoTHubDeviceClient.create_from_connection_string(CONNECTION_STRING)
print("Sending data to Azure IoT Hub:")
while True:
message = MSG_TXT.format(lock_status, access_attempts)
client.send_message(message)
print("Message sent: ", message)
time.sleep(5) # Delay between sending messages

except KeyboardInterrupt:
print("IoT Hub data transmission stopped.")

if __name__ == '__main__':
lock_status = True # Example lock status
access_attempts = 10 # Example access attempts
send_message(lock_status, access_attempts)
import time
from azure.iot.device import IoTHubDeviceClient

CONNECTION_STRING = "<your device connection string>"
MSG_TXT = '{{"lockStatus": {0}, "accessAttempts": {1}}}'

def send_message(lock_status, access_attempts):
try:
client = IoTHubDeviceClient.create_from_connection_string(CONNECTION_STRING)
print("Sending data to Azure IoT Hub:")
while True:
message = MSG_TXT.format(lock_status, access_attempts)
client.send_message(message)
print("Message sent: ", message)
time.sleep(5) # Delay between sending messages

except KeyboardInterrupt:
print("IoT Hub data transmission stopped.")

if __name__ == '__main__':
lock_status = True # Example lock status
access_attempts = 10 # Example access attempts
send_message(lock_status, access_attempts)
@Boss lady