I’m working with a Balena device and I’m trying to find a way to modify a device variable from a shell script running inside a Docker container. Specifically, I want to change the value of a device variable in a way that it gets synchronized with the Balena Cloud.
So far, I haven’t been able to find a solution that works with the balena-engine CLI, and I’m unsure if there is another approach or tool that could help achieve this.
Has anyone encountered this situation before or know of a way to interact with device variables from within a container and ensure the changes are synced with the Balena Cloud?
@philh, From your shell script you could call the balenaCloud API [1] (directly or via an SDK) to update the device var. That change will then be sent from the cloud to the device.
@rosswesleyporter, thank you very much for your quick reply, that is a nice solution. I just want to avoid that each of my Balena devices gets a sessiontoken or api key, which also gives it access to the configuration of other devices too.
I thought there is a way that a registered Balena device can set device variables for itself without additional authentication credentials that I have to pass. So that the device variables are automatically synchronized with the cloud.
What you could do is to implement a custom API endpoint in your server backend to call from the device. This dedicated endpoint should be used for only one purpose (change certain variable) without granting access to the entire device configuration.
Serverside you could then easily use Belena API directly or via the SDK as mentioned above. The advantage would be that you could manage access to the Belena API central rather than distributed over your devices. However you’d then have to add some kind of auth mechanism to secure your custom endpoint. If that’s something you have set up already, it wouldn’t be a big deal, else it’s a trade-off.