Connection Example
This example demonstrates how to establish a connection to your Aria Gen2 device using the Python SDK. Once authenticated, you can connect to devices by their serial number or IP address.
Quick Start
Run the connection example script:
python ~/Downloads/projectaria_client_sdk_samples_gen2/device_connect.py
The script connects to the first available device and displays its information.
What This Example Does
The script performs the following steps:
- Creates a device client
- Configures the client to connect to a specific device (or first available)
- Establishes a connection
- Displays device information
Code Walkthrough
Step 1: Import Required Modules
import argparse
import aria.sdk_gen2 as sdk_gen2
Step 2: Parse Command-Line Arguments
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument(
"--serial",
dest="serial",
type=str,
default="",
required=False,
help="Serial number of the device which will be connected. (e.g. 1M0YDB5H7B0020)",
)
return parser.parse_args()
Available Options:
--serial
: Specify a device by its serial number (e.g.,1M0YDB5H7B0020
)- If nothing is specified, connects to the first available device
Step 3: Create and Configure Device Client
device_client = sdk_gen2.DeviceClient()
config = sdk_gen2.DeviceClientConfig()
config.device_serial = serial
device_client.set_client_config(config)
How Configuration Works:
- Default (no arguments): Connects to the first available device
- By Serial: Targets a specific device by its unique serial number
Step 4: Establish Connection
try:
device = device_client.connect()
print(f"Successfully connected to device {device.connection_id()}")
except Exception as e:
print(f"Failed to connect to device: {e}")
return
What Happens:
- The
connect()
method establishes a session with the device - Returns a
Device
object that provides access to all device features - Throws an exception if connection fails
Complete Example Code
Here's the full connection script:
import argparse
import aria.sdk_gen2 as sdk_gen2
def device_connect(serial):
# Set up the device client to initiate connection to the device
device_client = sdk_gen2.DeviceClient()
# Set up the device client config to specify the device to be connected to e.g. device serial number.
# If nothing is specified, the first device in the list of connected devices will be connected to
config = sdk_gen2.DeviceClientConfig()
config.device_serial = serial
device_client.set_client_config(config)
# try to connect to the device
try:
device = device_client.connect()
print(f"Successfully connected to device {device.connection_id()}")
except Exception:
print("Failed to connect to device.")
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument(
"--serial",
dest="serial",
type=str,
default="",
required=False,
help="Serial number of the device which will be connected. (e.g. 1M0YDB5H7B0020)",
)
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
device_connect(args.serial)
Usage Examples
Connect to First Available Device
python ~/Downloads/projectaria_client_sdk_samples_gen2/device_connect.py
Output:
Successfully connected to device 1M0YDB5H7B0020
Connect by Serial Number
python ~/Downloads/projectaria_client_sdk_samples_gen2/device_connect.py --serial 1M0YDB5H7B0020
When to Use:
- Multiple devices are connected
- You need to ensure you're using a specific device
- Scripts that require consistent device selection
Finding Device Information
Get Device Serial Number
Use the CLI to list all available devices:
aria-gen2 device list
# Output example:
# [AriaGen2Cli:App][INFO]: 1M0YDB5H7B0020
Troubleshooting
Connection Failed: Device Not Found
Problem: Script cannot find or connect to the device.
Solutions:
-
Check device is connected:
aria-gen2 device list
-
Verify authentication:
aria-gen2 auth check
-
Run aria-doctor:
aria-doctor
-
Check USB connection:
- Try a different USB port
- Use a high-quality USB cable
- Ensure device is powered on
Connection Failed: Wrong Serial Number
Problem: Specified serial number doesn't match any device.
Solutions:
- List available devices:
aria-gen2 device list
- Use the correct serial number from the output
- Serial numbers are case-sensitive
Connection Modes
USB Connection (Default)
How it works:
- Device connected via USB cable
- Most reliable connection method
Usage:
# Connects via USB to first available device
config = sdk_gen2.DeviceClientConfig()
Key Concepts
DeviceClientConfig
The configuration object controls how the client connects to devices:
config = sdk_gen2.DeviceClientConfig()
# Option 1: Connect to first available device (default)
# Leave config empty
# Option 2: Connect by serial number
config.device_serial = "1M0YDB5H7B0020"
# Apply configuration
device_client.set_client_config(config)
Device Object
Once connected, the Device
object provides:
device = device_client.connect()
# Device information
device.connection_id() # Get connection identifier
# Device operations (covered in other examples)
device.start_recording() # Start recording
device.start_streaming() # Start streaming
device.render_tts(text) # Text-to-speech
Next Steps
- Learn how to control recording with your connected device
- Explore real-time streaming
- Send text-to-speech commands
- Review all Python SDK examples