Can I start a module on IoT Edge using the Python IoT SDK

Giri Gopalan 41 Reputation points
2020-07-02T01:58:16.367+00:00

Hi, I have developed a simple module and registered it with ACR. I have been able to deploy this module successfully onto an IoT Edge using the Azue CLI and the Azure portal.

Now I would like to do it programatically. So wanted to see if a module can be instantiated on IoT Edge using the Python IoT SDK.

Thanks,

Giri

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.
576 questions
{count} votes

Accepted answer
  1. Sander van de Velde | MVP 33,046 Reputation points MVP
    2020-07-06T22:50:00.337+00:00

    I checked out a few samples provided for the IoT Hub and the related RegistryManager.

    There seems to be no SDK available for this job.

    One other option could be the IoT Hub Rest API.

    In https://learn.microsoft.com/en-gb/rest/api/iothub/service/configuration/applyonedgedevice it says "Applies the provided configuration content to the specified edge device". This seems to be able to post a deployment manifest.

    It looks like you have to work with the "modulesContent" but there is no description of the actual object in the documentation.

    But, you can check out this https://www.danielemaggio.eu/iot/iot-edge-rest-api/

    Here, an example is shown in C#. This could be rewritten into Python or any other language is capable of making a Rest call.

    Please mark an answer as "accepted answer" if it provides the answer to your question.

    3 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Giri Gopalan 41 Reputation points
    2020-07-13T05:36:30.703+00:00

    Hi,

    Thanks for the pointers, I used them to successfully add modules using REST calls. Here are more details that may help others:

    1. I used some python code from this repo: https://github.com/Azure-Samples/iot-hub-python-get-started. Specifically modified the deviceManager.py to add a deploy_modules method and to reuse the SAS token code
    2. The suggestion from this link: https://www.danielemaggio.eu/iot/iot-edge-rest-api/ to use the POST was spot on. A word of caution is to use the correct api-version. The latest version for the applyConfigurationContent REST call is: api-version=2019-07-01-preview. I point this out since other REST calls used a later version (2020-something) that will not work for applyConfigurationContent
    3. Finally, for the "Request Body" part, that data has to be sent as it is shown in that link, that is with the newlines and all. I was reading it in as a JSON and sending it and was getting some weird errors that too a while to figure out. Simply read that file in as is and sent it as the body.

    So thanks again for the pointers. It was very useful.

    This thread can be closed.

    Giri

    2 people found this answer helpful.

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.