Button Press Event

Handle button press events from smart glasses.

Endpoint

POST https://api.mentra.glass/api/hardware/button-press

Headers

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:
{
  "success": true
}
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

Button Press Handling Logic

  1. Checks if any apps are subscribed to BUTTON_PRESS events
  2. If no apps subscribed:
    • Creates a system photo request using photoRequestService
    • Returns photo request ID for glasses to take photo
  3. 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

Headers

Authorization: Bearer <glassesJwt>

Parameters

ParameterTypeDescription
requestIdstringThe 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

Default Button Action

When no apps are subscribed to button events:
  1. System creates a photo request with unique ID
  2. Glasses receive instruction to take photo
  3. Photo is uploaded via /api/photos/upload endpoint
  4. Photo is saved to user’s gallery

App-Controlled Buttons

When apps subscribe to button events:
  1. Button press is relayed to subscribed apps via WebSocket
  2. Apps decide what action to take
  3. System takes no default action
  4. Apps can request photos through their own logic

Button Types

Button IDDescription
mainPrimary button on glasses

Press Types

Press TypeDescription
shortQuick button press
longButton held down

Error Codes

CodeDescription
401Unauthorized - invalid glasses token
404Photo request not found or not system-origin
500Internal 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