1

SUMMARY

I don't get the expected hostname from the device when requesting it via python code; I get some container ID

BACKGROUND

When running the following code on Raspbian in python 3:

import socket
print(socket.gethostname())

or:

import platform
platform.node()

...you get the hostname of the machine you're running the code on. (That's what I expect)

When doing the same from a Custom IoT Edge module you get some kind of identifier for I think the container?

How can you get the hostname of the system the container is running on within the container module itself?

SOLUTION

As suggested the Device ID and Module ID are exposed as environment variables: IOTEDGE_DEVICEID and IOTEDGE_MODULEID.

So now in python you can do the following:

DEVICEID = os.environ["IOTEDGE_DEVICEID"]
MODULEID = os.environ["IOTEDGE_MODULEID"]

And then use the variables like that in your (python) code down the line.

capacious
  • 13
  • 4

1 Answers1

1

See here for a similar question. Short answer: do a docker inspect on your custom module container and see the different environment variables that are available. One of them is the hostname of your Edge device.

silent
  • 14,494
  • 4
  • 46
  • 86
  • This was exacty what I was looking for! I didn't find the Github page before. I now do the following in python in the code for my custom module: `DEVICEID = os.environ["IOTEDGE_DEVICEID"]` `MODULEID = os.environ["IOTEDGE_MODULEID"]` and then I can perfectly use them further down the line. :-) – capacious Mar 29 '19 at 13:15