CARP Flutter Plugins

repository·master·Indexed 20 days ago

https://github.com/carp-dk/flutter-plugins

A 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.

Tokens
26.9K
Snippets
90
Records
117
Agent score
69%

What's inside carp-dk-flutter-plugins

  1. Overview of CARP Flutter plugins

    master
    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.
  2. How Empatica device management and streams work

    master

    The 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 statusEventSink and dataEventSink before initiating connection or scanning to ensure you don't miss events.

  3. How Movisens device hierarchy works

    master

    The plugin follows a hierarchical Bluetooth GATT structure:

    1. MovisensDevice: The top-level object representing the sensor.
    2. MovisensService: A collection of related data categories (e.g., ambientService, hrvService) belonging to the device.
    3. MovisensBluetoothCharacteristic: The individual data types within a service. These are either:
      • Streams: Continuous data like SensorTemperatureEvents.
      • Read/Write: Discrete actions like setDeleteData().
  4. How ESenseManager and Streams work together

    master

    The esense_flutter plugin uses a reactive programming model based on Dart Streams. Instead of traditional listeners, you interact with the ESenseManager by listening to specific streams for different types of data:

    1. connectionEvents: Provides ConnectionEvent updates. You should start listening to this stream before calling connect() to ensure you capture the connection status.
    2. sensorEvents: Provides a stream of SensorEvent data. You can control the sampling rate using setSamplingRate() when not actively listening.
    3. eSenseEvents: Used for asynchronous property reading. When you call a method like getDeviceName(), the result is emitted as an ESenseEvent through 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();
  5. How mobility features are derived

    master

    The plugin uses a hierarchical model to derive features from raw GPS data:

    1. 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.
    2. Place: A cluster of Stops (using the DBSCAN algorithm). A place represents a location visited multiple times.
    3. 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.
  6. Configure iOS permissions and platform version

    master

    The plugin requires iOS 10 or later. Ensure your ios/Podfile is set to:

    platform :ios, '10.0'

    Add the following keys to your ios/Runner/Info.plist to 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>
  7. Configure permissions for the Pedometer plugin

    master

    To 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.plist file 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>
  8. Install movesense_plus on Android

    master
    1. Download the latest mdslib-x.x.x-release.aar from the movesense-mobile-lib repository.
    2. Place the .aar file in your app's android/libs folder.
    3. Update your android/build.gradle file to include the libs directory in your repositories.

    For Groovy:

    allprojects {
        repositories {
            ...
            flatDir{
                dirs "$rootDir/libs"
            }
        }
    }

    For Kotlin: Use dirs("$rootDir/libs") within the repositories block.

  9. Install the notifications plugin

    master

    To use the notifications plugin, add it as a dependency in your pubspec.yaml file.

    Additionally, you must register the notification listener service in your Android configuration. Add the following <service> block inside the <application> tag of your android/app/src/main/AndroidManifest.xml file:

        <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>
  10. Configure iOS permissions for noise_meter

    master

    To use the noise meter on iOS, follow these three steps:

    1. Enable Background Modes: In Xcode, go to Capabilities > Background Modes and enable Audio, AirPlay and Picture in Picture.
    2. Add Microphone Usage Description: In your Runner Xcode project, edit the Info.plist file and add an entry for Privacy - Microphone Usage Description.
    3. Update Podfile: Edit your Podfile to include the microphone permission in the post_install block 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