Overview
Saved devices allow you to store wireless device configurations for quick reconnection. When you successfully connect to a wireless device, it’s automatically saved with its IP, port, label, and last connection timestamp.
GET /api/saved-devices
Get the list of all saved wireless devices.
Response
Array of saved device objects Unique device ID (timestamp-based)
Device label (either custom or auto-detected brand/model)
ISO 8601 timestamp of last successful connection
Example Request
curl http://localhost:3000/api/saved-devices
const response = await fetch ( 'http://localhost:3000/api/saved-devices' );
const data = await response . json ();
console . log ( data . devices );
Example Response
{
"devices" : [
{
"id" : "1709123456789" ,
"label" : "Samsung Galaxy S21" ,
"ip" : "192.168.1.100" ,
"port" : "5555" ,
"lastConnected" : "2024-03-01T14:23:45.123Z"
},
{
"id" : "1709234567890" ,
"label" : "My Tablet" ,
"ip" : "192.168.1.150" ,
"port" : "5555" ,
"lastConnected" : "2024-02-28T10:15:30.456Z"
}
]
}
POST /api/saved-devices
Manually add or update a saved wireless device.
Request Body
Custom device label. If omitted, defaults to "ip:port"
Response
Behavior
If a device with the same IP and port already exists, it’s updated with the new label and timestamp
If it doesn’t exist, a new device is added
The lastConnected timestamp is always set to the current time
Example Request
curl -X POST http://localhost:3000/api/saved-devices \
-H "Content-Type: application/json" \
-d '{
"ip": "192.168.1.100",
"port": "5555",
"label": "My Phone"
}'
const response = await fetch ( 'http://localhost:3000/api/saved-devices' , {
method: 'POST' ,
headers: { 'Content-Type' : 'application/json' },
body: JSON . stringify ({
ip: '192.168.1.100' ,
port: '5555' ,
label: 'My Phone'
})
});
const data = await response . json ();
// { ok: true }
Example Response
Error Response
Returns 400 if required fields are missing:
{
"error" : "IP y puerto son requeridos"
}
DELETE /api/saved-devices/:id
Remove a saved device by its ID.
Path Parameters
Device ID (from the id field in saved devices)
Response
Always returns true (even if the ID doesn’t exist)
Example Request
curl -X DELETE http://localhost:3000/api/saved-devices/1709123456789
const deviceId = '1709123456789' ;
const response = await fetch (
`http://localhost:3000/api/saved-devices/ ${ deviceId } ` ,
{ method: 'DELETE' }
);
const data = await response . json ();
// { ok: true }
Example Response
Auto-Save Behavior
Devices are automatically saved or updated in these scenarios:
1. Successful Wireless Connection
When /api/adb/connect succeeds, the device is automatically saved with:
Auto-detected brand and model (if no custom label provided)
Current timestamp in lastConnected
Generated unique ID (if new)
2. Device Detection
When /api/devices detects a wireless device, if its IP matches a saved device:
The saved device’s lastConnected is updated
The saved device’s label is updated with the detected brand/model (if different)
Use Cases
Quick Reconnect UI
Build a “Recent Devices” list for one-tap reconnection:
// Fetch saved devices
const { devices } = await fetch ( 'http://localhost:3000/api/saved-devices' )
. then ( r => r . json ());
// Sort by most recent
devices . sort (( a , b ) =>
new Date ( b . lastConnected ) - new Date ( a . lastConnected )
);
// Display in UI with "Connect" button
devices . forEach ( device => {
console . log ( ` ${ device . label } ( ${ device . ip } : ${ device . port } )` );
// When clicked:
// POST /api/adb/connect with device.ip and device.port
});
Device Management
Allow users to edit labels or remove old devices:
// Update device label
await fetch ( 'http://localhost:3000/api/saved-devices' , {
method: 'POST' ,
headers: { 'Content-Type' : 'application/json' },
body: JSON . stringify ({
ip: device . ip ,
port: device . port ,
label: 'New Custom Name'
})
});
// Remove device
await fetch ( `http://localhost:3000/api/saved-devices/ ${ device . id } ` , {
method: 'DELETE'
});
Storage
Saved devices are stored in:
File: devices.json in the server directory
Format: JSON array of device objects
Persistence: Survives server restarts
Cache: Loaded into memory on first access
Example devices.json:
[
{
"id" : "1709123456789" ,
"label" : "Samsung Galaxy S21" ,
"ip" : "192.168.1.100" ,
"port" : "5555" ,
"lastConnected" : "2024-03-01T14:23:45.123Z"
}
]