Meta Config

The APP supports the meta.json configuration file, which can be used as needed.

If the APP.tar.gz package contains custom configuration files, the gateway Web UI renders the interface based on the fields defined in the meta.json file within the package.

Users can modify and save configurations through the gateway Web Console, and the code within the app retrieves the configuration content via API functions.

Note

  • Configuration change notifications are not currently supported. Scripts need to periodically read and compare configurations to detect changes.

Prepare Code

Write a file named hello.py with the following content:

import cassiasys


def main():
    print("hello")

    try:
        # read user config ok: {"config1":"value1","config2":"value2"}
        config = cassiasys.read_user_config()
        print(f"read user config ok: {config}")
    except Exception as e:
        print(f"read user config failed: {e}")


main()

meta.json

Write a file named meta.json with the following content:

{
    "name": "hello",
    "version": "1.0.0",
    "config_items": [
        {
            "name": "config1",
            "type": "text"
        },
        {
            "name": "config2",
            "type": "text"
        }
    ]
}

Package APP

The code files need to be packaged into a Cassia APP package before they can be uploaded and run. A sample packaging script is as follows:

After successful execution, you will see hello.1.0.tar.gz in the build directory.

#!/bin/bash

#!/bin/bash

NAME_VER=hello.1.0
TAR_GZ=${NAME_VER}.tar.gz

rm -rf build/"$NAME_VER"
rm -rf "$TAR_GZ"

mkdir -p build/"$NAME_VER"
cp hello.py build/"$NAME_VER"
cp meta.json build/"$NAME_VER"

cd build || exit
gtar -zcvf "$TAR_GZ" "$NAME_VER" || tar -zcvf "$TAR_GZ" "$NAME_VER"

ls -lh "$NAME_VER".*

cd - || exit

Upload APP

  1. First, navigate to the Other page and scroll to the Micro APP section.

  2. Click the Select file button and choose the hello.1.0.tar.gz file.

  3. Click the Upload button to upload the APP file.

  4. Please wait for the Upload Successful prompt to appear.

../_images/image.png

Modify configuration

  1. Modify the configuration of config1 to value1.

  2. Modify the configuration of config2 to value2.

  3. Click the Apply button.

../_images/image-4.png

Run APP

  1. Click the Start button to run the app.

../_images/image-2.png

View Results

  1. Click View Log to see the normal output of the running results as follows:

hello
read user config ok: {"config1":"value1","config2":"value2"}