adafruit / Adafruit_CircuitPython_AzureIoT

Access to Microsoft Azure IoT device, messaging, and job services from CircuitPython!
MIT License
20 stars 15 forks source link

device.on_command_executed is never called, IoT Central methods can't be used #58

Open Grudon opened 1 year ago

Grudon commented 1 year ago

It seems like device.on_command_executed is never called, even though my device is clearly receiving the method from IoT Central when looking at the log:

1861.44: INFO - C2D: => $iothub/methods/res/200/?$rid=1 with data {"Value": ""} and name => speaker

The code, taken from the docs (https://docs.circuitpython.org/projects/azureiot/en/latest/index.html#azure-iot-central):

def command_executed(command_name: str, payload) -> IoTResponse:
    print("Payload:", payload)
    if command_name == "speaker":
        commandPlaySpeaker(payload)
    print("Command", command_name, "executed with payload", str(payload))
    # return a status code and message to indicate if the command was handled correctly
    return IoTResponse(200, "OK")

device.on_command_executed = command_executed

A similiar problem seems to have been reported on Stackoverflow: https://stackoverflow.com/questions/71110928/unable-to-send-command-from-iot-central-to-pyportal

Using CircuitPython 6.3.0 with Library Bundle 6.x on a Adafruit PyPortal.