Reading device variable from python container

Hi,

I have a service called “con” in witch I’m running my python code.
How can I access my device variable called “DEVICE_NAME”?

Hello @Jesper

Did you try to get the information from the balenaCloud API? Resources - Balena Documentation

?

@mpous
I have looked at it, but then I would have to modify my code for each device, so that it would include the Device ID and auth token for use in the http call?

That seems a bit od.

@Jesper did you try to get the device UUID using these variables?

you might use os.environ['BALENA_DEVICE_UUID'] and then you might get the name. Here you have an example from a bash script and not to get the name but similar:

Let us know if this works!

If you can run printenv in the container you see what env vars are available.
I found BALENA_DEVICE_NAME_AT_INIT closest to Device name, i hope that suffices your needs.

It does!!
In the forum post I found they did not mention this:

environment:
      - 'DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket'

So now I can get the info using eg. os.environ[‘BALENA_DEVICE_UUID’]