Updating config.txt remotely

Configuration of the Raspberry Pi hardware is possible via a simple text file named config.txt- that can be found in the boot partition of the device. Here you can specify a slew of boot- audio and video card options [https://www.raspberrypi.org/documentation/configuration/config-txt.md]. In this post- we’ll discuss how you can edit and manage the hardware configuration of…

Configuration of the Raspberry Pi hardware is possible via a simple text file named config.txt, that can be found in the boot partition of the device. Here you can specify a slew of boot, audio and video card options. In this post, we’ll discuss how you can edit and manage the hardware configuration of your Raspberry Pi devices with resin.io, no matter how many they are or what their location is.

Introduction

Traditionally, editing config.txt has been a manual process. You mount the SD card and edit the file in a text editor, then slap the card back to the device. The process is simple, but can become tedious if you need to configure many or remote devices. With resin.io though, you can do better than that.

We recently enabled editing of config.txt via our Dashboard, Javascript and Python SDKs, and our newly-released CLI. And the best news is that it’s available immediately for almost every device, since our open-source device agent has had the ability to modify config.txt for quite some time.

How it works

The default behaviour of our device agent whenever you add or remove an application or device environment variable, is to simply expose it to your application container. But if the variable name starts with RESIN_HOST_CONFIG_, it will instead strip the prefix and save the resulting name and value to the device’s config.txt file. After the file is modified and safely written to disk, our agent reboots the device in order for the hardware to pick up the new configuration.

Our agent is smart enough to not overwrite previous entries set perhaps manually. If there’s already a config.txt file, it will load and parse it, merge the changed values and apply the new ones, before saving it back.

By building the feature on the existing functionality of environment variables, you automatically gain the ability to centrally specify a complete hardware configuration at the application level. These configuration variables apply to all devices belonging to the application and, similarly to plain environment variables, you may redefine them for each device individually if needed.

An example

Let’s see a simple example to make things clearer. We’ll configure the HDMI output format for all devices belonging to our imaginary application, conveniently named MyApp.

The config.txt name for this option is hdmi_mode. For our agent to pick it up as a configuration variable, we’ll need to prefix it with RESIN_HOST_CONFIG_, so it becomes RESIN_HOST_CONFIG_hdmi_mode.

The option’s value can be any integer from 1 to 59, each one specifying a different combination of resolution and frequency for the HDMI output of our Raspberry Pi devices. So, to set the output format to 1080p we would specify the value 16.

To set the new configuration variable via the Dashboard, navigate to the Fleet Configuration page of your application and create a new entry in the Application Config Variables section.

Screen Shot 2016-02-26 at 15.36.21.png

This is equally easy to accomplish via our CLI:

$ resin env add RESIN_HOST_CONFIG_hdmi_mode 16 --application=MyApp

Or, via our Javascript SDK:

resin.models.environmentVariables.create('MyApp', 'RESIN_HOST_CONFIG_hdmi_mode', 16);

Conclusion

config.txt is a powerful way to configure your Raspberry Pi, and we hope that with this feature we make it more accessible to you. As a next step, you may want to read our documentation on the feature, or check out the various config.txt options that are available to you.

We’d love to hear from you. Tell us about the things you build at our gitter channel!

Happy hacking!


Posted

in

Tags: