sample - Python video device
This repository contains a python video device example for building and deploying the service on the AosEdge platform.
Follow this guide set up your environment, compile the service, pass video device from board to service, create the service on AosCloud, and sign and upload service.
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 the Get access page for login help.
- Tools: AosCore SDK, SQLLite, CMake, Bash, Wget, 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 service on AosCloud step.
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>'
Replace <YOUR_SERVICE_UUID> with the UUID saved earlier. Save and close the file.
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.
Link unit and service together
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.
Adding video device to service
To use a video device (such as a USB webcam) in the AOS system, follow these steps:
Connecting and detecting video device
-
Connect your video device to the Raspberry Pi board.
-
Start the device and connect to it via terminal.
-
Switch to the DomD partition.
-
Run the following command to list available video devices:
v4l2-ctl --list-devices
(XEN) root@main:~# v4l2-ctl --list-devices
(XEN) GENERAL WEBCAM: GENERAL WEBCAM (usb-xhci-hcd.1.auto-1):
(XEN) /dev/video0
(XEN) /dev/video1
(XEN) /dev/media0 -
Copy the device paths — you will need them in the next steps.
Preparing unitconfig.json
- Go to the appropriate Releases page:
- For Raspberry Pi: meta-aos-rpi releases
- For VirtualBox: meta-aos-vm releases
-
Download the
unitconfig.json. -
Open the file in any text editor.
-
Add a new devices section on the same level as labels and resources.
"devices": [
{
"name": "camera0",
"groups": ["video"],
"hostDevices": [
"/dev/video0",
"/dev/video1",
"/dev/media0"
],
"sharedCount": 1
}
]
Full example userconfig.json
{
"nodes": [
{
"labels": [
"main"
],
"devices": [
{
"name": "camera0",
"groups": [
"video"
],
"hostDevices": [
"/dev/video0",
"/dev/video1",
"/dev/media0"
],
"sharedCount": 1
}
],
"nodeType": "aos-rpi-1.0-single-domd",
"priority": 100,
"resources": [
{
"name": "kuksa",
"hosts": [
{
"ip": "10.0.0.100",
"hostname": "Server"
}
]
}
]
}
],
"components": [
{
"id": "aos-rpi-1.0-single-domd"
}
]
}
- Save updated file.
Update target system
- Visit the Target systems page.
- Select the appropriate target system:
aos-rpifor Raspberry Piaos-vmfor VirtualBox
- Click the Edit button.
- Paste the contents of your updated
unitconfig.jsonfile into the configuration editor.
Done! Your video device is now part of the AOS service configuration.
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 service
-
For detailed instructions on working with logs, please refer to the Validate result of service chapter.
-
Download the log file from your device and find the
Running: v4l2-ctl --list-devices. This means the command v4l2-ctl was run to print the list of devices available on your unit.