- Add updateDeviceMetadata and attachDeviceToDeployment API methods - Device Settings: editable location/description fields with save - Equipment screen: location placeholder and quick navigation to settings - Add Sensor: multi-select with checkboxes, select all/deselect all - Setup WiFi: batch processing of multiple sensors sequentially - BatchSetupProgress: animated progress bar, step indicators, auto-scroll - SetupResultsScreen: success/failed/skipped summary with retry options - Error handling: modal with Retry/Skip/Cancel All buttons - Documentation: SENSORS_SYSTEM.md with full BLE protocol and flows Implemented via Ralphy CLI autonomous agent in ~43 minutes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
9.8 KiB
PRD: Sensors Management System
Context
WellNuo app for elderly care. BLE/WiFi sensors monitor beneficiaries (elderly people) at home. Each user can have multiple beneficiaries. Each beneficiary has one deployment (household) with up to 5 sensors.
Architecture:
- User → Beneficiary (WellNuo API) → deploymentId → Deployment (Legacy API) → Devices
- BLE for sensor setup, WiFi for data transmission
- Legacy API at
https://eluxnetworks.net/function/well-api/api(external, read-only code access)
Documentation: docs/SENSORS_SYSTEM.md
Feature Spec: specs/wellnuo/FEATURE-SENSORS-SYSTEM.md
Tasks
Phase 1: API Layer
-
TASK-1.1: Add updateDeviceMetadata method to api.ts
File:
services/api.tsAdd method to update device location and description via Legacy API.
async updateDeviceMetadata( wellId: number, mac: string, deploymentId: number, location: string, description: string ): Promise<boolean>Implementation:
- Get Legacy API credentials via
getLegacyCredentials() - Build form data with:
function=device_form,user_name,token,well_id,device_mac,location,description,deployment_id - POST to
https://eluxnetworks.net/function/well-api/api - Return true on success, false on error
Reference:
docs/SENSORS_SYSTEM.mdlines 266-280 for API format. - Get Legacy API credentials via
Phase 2: Device Settings UI
-
TASK-2.1: Add location/description editing to Device Settings screen
File:
app/(tabs)/beneficiaries/[id]/device-settings/[deviceId].tsxAdd editable fields for sensor location and description:
- Add state variables:
location,description,isSaving - Add two TextInput fields below device info section
- Add "Save" button that calls
api.updateDeviceMetadata() - Show loading indicator during save
- Show success/error toast after save
- Pre-fill fields with current values from device data
UI requirements:
- TextInput for location (placeholder: "e.g., Bedroom, near bed")
- TextInput for description (placeholder: "e.g., Main activity sensor")
- Button: "Save Changes" (disabled when no changes or saving)
- Toast: "Settings saved" on success
- Add state variables:
Phase 3: Equipment Screen Improvements
-
TASK-3.1: Show placeholder for empty location in Equipment screen
File:
app/(tabs)/beneficiaries/[id]/equipment.tsxFind the sensor list rendering (around line 454) and update:
Before:
{sensor.location && ( <Text style={styles.deviceLocation}>{sensor.location}</Text> )}After:
<Text style={[styles.deviceLocation, !sensor.location && styles.deviceLocationEmpty]}> {sensor.location || 'Tap to set location'} </Text>Add style
deviceLocationEmptywithopacity: 0.5, fontStyle: 'italic' -
TASK-3.2: Add quick navigation to Device Settings from Equipment screen
File:
app/(tabs)/beneficiaries/[id]/equipment.tsxMake the location text tappable to navigate to Device Settings:
- Wrap location Text in TouchableOpacity
- onPress: navigate to
/beneficiaries/${id}/device-settings/${device.id} - Import
useRouterfromexpo-routerif not already imported
Phase 4: Batch Sensor Setup - Selection UI
-
TASK-4.1: Add checkbox selection to Add Sensor screen
File:
app/(tabs)/beneficiaries/[id]/add-sensor.tsxAfter BLE scan, show checkboxes for selecting multiple sensors:
- Add state:
selectedDevices: Set<string>(device IDs) - After scan, select ALL devices by default
- Render each device with checkbox (use Checkbox from react-native or custom)
- Add "Select All" / "Deselect All" toggle at top
- Show count: "3 of 5 selected"
- Change button from "Connect" to "Setup Selected (N)"
- Pass selected devices to Setup WiFi screen via route params
UI layout:
[ ] Select All [x] WP_497_81a14c -55 dBm ✓ [x] WP_498_82b25d -62 dBm ✓ [ ] WP_499_83c36e -78 dBm [Setup Selected (2)] - Add state:
-
TASK-4.2: Update navigation to pass selected devices
File:
app/(tabs)/beneficiaries/[id]/add-sensor.tsxWhen navigating to setup-wifi screen, pass selected devices:
router.push({ pathname: `/(tabs)/beneficiaries/${id}/setup-wifi`, params: { devices: JSON.stringify(selectedDevicesArray), beneficiaryId: id } });
Phase 5: Batch Sensor Setup - WiFi Configuration
-
TASK-5.1: Refactor Setup WiFi screen for batch processing
File:
app/(tabs)/beneficiaries/[id]/setup-wifi.tsxUpdate to handle multiple devices:
- Parse
devicesfrom route params (JSON array of WPDevice objects) - Get WiFi list from FIRST device only (all sensors at same location = same WiFi)
- After user enters password, process ALL devices sequentially
- Add state for batch progress tracking
New state:
interface DeviceSetupState { deviceId: string; deviceName: string; status: 'pending' | 'connecting' | 'unlocking' | 'setting_wifi' | 'attaching' | 'rebooting' | 'success' | 'error'; error?: string; } const [setupStates, setSetupStates] = useState<DeviceSetupState[]>([]); - Parse
-
TASK-5.2: Implement batch setup processing logic
File:
app/(tabs)/beneficiaries/[id]/setup-wifi.tsxCreate
processBatchSetupfunction:async function processBatchSetup(ssid: string, password: string) { for (const device of devices) { updateStatus(device.id, 'connecting'); // 1. Connect BLE const connected = await bleManager.connectDevice(device.id); if (!connected) { updateStatus(device.id, 'error', 'Could not connect'); continue; // Skip to next device } // 2. Unlock with PIN updateStatus(device.id, 'unlocking'); await bleManager.sendCommand(device.id, 'pin|7856'); // 3. Set WiFi updateStatus(device.id, 'setting_wifi'); await bleManager.setWiFi(device.id, ssid, password); // 4. Attach to deployment via Legacy API updateStatus(device.id, 'attaching'); await api.attachDeviceToDeployment(device.wellId, device.mac, deploymentId); // 5. Reboot updateStatus(device.id, 'rebooting'); await bleManager.rebootDevice(device.id); updateStatus(device.id, 'success'); } } -
TASK-5.3: Add progress UI for batch setup
File:
app/(tabs)/beneficiaries/[id]/setup-wifi.tsxShow progress for each device:
Connecting to "Home_Network"... WP_497_81a14c ✓ Connected ✓ Unlocked ✓ WiFi configured ● Attaching to Maria... WP_498_82b25d ✓ Connected ○ Waiting... WP_499_83c36e ○ PendingUse icons: ✓ (success), ● (in progress), ○ (pending), ✗ (error)
Phase 6: Error Handling
-
TASK-6.1: Add error handling UI with retry/skip options
File:
app/(tabs)/beneficiaries/[id]/setup-wifi.tsxWhen a device fails:
- Pause batch processing
- Show error message with device name
- Show three buttons: [Retry] [Skip] [Cancel All]
- On Retry: try this device again
- On Skip: mark as skipped, continue to next device
- On Cancel All: abort entire process, show results
{currentError && ( <View style={styles.errorContainer}> <Text style={styles.errorTitle}> Failed: {currentError.deviceName} </Text> <Text style={styles.errorMessage}> {currentError.message} </Text> <View style={styles.errorButtons}> <Button title="Retry" onPress={handleRetry} /> <Button title="Skip" onPress={handleSkip} /> <Button title="Cancel All" onPress={handleCancelAll} /> </View> </View> )} -
TASK-6.2: Add results screen after batch setup
File:
app/(tabs)/beneficiaries/[id]/setup-wifi.tsxAfter all devices processed, show summary:
Setup Complete Successfully connected: ✓ WP_497_81a14c ✓ WP_498_82b25d Failed: ✗ WP_499_83c36e - Connection timeout [Retry This Sensor] Skipped: ⊘ WP_500_84d47f [Done]"Done" button navigates back to Equipment screen.
Phase 7: API Method for Device Attachment
-
TASK-7.1: Add attachDeviceToDeployment method to api.ts
File:
services/api.tsAdd method to register a new device with Legacy API:
async attachDeviceToDeployment( wellId: number, mac: string, deploymentId: number, location?: string, description?: string ): Promise<{ success: boolean; deviceId?: number; error?: string }>Implementation:
- Call Legacy API
device_formwith deployment_id set - Return device ID from response on success
- Return error message on failure
This is used during batch setup to link each sensor to the beneficiary's deployment.
- Call Legacy API
Verification Checklist
After all tasks complete, verify:
- Can view sensors list for any beneficiary
- Can scan and find WP_* sensors via BLE
- Can select multiple sensors with checkboxes
- Can configure WiFi for all selected sensors
- Progress UI shows status for each device
- Errors show retry/skip options
- Results screen shows success/failure summary
- Can edit sensor location in Device Settings
- Location placeholder shows in Equipment screen
- Can tap location to go to Device Settings
- Mock BLE works in iOS Simulator
Notes for AI Agent
- Read documentation first:
docs/SENSORS_SYSTEM.mdhas full context - Check existing code: Files may already have partial implementations
- BLE Manager: Use
services/ble/BLEManager.tsfor real device,MockBLEManager.tsfor simulator - Legacy API auth: Use
getLegacyCredentials()method in api.ts - Error handling: Always wrap BLE operations in try/catch
- TypeScript: Project uses strict TypeScript, ensure proper types
- Testing: Use iOS Simulator with Mock BLE for testing