I have questions about the meaning of “o” or “b” and sometime “i” on the above code, usually they are written in the mos.yml file.
what are they? and how many letter are they? how & when to use them?
- ["app.pin", "i", 5, {title: "GPIO pin a sensor is attached to"}]
i’m assuming " i " mean intger, what does 5 mean ?
The config_schema section of the mos.yml provides a way to define configuration options for the device and override options defined elsewehre (e.g. in alibrary).
Example:
During the build process, each object defined in the config_schema will be compiled in a C structure (the boolean type is translated to int with values 0 for false and 1 for true):
struct mgos_config_app {
const char * name;
int led_pin;
int led_enable;
double interval;
unsigned int uint_val;
};
The default values can be changed at runtime running, e.g
mos config-set app.led_enable=false
mos config-set app.name="New app"
These settings can be used in your code to do an action according to their values:
if((mgos_sys_config_get_app_led_pin() > 0) && mgos_sys_config_get_app_led_enable()){
// toggle the led
mgos_gpio_toggle(mgos_sys_config_get_app_led_pin());
}
how can we do like this but not get override by mos.yml
In runtime user may change the config then we want to keep user change in flash memory.
I will put some method for initial that config in production. like…
void initSystemConfig () { // This is factory default setup function will get call by developer only!!!
if(mgos_config_app.version!=1) {
mgos_config_app.version = 1; // 1 mean already initial or restore to factory setting
mgos_config_app.interval = 2; // default factory setting
then save mgos_config_app where ?? how ??
}
}
So after mgos_config_app has been initial it will get last save from user only to used during runtime.
How can I do it?
mgos_sys_config_save saves the settings in conf9.json.
The conf0.json is not used anymore to store the defaults. They are harcoded in build/gen/mgos_config.c during the build process.
After OTA update confX.json are copied over in the new fs partion from the old one.