Azure IoT Edge Debug

Iain White 146 Reputation points
2021-02-26T16:16:53.997+00:00

I've inherited an IoT Edge solution. I want to debug using VS Code and I've followed the docs here that tell me how to use a simulator to locally debug. That is working, and I can trigger a breakpoint by POSTing to the API, but only if it's an input message that's defined like:

await ioTHubModuleClient.SetInputMessageHandlerAsync("inputcommand", HandleMessage, ioTHubModuleClient);.   

What I can't figure out is how to trigger and therefore debug Direct Methods that are defined like:

await ioTHubModuleClient.SetMethodHandlerAsync("readcommand", HandleReadCommand, ioTHubModuleClient);  

How do I trigger these when running on the simulator? Am I missing something or are the docs lacking coverage of this? Any help would be gratefully appreciated.

Azure IoT Edge
Azure IoT Edge
An Azure service that is used to deploy cloud workloads to run on internet of things (IoT) edge devices via standard containers.
567 questions
0 comments No comments
{count} vote

Accepted answer
  1. Matthijs van der Veer 4,376 Reputation points MVP
    2021-02-26T16:38:05.143+00:00

    Hi again! To use Direct Methods, the approach is a bit different. When you set up the simulator, you get to select a device from your IoT Hub. (In VS Code, the command is "IoT Edge: Setup IoT Edge Simulator")

    After that, when you then run your module, a module is added to your device in IoT hub. The module is called target and you can run your direct methods on it. So you can either go to the portal, browse to your device, click on the module and send it a direct method. Or you can use az cli to do the same.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Vanhee, Frederik 6 Reputation points
    2021-07-23T13:20:27.97+00:00

    Hi Matthijs,
    Had the same question.
    I my case I also needed to restart a module. This is done by calling direct method RestartModule on the edgeAgent, but doesn't seem to work with a simulator. Just performing a docker restart <modulename> also did the trick.

    regards,
    Frederik

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.