Config

A lot of the Mongose OS functionality is driven by the device configuration.
For example, in order to make a device connected to the MQTT server,
there is no need to write a single line of code. It is enough to
modify mqtt.* configuration settings.

A configuration infrastructure is described in the user guide. Below is
the programmatic API for the device configuration.

save_cfg

bool save_cfg(const struct mgos_config *cfg, char **msg);

Save config. Performs diff against defaults and only saves diffs.
Reboot is required to reload the config.
If return value is false, a message may be provided in *msg.
If non-NULL, it must be free()d.
It is safe to pass a NULL msg

(*mgos_config_validator_fn)

Register a config validator.
Validators will be invoked before saving config and if any of them
returns false, config will not be saved.
An error message may be *msg may be set to error message.
Note: if non-NULL, *msg will be freed. Remember to use strdup and asprintf.

Cfg.set

Cfg.set(obj, opt_save)

Set the configuration. obj must be a subset of the whole configuation
tree. save is boolean flag that indicating whether the change should
be saved - it could be omitted, in which case it defaults to true.
Examples: