Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

Configuration Schema Syntax Description

mookiedogmookiedog Washington, USA

I have read the page on configuration, which describes the creation and usage of config schema items, but I can't find any detailed description on the configuration syntax. As shown on the configuration page:

config_schema:
  - ["hello", "o", {"title": "Hello app settings"}]
  - ["hello.who", "s", "world", {"title": "Who to say hello to"}]

For example, what does the"o" mean? I have also seen reference to "s", "b", and "i" in other mos.yml files, and they seem to indicate a data type (string, bool, int respectively), but "o" is probably not "octal". Why would I include a "title", and under what circumstances does the "title" matter? I have also seen entries that indicate that you can "hide" entries, whatever that means. I have also seen mos.yml files that would appear to supply default values, or declare things to be read-only, but I'm still guessing about how it all works. Is there a detailed description of this syntax somewhere?

Comments

  • I guess no, nothing more detailed than the page you linked, unfortunately. Surely there is a room for improvement.

    o means "object": if one needs to have a configuration key foo.bar.baz, they'd need to declare an object foo first, and then another object foo.bar (unless they aren't already declared by some library, of course)

    The use case of title is to generate some html form to set configuration values (and of course it's also useful for readers of mos.yml)

  • This is a good question. It's not difficult to infer that o means object. However, I still think Mongoose should release a more detailed document about how the mos.yml file is compiled to .h and .c file,

  • I'm having trouble getting basic configuration working. I've tried the different combinations I can think of, but cannot get it working.

    As an example - In my mos.yml I already have a config_schema, and I've added the topmost setting here:

    config_schema:
      - ["hello.who", "s", "world", {"title": "Who to say hello to"}]
      - ["debug.level", 3]
      - ["i2c.enable", true]
      - ["i2c.debug", false]
      - ["i2c.sda_gpio", 33]
      - ["i2c.scl_gpio", 32]

    Are we supposed to combine our own definitions of config values into the same config_schema as the existing one?

    Or are we supposed to have multiple config_schema, like this?

    config_schema:
    - ["my_app.bool_value", "b", false, {title: "Some boolean value"}]
    - ["my_app.string_value", "s", "", {title: "Some string value"}]
    - ["my_app.int_value", "i", 123, {title: "Some integer value"}]

    config_schema:
    - ["debug.level", 3]
    - ["i2c.enable", true]
    - ["i2c.debug", false]
    - ["i2c.sda_gpio", 33]
    - ["i2c.scl_gpio", 32]

    Also, in the C/C++ quick start, the example uses get_cfg(), which I believe is no longer supposed to be used?

    And, in the configuration the example uses

    printf("My device ID is: %d\n", mgos_sys_config_get_device_id());

    but there is no corresponding config_schema setting in the example, which makes it somewhat confusing.

  • nliviunliviu Romania

    You must use only one config_schema: section.
    get_cfg() is not available anymore BREAKING: Sys config API change

    config_schema:
      - ["hello.who", "s", "world", {"title": "Who to say hello to"}]
    
    

    If you try to use const char* who = mgos_sys_config_get_hello_who();, you will get a compiler error

     error: 'mgos_sys_config_get_hello_who' was not declared in this scope
             const char* who = mgos_sys_config_get_hello_who();
    

    because you did not define the hello object:

    config_schema:
     - ["hello", "o", {"title": "Hello"}]
     - ["hello.who", "s", "world", {"title": "Who to say hello to"}]
    

    will compile without error.

Sign In or Register to comment.