Skip to main content
Version: Next

sample - Python Preset example

This artical contains a preset python example for building and deploying a service on the AOS Edge platform. Follow this guide to create a service on AosCloud, share state between units, and sign and upload the service version. You can explore the example by checking out the source code.

Prerequisites

  • Target unit: a supported platform (VirtualBox or Raspberry Pi).
  • AosCloud account: an SP user account for AosCloud. See the AosEdge dictionary for user types and Get access page for login help.
  • Tools: AosCore SDK, Bash, Python and a virtual environment (venv) are installed.

Prepare service for upload

Before signing and uploading your service to AosCloud, prepare the service by organizing the compiled binary and updating the configuration with the service UUID obtained from the Create a Service on AosCloud step.

  1. Move script to service source folder.

    Copy or move the compiled preset.py script to the service source directory:

    mv preset.py ./src

    Ensure the script is in the ./src directory, as this is where the aos-signer tool expects it.

  2. Update service configuration.

    Open the service configuration file ./meta/config.yaml and update the service_id field with the UUID you copied from the Service Detail screen in AosCloud:

    nano ./meta/config.yaml

    Example config.yaml:

    service_id: '<YOUR_SERVICE_UUID>'
    configuration:
    state:
    filename: default_state.dat
    required: True

    Replace <YOUR_SERVICE_UUID> with the UUID saved earlier. Save and close the file.

  3. Create file default_state.dat in folder ./meta/.

    This file will be shared between unit instances and should contain any default state data required for service initialization.

    touch ./meta/default_state.dat

Sign and upload service version

Use the aos-signer go tool to sign and upload your service to AosCloud.

In the service directory, run:

~/.aos/venv/bin/python3 -m aos_signer go

Expected output:

Starting SERVICE SIGNING process...
Starting CONFIG VALIDATION process...
Validating config... VALID
Copying application... DONE
Copying configuration... DONE
Copying default state... SKIP
Creating archive... DONE
Sing package... DONE
Creating service package... DONE
*
Starting SERVICE UPLOAD process...
Starting CONFIG VALIDATION process...
Validating config... VALID
Uploading... DONE

On success, the output ends with an Uploaded message. Verify the service details on the Services section of AosCloud.

Once your service is created and uploaded to the cloud, the next essential step is to link it with your unit.
You can accomplish this by creating a subject, which acts as the bridge between your unit and the service.
For detailed instructions on how to set this up, please refer to the following guide.
Please see Creating subject, Access subject, Assign unit to subject,
Assign service to subject chapters.

Approve service

Before installing a service on a unit or updating an existing one, you must approve these changes. For detailed instructions on how to set this up, please refer to the following guide.
Please see Approve service сhapter.

Validate result of the service

For detailed instructions on working with logs, please refer to the Validate result of service chapter.

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

If message found the preset correct applyied on our unit Next step you should remove subject from current unit and set to other unit

Go to Units and choose you unit Check result 3

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

Next step set up this subject to other unit. Go to Units and choose you unit

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

Open logs and try find the message [AosEdge] Current preset in logs. You should be able to find message [AosEdge] Current preset but preset setting should be different.
The result should be:
Check result 4