Handle button press events from smart glasses.
Endpoint
POST https://api.mentra.glass/api/hardware/button-press
Authorization: Bearer <glassesJwt>
This endpoint requires glasses authentication, not regular user authentication.
Request Body
{
"buttonId": "main",
"pressType": "short" // or "long"
}
Response
When no apps are subscribed to button events:
{
"success": true,
"action": "take_photo",
"requestId": "photo-request-123"
}
When apps are subscribed to button events:
Error (500):
{
"error": "Failed to process button press"
}
Implementation
- File:
packages/cloud/src/routes/hardware.routes.ts:20-59
- Middleware:
validateGlassesAuth
- Behavior: Creates system photo request if no apps are subscribed to
BUTTON_PRESS stream
- Checks if any apps are subscribed to
BUTTON_PRESS events
- If no apps subscribed:
- Creates a system photo request using
photoRequestService
- Returns photo request ID for glasses to take photo
- If apps subscribed:
- Lets apps handle the button press via WebSocket
- Returns success without action
Check System Photo Request
Check if a system-initiated photo request exists.
Endpoint
GET https://api.mentra.glass/api/hardware/system-photo-request/:requestId
Authorization: Bearer <glassesJwt>
Parameters
| Parameter | Type | Description |
|---|
requestId | string | The photo request ID to check (in URL) |
Response
Success (200):
{
"success": true,
"action": "take_photo"
}
Not Found (404):
{
"success": false,
"message": "Photo request not found"
}
Error (500):
{
"error": "Failed to check system photo request"
}
Implementation
- File:
packages/cloud/src/routes/hardware.routes.ts:66-86
- Service: Uses
photoRequestService.getPendingPhotoRequest()
- Validation: Only returns requests with
origin: 'system'
System Behavior
When no apps are subscribed to button events:
- System creates a photo request with unique ID
- Glasses receive instruction to take photo
- Photo is uploaded via
/api/photos/upload endpoint
- Photo is saved to user’s gallery
When apps subscribe to button events:
- Button press is relayed to subscribed apps via WebSocket
- Apps decide what action to take
- System takes no default action
- Apps can request photos through their own logic
| Button ID | Description |
|---|
main | Primary button on glasses |
Press Types
| Press Type | Description |
|---|
short | Quick button press |
long | Button held down |
Error Codes
| Code | Description |
|---|
| 401 | Unauthorized - invalid glasses token |
| 404 | Photo request not found or not system-origin |
| 500 | Internal server error |
Notes
- Button events are a key hardware interaction point
- System provides default photo-taking behavior
- Apps can override default behavior by subscribing to
BUTTON_PRESS stream
- Photo requests are managed centrally by
photoRequestService
- All endpoints require glasses authentication
- The user is identified by email from the decoded JWT token