Reputation: 13
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.
Upvotes: 1
Views: 2008