This guide provides a quick overview of how to integrate ReflectionsOS watch functionality with Superstar Avatar.
- Hardware: ReflectionsOS watch with ESP32-S3
- Flutter Package: Add
flutter_blue_plusfor BLE communication - Firmware: Custom ReflectionsOS firmware with BLE GATT server
Add to pubspec.yaml:
dependencies:
flutter_blue_plus: ^1.0.0 # For BLE connectivityRun:
flutter pub getThe ReflectionsService class in lib/services/reflections_service.dart has placeholder TODOs that need to be implemented with actual BLE code. The structure is ready - you just need to:
- Uncomment and implement the BLE scanning code
- Implement device connection
- Implement data transmission/reception
- Test with your ReflectionsOS hardware
Example integration in activity completion:
import 'services/reflections_service.dart';
Future<void> completeActivityWithGesture(ActivityScript activity) async {
final reflectionsService = ReflectionsService();
// Connect to watch if not already connected
if (!reflectionsService.isConnected) {
// Scan and connect to watch
await reflectionsService.scanForDevices().first.then((device) {
return reflectionsService.connectToWatch(device['id']!);
});
}
// Map activity to expected gesture
final expectedGesture = mapActivityToGesture(activity);
// Wait for gesture verification
final verified = await reflectionsService.verifyActivityWithGesture(
activity.id,
expectedGesture,
);
if (verified) {
// Complete activity on blockchain
await blockchainService.completeActivity(
activityId: activity.id,
avatarId: avatar.id,
proof: 'gesture_verified', // Include gesture signature
);
// Trigger haptic celebration
await reflectionsService.triggerHaptic(
ReflectionsService.HapticPattern.celebration,
);
}
}Future<void> syncAvatarToWatch(Avatar avatar) async {
final reflectionsService = ReflectionsService();
if (!reflectionsService.isConnected) {
return; // Skip if not connected
}
// Convert avatar to JSON
final avatarJson = avatar.toJson();
// Sync to watch
await reflectionsService.syncAvatarToWatch(avatarJson);
// Update power levels display
final powersJson = avatar.powers.map((p) => {
'type': p.type.toString(),
'level': p.level,
'experience': p.experience,
'maxExperience': p.maxExperience,
}).toList();
await reflectionsService.updatePowerDisplay(powersJson);
}Create a helper function to map gestures to activities:
ReflectionsService.GestureType mapActivityToGesture(ActivityScript activity) {
// Map based on primary power
switch (activity.primaryPower) {
case PowerType.Courage:
return ReflectionsService.GestureType.highFive;
case PowerType.Creativity:
return ReflectionsService.GestureType.drawing;
case PowerType.Connection:
return ReflectionsService.GestureType.handshake;
case PowerType.Insight:
return ReflectionsService.GestureType.thinking;
case PowerType.Kindness:
return ReflectionsService.GestureType.wave;
default:
return ReflectionsService.GestureType.singleTap;
}
}- Service:
0000fe40-cc7a-482a-984a-7f2ed5b3e58f
-
Command Characteristic (
0000fe41-cc7a-482a-984a-7f2ed5b3e58f)- Write only
- Send commands to watch (haptic, display updates, etc.)
- Format: JSON strings
-
Data Characteristic (
0000fe42-cc7a-482a-984a-7f2ed5b3e58f)- Write only
- Send avatar data, power levels, etc.
- Format: JSON strings (may need chunking for large payloads)
-
Gesture Characteristic (
0000fe43-cc7a-482a-984a-7f2ed5b3e58f)- Notify/Read
- Receive gesture events from watch
- Format: JSON strings with gesture data
{
"type": "haptic",
"pattern": "celebration"
}{
"type": "avatar_sync",
"data": {
"id": "avatar123",
"name": "My Avatar",
"powers": [...],
"totalExperience": 5000
}
}{
"type": "power_update",
"powers": [
{
"type": "Courage",
"level": 5,
"experience": 2500,
"maxExperience": 3000
}
]
}{
"gesture": "highFive",
"confidence": 0.95,
"timestamp": 1640000000
}The ESP32 firmware needs to implement:
- BLE GATT Server with the service and characteristics above
- Gesture Recognition - Process accelerometer/IMU data and detect gestures
- Display Manager - Render avatar data on TFT display
- Haptic Controller - Trigger vibration patterns
- GPS Data Transmission (optional, for location features)
// BLE Service setup
BLEServer *pServer = BLEDevice::createServer();
BLEService *pService = pServer->createService(serviceUuid);
// Gesture characteristic
BLECharacteristic *pGestureChar = pService->createCharacteristic(
gestureCharacteristicUuid,
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY
);
// Command characteristic
BLECharacteristic *pCommandChar = pService->createCharacteristic(
commandCharacteristicUuid,
BLECharacteristic::PROPERTY_WRITE
);
pCommandChar->setCallbacks(new CommandCallbacks());
// Gesture detection loop
void loop() {
GestureType gesture = detectGesture(); // Your gesture recognition logic
if (gesture != NONE) {
String gestureJson = "{\"gesture\":\"" + gestureToString(gesture) + "\"}";
pGestureChar->setValue(gestureJson.c_str());
pGestureChar->notify();
}
delay(100);
}- BLE device discovery works
- Connection to ReflectionsOS watch succeeds
- Gesture events are received from watch
- Avatar data syncs to watch display
- Haptic feedback triggers correctly
- Activity verification flow works end-to-end
- Power level updates display correctly
- Error handling works (disconnection, timeouts)
- Hardware Setup: Get ReflectionsOS watch hardware
- Firmware Development: Implement BLE GATT server in ESP32 firmware
- Flutter Implementation: Complete BLE code in
ReflectionsService - Integration Testing: Test gesture recognition and activity verification
- UI Integration: Add watch connection UI to settings screen
- Smart Contract Updates: Add gesture proof fields to activity contracts
- Ensure ReflectionsOS watch is powered on and in pairing mode
- Check BLE permissions are granted in app settings
- Verify service UUID matches in firmware
- Check device is within BLE range (typically ~10 meters)
- Verify no other device is connected to watch
- Check firmware is running latest version
- Verify gesture recognition is enabled in firmware
- Check gesture characteristic notifications are enabled
- Ensure accelerometer/IMU sensors are calibrated
- Check JSON format matches expected protocol
- Verify data chunking for large payloads
- Check firmware buffer sizes are sufficient
- Full Integration Analysis: See
REFLECTIONSOS_INTEGRATION_ANALYSIS.md - Flutter Blue Plus Docs: https://pub.dev/packages/flutter_blue_plus
- ESP32 BLE Documentation: https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/bluetooth/bt_ble.html
- ReflectionsOS Repository: https://github.com/tjcrowley/ReflectionsOS
Note: This is a reference implementation. Actual implementation details may vary based on your specific ReflectionsOS firmware version and hardware configuration.