Skip to main content
Version: v1.1

Sample - Python Preset Example

This example shows how to use shared state on a unit.

Prerequisites

  • Tools: AosCore SDK, Bash, Python and a virtual environment (venv) are installed.

Source Code

You can explore the example by checking out the source code.

Prepare Service for Upload

Before signing and uploading your service to AosCloud, verify that your source files are packaged in service1/x86 and review the root config.yaml file.

  1. Check service payload files.

    Ensure the following files exist:

    • service1/x86/preset.py
    • service1/x86/default_state.dat
  2. Update service configuration.

    Open the root service configuration file:

    nano ./config.yaml

    Example config.yaml structure:

    schemaVersion: 2
    items:
    - identity:
    codename: "preset-service"
    configuration:
    cmd: /usr/bin/python3 -u preset.py
    state:
    filename: default_state.dat
    required: true
    images:
    - archInfo:
    architecture: amd64
    cmd: /usr/bin/python3 -u preset.py
    sourceFolder: x86
    sourceFolder: service1
    publish:
    tlsKey: aos-user-sp.p12

    Update fields such as service identity, version, and signing key as needed for your environment.

Upload service to AosCloud

From the preset directory, run:

<host>:~/demo-services/preset$ aos-signer go
Starting DEPLOYMENT BUNDLE SIGNING process...
Starting CONFIG VALIDATION process...
Validating config... VALID
Validating image paths... VALID
Starting BUNDLE BUILDING process...
....
Uploading... DONE
Deployment bundle successfully uploaded!

Confirm

For detailed instructions on working with logs, see Get service logs.

Open logs and find the message [AosEdge] Current preset. Check result 2

If the message is found, the preset is correctly applied on the current unit. Next, remove the subject from the current unit and assign it to another unit.

Go to Units and choose your unit. Check result 3

Switch to Subjects & Services and remove the subject from the current unit. Check result 4

Next, assign this subject to another unit. Go to Units and choose your unit.

  1. Assign as described in Assign a unit to subject.
  2. Approve as described in Approve service.
  3. Download logs for current unit

Open logs and find the message [AosEdge] Current preset. You should see the same message, but the preset value should be different. Expected result: Check result 4