Bharath G Kumar
Bharath G Kumar

Reputation: 83

Unable to 'Build and Run IoT Edge Simulator' in Visual Studio Code on macOS

Have been trying to build and run a custom Azure IoT Edge Module, in VS Code, on macOS. When I try to Build and Run IoT Edge Solution in Simulator, the

Please setup iotedgehubdev first before starting simulator

alert pops up. Completed the setup successfully and yet, every time this very warning pops up and am unable to perform the 'build and run' process.

Upvotes: 2

Views: 1086

Answers (2)

Syl van R
Syl van R

Reputation: 11

I had the same issue today working on a fresh linux install on my laptop. I figured that the simulator needs 3 steps:

  • setup (using a real device connection string)
  • start (actually runs docker-compose, and if use -v, will show docker logs)
  • stop

I setup vscode and going through the example at https://learn.microsoft.com/en-us/azure/iot-edge/how-to-vs-code-develop-module?view=iotedge-2020-11 then find out several things:

  • first vscode detects that there is a DevContainer definition, and offers to open in DevContainer - which I did but is unexpected
    • that means that setup for azureiothubdev on the host linux is unnecessary
    • and that had issues with versions of pyyaml , had to downgrade to 5.4.1
    • will now uninstall this
  • second, when I try to right click (contextual menu in Azure Iot Hub extension) on the device I choose to run the simulator as, it does 'setup IoT Edge Simulator' correctly.
  • third, when trying the command palette approach to 'Run IoT Edge Solution in the simulator', it does what the OP describes, with a popup at the bottom asking to choose the device, and when done with setup, just stops there.

In the end, I read the instructions related to the Azure Iot EdgeHub dev tool https://github.com/Azure/iotedgehubdev. Here is how I got it to work:

  • ran 2 actions in contextual menu for deployment.debug.template.json,
    • Generate IoT Edge Deployment Manifest
    • Build and Push IoT Edge Solution
  • ran 1 action in the context menu for my device in AZURE IOT HUB extension
    • Setup IoT Edge Simulator, which runs commands in the terminal
  • ran one command manually in the terminal to fill the gap
sudo "iotedgehubdev" start -d ./config/<your debug deployment file> -v
  • stopped on a breakpoint in the sample module (the whole point of the endeavor)
    • in your module, set a breakpoint, in a message handler perhaps
    • enter debug menu (CTRL+SHIFT+D)
    • select the config for your (C#) module with 'Remote Debug'
    • click Start Debugging (empty green triangle) or press F5
    • select the process matching your entrypoint in the dockerfile (mine was 'dotnet SampleModule.dll')

At this point you are attached to the program running in a container, and the breakpoint should get hit as expected.

you can't use the command palette to stop the simulator, if you have the -v option where docker-compose gives you logs. the command gets written to the terminal and does nothing in the middle of the logs. you just have to Ctrl+C in the terminal to end the simulation, though edgehub keeps running. You stop it with

sudo "iotedgehubdev" stop

Upvotes: 1

user18910291
user18910291

Reputation: 1

I am assuming you have Azure IoT Hub tool extension for VSCode installed. In the explorer menu pane (on left), navigate to 'Azure IoT Hub' -> Pick your Edge device and right click. You will see option 'Setup IoT Simulator' and click.

It will automatically fetch the device connection string for the device. Then you should be able to build it.

Upvotes: 0

Related Questions