|
| 1 | +# Pyrrha Mobile-Watch Integration Guide |
| 2 | + |
| 3 | +## Samsung Accessory Protocol Integration |
| 4 | + |
| 5 | +This document describes the Samsung Accessory Protocol integration between the Pyrrha Mobile App (Provider) and Pyrrha Watch App (Consumer) for real-time sensor data transmission. |
| 6 | + |
| 7 | +## Architecture Overview |
| 8 | + |
| 9 | +``` |
| 10 | +Prometeo Device (BLE) → Mobile App (Provider) → Galaxy Watch (Consumer) |
| 11 | +``` |
| 12 | + |
| 13 | +### Mobile App (Provider) |
| 14 | +- **Service**: `ProviderService.java` extends `SAAgent` |
| 15 | +- **Role**: Provider (sends sensor data) |
| 16 | +- **App Name**: `PyrrhaMobileProvider` |
| 17 | +- **Channel ID**: 104 |
| 18 | +- **Service Profile**: `/org/pyrrha-platform/readings` |
| 19 | + |
| 20 | +### Watch App (Consumer) |
| 21 | +- **Service**: JavaScript consumer in `connect.js` |
| 22 | +- **Role**: Consumer (receives sensor data) |
| 23 | +- **Expected Provider**: `PyrrhaMobileProvider` |
| 24 | +- **Channel ID**: 104 |
| 25 | + |
| 26 | +## Data Flow |
| 27 | + |
| 28 | +1. **BLE Reception**: Mobile app receives sensor data from Prometeo device via Bluetooth LE |
| 29 | +2. **Data Parsing**: `DeviceDashboard.displayData()` parses space-separated sensor values: |
| 30 | + - `parts[2]` = Temperature (°C) |
| 31 | + - `parts[4]` = Humidity (%) |
| 32 | + - `parts[6]` = Carbon Monoxide (ppm) |
| 33 | + - `parts[8]` = Nitrogen Dioxide (ppm) |
| 34 | +3. **Data Validation**: Invalid readings (CO > 1000 or < 0, NO2 > 10 or < 0) are set to 0 |
| 35 | +4. **JSON Formatting**: Data is formatted as JSON with message type and timestamp |
| 36 | +5. **Samsung Accessory Protocol**: Data transmitted via Samsung Accessory Protocol to watch |
| 37 | +6. **Watch Display**: Watch receives and displays real-time sensor readings |
| 38 | + |
| 39 | +## JSON Message Format |
| 40 | + |
| 41 | +```json |
| 42 | +{ |
| 43 | + "messageType": "sensor_data", |
| 44 | + "temperature": 25.4, |
| 45 | + "humidity": 65.2, |
| 46 | + "co": 15.3, |
| 47 | + "no2": 0.8, |
| 48 | + "timestamp": 1672531200000, |
| 49 | + "deviceId": "Prometeo:00:00:00:00:00:01", |
| 50 | + "status": "normal" |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +### Status Values |
| 55 | +- `"normal"`: All readings within safe thresholds |
| 56 | +- `"warning"`: One or more readings at 80% of alert threshold |
| 57 | +- `"alert"`: One or more readings exceed safety thresholds |
| 58 | + |
| 59 | +### Alert Thresholds |
| 60 | +- **Temperature**: 32°C |
| 61 | +- **Humidity**: 80% |
| 62 | +- **Carbon Monoxide**: 420 ppm |
| 63 | +- **Nitrogen Dioxide**: 8 ppm |
| 64 | + |
| 65 | +## Service Configuration |
| 66 | + |
| 67 | +### Mobile App Configuration |
| 68 | + |
| 69 | +**AndroidManifest.xml**: |
| 70 | +```xml |
| 71 | +<service android:name="org.pyrrha_platform.galaxy.ProviderService" /> |
| 72 | +``` |
| 73 | + |
| 74 | +**accessoryservices.xml**: |
| 75 | +```xml |
| 76 | +<application name="PyrrhaMobileProvider"> |
| 77 | + <serviceProfile |
| 78 | + id="/org/pyrrha-platform/readings" |
| 79 | + name="PyrrhaSensorProvider" |
| 80 | + role="provider" |
| 81 | + serviceImpl="org.pyrrha_platform.galaxy.ProviderService" |
| 82 | + version="2.0" |
| 83 | + serviceLimit="ANY" |
| 84 | + serviceTimeout="10000"> |
| 85 | + <supportedTransports> |
| 86 | + <transport type="TRANSPORT_BT" /> |
| 87 | + <transport type="TRANSPORT_WIFI" /> |
| 88 | + </supportedTransports> |
| 89 | + <serviceChannel |
| 90 | + id="104" |
| 91 | + dataRate="HIGH" |
| 92 | + priority="HIGH" |
| 93 | + reliability="ENABLE" /> |
| 94 | + <supportedFeatures> |
| 95 | + <feature type="message" /> |
| 96 | + </supportedFeatures> |
| 97 | + </serviceProfile> |
| 98 | +</application> |
| 99 | +``` |
| 100 | + |
| 101 | +### Watch App Configuration |
| 102 | + |
| 103 | +**config.xml**: |
| 104 | +```xml |
| 105 | +<tizen:application id="Jqb25DY60P.pyrrha" package="Jqb25DY60P" required_version="5.5"/> |
| 106 | +<tizen:setting background-support="enable" encryption="disable" hwkey-event="enable"/> |
| 107 | +<tizen:privilege name="http://tizen.org/privilege/healthinfo"/> |
| 108 | +<tizen:privilege name="http://tizen.org/privilege/alarm.set"/> |
| 109 | +``` |
| 110 | + |
| 111 | +## Testing Integration |
| 112 | + |
| 113 | +### Prerequisites |
| 114 | +1. Samsung Galaxy A51 with Android 14 (API 34) |
| 115 | +2. Samsung Galaxy Watch 3 with Tizen 5.5 |
| 116 | +3. Both devices paired via Samsung Galaxy Watch app |
| 117 | +4. Pyrrha Mobile App installed on phone |
| 118 | +5. Pyrrha Watch App installed on watch |
| 119 | + |
| 120 | +### Test Procedure |
| 121 | + |
| 122 | +1. **Start Mobile App**: Launch Pyrrha app and connect to Prometeo device |
| 123 | +2. **Check Provider Service**: Verify ProviderService starts and searches for watches |
| 124 | +3. **Start Watch App**: Launch Pyrrha app on Galaxy Watch |
| 125 | +4. **Connection**: Watch should automatically discover and connect to mobile provider |
| 126 | +5. **Data Flow**: Sensor readings should appear on watch within 3 seconds of mobile reception |
| 127 | + |
| 128 | +### Debugging |
| 129 | + |
| 130 | +**Mobile App Logs**: |
| 131 | +```bash |
| 132 | +adb logcat -s PyrrhaMobileProvider |
| 133 | +``` |
| 134 | + |
| 135 | +**Watch App Logs**: |
| 136 | +Access via Tizen Studio or Samsung Internet debugger on watch |
| 137 | + |
| 138 | +### Common Issues |
| 139 | + |
| 140 | +1. **Connection Failed**: Ensure both devices are on same Samsung account and paired |
| 141 | +2. **Service Not Found**: Verify both apps are running and have correct service profiles |
| 142 | +3. **No Data**: Check that Prometeo device is connected to mobile app via BLE |
| 143 | +4. **Invalid Data**: Sensor validation may filter out invalid readings (CO > 1000, NO2 > 10) |
| 144 | + |
| 145 | +## Implementation Details |
| 146 | + |
| 147 | +### ProviderService Features |
| 148 | +- **Automatic Discovery**: Searches for Galaxy Watches on service start |
| 149 | +- **Connection Management**: Handles multiple watch connections |
| 150 | +- **Error Handling**: Comprehensive error codes and reconnection logic |
| 151 | +- **Heartbeat Support**: Responds to watch heartbeat requests |
| 152 | +- **Data Broadcasting**: Sends sensor data every 3 seconds to connected watches |
| 153 | + |
| 154 | +### Watch Consumer Features |
| 155 | +- **Auto-Connect**: Automatically connects to PyrrhaMobileProvider |
| 156 | +- **Message Parsing**: Handles JSON sensor data and control messages |
| 157 | +- **UI Updates**: Real-time sensor display with circular Galaxy Watch 3 optimization |
| 158 | +- **Alert System**: Vibration alerts when readings exceed thresholds |
| 159 | +- **Reconnection**: Automatic reconnection on connection loss |
| 160 | + |
| 161 | +## Security Considerations |
| 162 | + |
| 163 | +- Samsung Accessory Protocol uses built-in Samsung authentication |
| 164 | +- Data transmission encrypted via Samsung framework |
| 165 | +- No additional authentication required for paired devices |
| 166 | +- Service limited to Samsung Galaxy ecosystem |
| 167 | + |
| 168 | +## Performance Notes |
| 169 | + |
| 170 | +- **Update Frequency**: 3-second intervals for optimal battery life |
| 171 | +- **Data Size**: JSON messages ~200 bytes each |
| 172 | +- **Battery Impact**: Minimal - uses Samsung's optimized protocol |
| 173 | +- **Range**: Standard Bluetooth range (10 meters typical) |
| 174 | + |
| 175 | +## Development Notes |
| 176 | + |
| 177 | +- Provider service automatically starts with DeviceDashboard activity |
| 178 | +- Watch consumer runs continuously while app is active |
| 179 | +- Service connections managed in activity lifecycle |
| 180 | +- Error handling includes graceful degradation without watch connectivity |
| 181 | + |
| 182 | +## Future Enhancements |
| 183 | + |
| 184 | +- Historical data synchronization |
| 185 | +- Multiple device support |
| 186 | +- Custom alert thresholds |
| 187 | +- Watch-initiated sensor requests |
| 188 | +- Offline data buffering |
0 commit comments