Meadow App Settings

It’s pretty common for an IoT application to need to read persistent but changeable settings at startup. Meadow applications have long supported the app.config.yaml file for settings to control behavior of the Resolver.Log, the device’s lifecycle behavior (e.g. restarting on an uncaught exception) or Meadow.Cloud settings, but how can you leverage that capability for your own application settings

Starting in Meadow.Core version 1.1.1, the IApp interface now has a Settings property.

public Dictionary<string, string> Settings { get; }

This property gets populated by any settings found in app.config.yaml that are not used by Meadow.Core. You’ll notice that the property is a Dictionary<string, string>. How does that translate from your custom settings? The key is a dot-notated “path” to the property name, and the value is always the string representation directly from the settings file.
So if you add the following section to your app.config.yaml file:

MyApp:
  PollInterval: 5
  Network:
    Name: MyDevice

You would end up with 2 items in the Settings property at run time:

"MyApp.PollInterval", "5"
"MyApp.Network.Name", "MyDevice"

Meadow is already parsing app.config.yaml for its own settings, so retrieving these values in this format is effectively free. Meadow, however, does not attempt to parse the values to any underlying type (like int, etc), nor does it support converting the values to a type-safe object because reflection on the F7 microcontroller can be a costly operation and we’d rather leave the decision to use it up to the user.

If you have questions about using Meadow configuration files in your application, join us on Slack.