Skip to content

Commit f60e57e

Browse files
authored
Merge pull request #51 from Pyrrha-Platform/updates
Updates
2 parents 87a00f4 + bd93c74 commit f60e57e

16 files changed

Lines changed: 2802 additions & 99 deletions

GALAXY_WATCH_INTEGRATION.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
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

app/build.gradle

Lines changed: 75 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 30
5-
buildToolsVersion "30.0.3"
4+
namespace 'org.pyrrha_platform'
5+
compileSdk 34 // Updated to Android 14 (latest stable)
6+
buildToolsVersion "34.0.0"
67

78
defaultConfig {
89
applicationId "org.pyrrha.platform"
9-
minSdkVersion 19
10-
targetSdkVersion 30
10+
minSdkVersion 26 // Updated to Android 8.0 (covers Samsung Galaxy A51 and 95%+ devices)
11+
targetSdkVersion 34 // Updated to Android 14 (IBM App ID temporarily removed)
1112
multiDexEnabled true
12-
versionCode 1
13-
versionName "1.0"
13+
versionCode 2 // Incremented for modernization
14+
versionName "2.0.0" // Version bump for major modernization
1415

1516
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16-
manifestPlaceholders = ['appIdRedirectScheme': android.defaultConfig.applicationId]
17+
// manifestPlaceholders = ['appIdRedirectScheme': android.defaultConfig.applicationId] // TEMPORARILY REMOVED
1718
}
1819

1920
buildTypes {
@@ -22,50 +23,84 @@ android {
2223
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
2324
}
2425
}
26+
27+
compileOptions {
28+
sourceCompatibility JavaVersion.VERSION_17
29+
targetCompatibility JavaVersion.VERSION_17
30+
}
31+
32+
// Enable modern Android features
33+
buildFeatures {
34+
viewBinding true
35+
dataBinding true
36+
buildConfig true
37+
}
38+
39+
lint {
40+
baseline = file("lint-baseline.xml")
41+
abortOnError false
42+
}
2543
}
2644

2745
dependencies {
2846
implementation fileTree(dir: "libs", include: ["*.jar"])
29-
implementation 'androidx.appcompat:appcompat:1.3.0'
30-
implementation 'com.google.android.material:material:1.4.0'
31-
implementation 'androidx.annotation:annotation:1.2.0'
32-
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
33-
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
34-
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
35-
implementation 'androidx.navigation:navigation-fragment:2.3.5'
36-
implementation 'androidx.navigation:navigation-ui:2.3.5'
47+
48+
// Core AndroidX libraries - updated to latest stable versions
49+
implementation 'androidx.appcompat:appcompat:1.6.1'
50+
implementation 'com.google.android.material:material:1.11.0'
51+
implementation 'androidx.annotation:annotation:1.7.1'
52+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
53+
implementation 'androidx.core:core-ktx:1.12.0' // Added for modern Android
54+
55+
// Lifecycle - updated to use ViewModel and LiveData instead of deprecated extensions
56+
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.7.0'
57+
implementation 'androidx.lifecycle:lifecycle-livedata:2.7.0'
58+
implementation 'androidx.lifecycle:lifecycle-runtime:2.7.0'
59+
60+
// Navigation - updated to latest
61+
implementation 'androidx.navigation:navigation-fragment:2.7.6'
62+
implementation 'androidx.navigation:navigation-ui:2.7.6'
63+
64+
// Samsung SDK files (keep existing)
3765
implementation files('libs/accessory-v2.6.4.jar')
3866
implementation files('libs/sdk-v1.0.0.jar')
39-
testImplementation 'junit:junit:4.12'
40-
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
41-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
42-
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
43-
implementation 'com.google.code.gson:gson:2.8.6'
44-
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.1'
67+
68+
// Testing - updated versions
69+
testImplementation 'junit:junit:4.13.2'
70+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
71+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
72+
73+
// JSON processing - updated Gson
74+
implementation 'com.google.code.gson:gson:2.10.1'
75+
76+
// MQTT - updated to latest stable versions
77+
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5'
4578
implementation('org.eclipse.paho:org.eclipse.paho.android.service:1.1.1') {
4679
exclude module: 'support-v4'
4780
}
48-
implementation 'com.github.ibm-cloud-security:appid-clientsdk-android:6.+'
49-
50-
// We need this dependency for the api res call
51-
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
52-
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
53-
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.0'
54-
55-
def room_version = "2.3.0"
56-
81+
82+
// IBM App ID SDK for authentication - TEMPORARILY REMOVED
83+
// implementation 'com.github.ibm-cloud-security:appid-clientsdk-android:6.+'
84+
85+
// Networking - updated Retrofit and OkHttp to latest stable
86+
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
87+
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
88+
implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'
89+
90+
// Room database - updated to latest stable
91+
def room_version = "2.6.1"
5792
implementation "androidx.room:room-runtime:$room_version"
5893
annotationProcessor "androidx.room:room-compiler:$room_version"
59-
60-
// optional - RxJava support for Room
61-
implementation "androidx.room:room-rxjava2:$room_version"
62-
63-
// optional - Guava support for Room, including Optional and ListenableFuture
94+
95+
// Room optional features - updated
96+
implementation "androidx.room:room-rxjava3:$room_version" // Updated from RxJava2 to RxJava3
6497
implementation "androidx.room:room-guava:$room_version"
65-
66-
// optional - Test helpers
6798
testImplementation "androidx.room:room-testing:$room_version"
68-
99+
100+
// Security and modern Android features
101+
implementation 'androidx.security:security-crypto:1.1.0-alpha06' // For secure data storage
102+
implementation 'androidx.work:work-runtime:2.9.0' // For background tasks
103+
69104
}
70105

71106
android{
@@ -94,9 +129,9 @@ if (propFile.canRead()) {
94129
}
95130
}
96131
} else {
97-
throw new InvalidUserDataException('pyrrha.properties found, but some entries are missing')
132+
throw new RuntimeException('pyrrha.properties found, but some entries are missing')
98133
}
99134
} else {
100135
// The properties file was not found
101-
throw new MissingResourceException('pyrrha.properties not found')
136+
throw new RuntimeException('pyrrha.properties not found')
102137
}

0 commit comments

Comments
 (0)