CARP Flutter Plugins
repository·master·Indexed 20 days ago
https://github.com/carp-dk/flutter-pluginsA collection of first-party Flutter plugins maintained by the Copenhagen Research Platform (CARP) for accessing platform-specific sensors and APIs. Included plugins provide functionality for activity recognition, air quality data retrieval via aqicn.org, Android app usage statistics, PCM audio streaming via audio_streamer, and background location tracking.
What's inside carp-dk-flutter-plugins
- This repository contains a collection of first-party Flutter plugins maintained by the Copenhagen Research Platform (CARP) team at the Technical University of Denmark. These plugins provide access to platform-specific APIs (Android and iOS) via platform channels, enabling features like sensor data collection, location tracking, and environmental monitoring within Flutter applications.
How Empatica device management and streams work
masterThe plugin maps the Empatica Android API almost 1:1 but uses Dart
Streams instead of callbacks to follow Flutter's reactive architecture.Key concepts:
EmpaticaPlugin: The main class used to manage all device operations.statusEventSink: A stream used to monitor the state of the device manager (e.g.,UpdateStatus,DiscoverDevice).dataEventSink: A stream that emits physiological data once a device is connected.
Important Lifecycle Rule: You must start listening to
statusEventSinkanddataEventSinkbefore initiating connection or scanning to ensure you don't miss events.How Movisens device hierarchy works
masterThe plugin follows a hierarchical Bluetooth GATT structure:
MovisensDevice: The top-level object representing the sensor.MovisensService: A collection of related data categories (e.g.,ambientService,hrvService) belonging to the device.MovisensBluetoothCharacteristic: The individual data types within a service. These are either:- Streams: Continuous data like
SensorTemperatureEvents. - Read/Write: Discrete actions like
setDeleteData().
- Streams: Continuous data like
How ESenseManager and Streams work together
masterThe
esense_flutterplugin uses a reactive programming model based on DartStreams. Instead of traditional listeners, you interact with theESenseManagerby listening to specific streams for different types of data:connectionEvents: ProvidesConnectionEventupdates. You should start listening to this stream before callingconnect()to ensure you capture the connection status.sensorEvents: Provides a stream ofSensorEventdata. You can control the sampling rate usingsetSamplingRate()when not actively listening.eSenseEvents: Used for asynchronous property reading. When you call a method likegetDeviceName(), the result is emitted as anESenseEventthrough this stream.
Important: Audio playing and recording are performed via Bluetooth Classic and are not supported by this specific library.
// 1. Initialize ESenseManager eSenseManager = ESenseManager('eSense-0332'); // 2. Listen to connection status BEFORE connecting eSenseManager.connectionEvents.listen((event) { print('CONNECTION event: $event'); }); // 3. Initiate connection bool connecting = await eSenseManager.connect();How mobility features are derived
masterThe plugin uses a hierarchical model to derive features from raw GPS data:
- Stop: A collection of GPS points representing a visit to a location for an extended period. Defined by a centroid, an arrival timestamp, and a departure timestamp.
- Place: A cluster of Stops (using the DBSCAN algorithm). A place represents a location visited multiple times.
- Move: The path of GPS points between two stops. The distance is calculated using the haversine formula.
Derived Metrics:
- Home Stay: The percentage of time elapsed since midnight spent at the user's home location.
- Entropy/Normalized Entropy: Measures the predictability/regularity of time spent at different places.
- Distance Traveled: The sum of all move distances in meters.
Configure iOS permissions and platform version
masterThe plugin requires iOS 10 or later. Ensure your
ios/Podfileis set to:platform :ios, '10.0'Add the following keys to your
ios/Runner/Info.plistto allow Bluetooth usage and background modes:<key>NSBluetoothAlwaysUsageDescription</key> <string>Uses bluetooth to connect to the eSense device</string> <key>UIBackgroundModes</key> <array> <string>bluetooth-central</string> <string>bluetooth-peripheral</string> <string>audio</string> <string>external-accessory</string> <string>fetch</string> </array>Use the app_usage_example project as a starting point
masterTheapp_usage_exampleproject serves as a demonstration application for theapp_usageplugin. It provides a functional Flutter application template to help you understand how to integrate and use theapp_usageplugin in a real-world scenario.Configure permissions for the Pedometer plugin
masterTo use the Pedometer plugin, you must configure platform-specific permissions to access motion and activity data. Note that on some devices, users may still need to manually grant these permissions in the system Settings.
Android
For Android 10 and above, add the following permission to your
AndroidManifest.xml:iOS
Add the following keys to your
Info.plistfile within the Runner Xcode project:<!-- Android: AndroidManifest.xml --> <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" /> <!-- iOS: Info.plist --> <key>NSMotionUsageDescription</key> <string>This application tracks your steps</string> <key>UIBackgroundModes</key> <array> <string>processing</string> </array>Install movesense_plus on Android
master- Download the latest
mdslib-x.x.x-release.aarfrom the movesense-mobile-lib repository. - Place the
.aarfile in your app'sandroid/libsfolder. - Update your
android/build.gradlefile to include thelibsdirectory in your repositories.
For Groovy:
allprojects { repositories { ... flatDir{ dirs "$rootDir/libs" } } }For Kotlin: Use
dirs("$rootDir/libs")within therepositoriesblock.- Download the latest
Install the light plugin
masterAdd
lightas a dependency in yourpubspec.yamlfile to use the plugin for collecting ambient light data on Android and iOS.dependencies: light: ^latest_versionInstall the notifications plugin
masterTo use the
notificationsplugin, add it as a dependency in yourpubspec.yamlfile.Additionally, you must register the notification listener service in your Android configuration. Add the following
<service>block inside the<application>tag of yourandroid/app/src/main/AndroidManifest.xmlfile:<service android:label="notifications" android:name="dk.cachet.notifications.NotificationListener" android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"> <intent-filter> <action android:name="android.service.notification.NotificationListenerService" /> </intent-filter> </service>Configure iOS permissions for noise_meter
masterTo use the noise meter on iOS, follow these three steps:
- Enable Background Modes: In Xcode, go to Capabilities > Background Modes and enable Audio, AirPlay and Picture in Picture.
- Add Microphone Usage Description: In your Runner Xcode project, edit the
Info.plistfile and add an entry forPrivacy - Microphone Usage Description. - Update Podfile: Edit your
Podfileto include the microphone permission in thepost_installblock so the permission handler recognizes it.
post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) target.build_configurations.each do |config| config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [ '$(inherited)', 'PERMISSION_MICROPHONE=1',] end end end