MentraOS ASG Client Development Guidelines
This guide provides an overview and development guidelines for the MentraOS ASG (Android Smart Glasses) Client, which runs on Android-based smart glasses like Mentra Live.Overview
The MentraOS ASG Client is an Android application that runs directly on Android-based smart glasses hardware. It serves as the bridge between the glasses’ hardware capabilities and the MentraOS ecosystem, enabling features like camera capture, display rendering, Bluetooth communication, and network management.Architecture
Core Components
-
AsgClientService - The main service that coordinates all functionality:
- Parses Bluetooth messages from the MentraOS mobile app
- Handles command processing from those messages
- Parses messages from Mentra Live’s microcontroller (button presses, swipes)
- Triggers actions like taking pictures, videos, and starting RTMP streams
- Manages network state and battery status reporting
-
Manager Systems - Interface-based factory pattern for device abstraction:
- NetworkManager - WiFi and hotspot control
- BluetoothManager - BLE communication with phone app
- MediaCaptureService - Photo/video capture and upload
- RtmpStreamingService - Live video streaming
Network Manager System
The NetworkManager uses a factory pattern to support different device types:- K900NetworkManager - For Mentra Live (K900) devices using proprietary broadcasts
- SystemNetworkManager - For devices with system permissions using reflection
- FallbackNetworkManager - For regular devices, prompts user for manual configuration
Bluetooth Manager System
Similarly structured for Bluetooth/BLE operations:- K900BluetoothManager - Uses serial port communication with BES2700 chip
- StandardBluetoothManager - Full BLE GATT server implementation for standard Android devices
Media System
The media system handles camera button presses and media capture: Button Press Flow:- Physical button press detected by microcontroller
- MCU sends command to ASG Client (
cs_pho
for short press,cs_vdo
for long press) - ASG Client checks button press mode configuration:
- PHOTO mode: Takes photo/video locally
- APPS mode: Sends button event to phone/apps
- BOTH mode: Does both actions
- Photos are captured and queued for upload when connected
RTMP Streaming
Supports live video streaming with four main commands:- start_rtmp_stream - Initiates streaming to specified RTMP URL
- stop_rtmp_stream - Terminates active stream
- keep_rtmp_stream_alive - Must be sent every 15 seconds to prevent 60-second timeout
- get_rtmp_status - Queries current streaming status
Development Guidelines
Code Style
- Java:
- Use Java SDK 17
- Classes: PascalCase
- Methods: camelCase
- Constants: UPPER_SNAKE_CASE
- Member variables: mCamelCase (with m prefix)
- 2-space indentation
- EventBus for component communication
Adding Support for New Glasses
To add support for new Android-based smart glasses:-
Fix Device Detection (REQUIRED):
-
Create a SmartGlassesCommunicator in augmentos_core:
- Extend
SmartGlassesCommunicator
base class - Implement BLE client to connect to StandardBluetoothManager
- Handle display, audio, and sensor capabilities
- See
ANDROID_FIRMWARE_GUIDE.md
for detailed instructions
- Extend
-
Update Device Detection:
-
Configure Manager Selection:
- StandardBluetoothManager will work for most devices
- Choose appropriate NetworkManager based on permissions
- Test with both System and Fallback network managers
Important Notes on Current State
StandardBluetoothManager: A fully implemented BLE GATT server exists with:- Complete BLE GATT server functionality
- Auto-pairing capabilities
- MTU negotiation
- Serial-like data exchange over characteristics
- The K900 (Mentra Live) uses proprietary serial communication via K900BluetoothManager
- The MentraLiveSGC.java in augmentos_core is designed specifically for K900’s serial protocol
- To use StandardBluetoothManager, you’d need a new SmartGlassesCommunicator that acts as a BLE client
Building and Testing
-
Environment Setup:
-
Build Requirements:
- Android Studio with Java SDK 17
- Set Gradle JDK to version 17 in Android Studio settings
-
Testing on Mentra Live Glasses:
Mentra Live only supports ADB over WiFi (no USB ADB). To connect:
a. Setup WiFi ADB Connection:
b. Build and Install:
Message Processing
The client processes JSON commands from the cloud:Compatible Devices
Currently supported:- Mentra Live (K900)
Next Steps for Contributors
- Fix the K900 detection in both factory classes
- Create device-specific SmartGlassesCommunicators in augmentos_core
- Add device detection for your specific glasses model
- Test the StandardBluetoothManager with your device
- Submit PRs with your device support additions
Resources
- MentraOS Mobile App Guidelines - Mobile app development guide