Code: Select all
import time
import qrcode
import cups
from azure.iot.device import IoTHubDeviceClient
CONNECTION_STRING = (Not Showing This)
device_client = IoTHubDeviceClient.create_from_connection_string(CONNECTION_STRING)
device_client.connect()
def message_handler(message):
try:
print("Message received:")
messageDataString = message.data.decode("utf-8")
print(messageDataString)
img = qrcode.make(messageDataString)
img.save(str(messageDataString) + ".png")
conn = cups.Connection()
printers = conn.getPrinters()
printerName = list(printers.keys())[0]
conn.printFile(printerName, "/home/ahelm/printApi/" + str(messageDataString) + ".png", "", {})
print(printerName)
except Exception as e:
print(e)
try:
device_client.on_message_received = message_handler
while True:
time.sleep(300)
except KeyboardInterrupt:
print("IoT Hub Cloud to Device Messaging Device Sample Stopped")
finally:
print("Shutting Down")
device_client.shutdown()
Code: Select all
Message received:
test5
Brother_QL-800
Mobile version