Skip to content
CARP Docs
Ask AISystemLightDark
On this page

Connectivity Sampling Package

Collect network status, Wi-Fi, nearby Bluetooth devices and iBeacons from the phone in a CARP Mobile Sensing study.

Copy MarkdownOpen inOpen in GitHubView as MarkdownOpen in Scira AIOpen in ChatGPTOpen in ClaudeOpen in Cursor

carp_connectivity_package adds four phone measures to a CARP Mobile Sensing (CAMS) study. They record the networks the phone uses, the Wi-Fi network it is connected to, and the Bluetooth Low Energy (BLE) devices and iBeacons around it. Use them when a study needs the network context of a participant's phone, or the devices and places around it.

The package builds on four Flutter plugins: connectivity_plus for the network status, network_info_plus for the Wi-Fi network, flutter_blue_plus for Bluetooth scans and dchs_flutter_beacon for iBeacons.

pub.devAPI referenceGitHub

Bluetooth plugin license

An app resolves flutter_blue_plus 2.x unless another dependency pins 1.x. Version 2.x is under the FlutterBluePlus License, which is free for nonprofits and educational institutions but paid for commercial use. To stay on the BSD-licensed 1.x, see Installation.

Features

Connectivity status

Records the network types the phone uses, such as Wi-Fi or mobile data, every time they change.

Wi-Fi

Reads the name, access point and IP address of the connected Wi-Fi network at a fixed interval. The default privacy schema hashes the network name.

Bluetooth

Scans for nearby BLE devices in short windows and lists each device with its signal strength. The default privacy schema hashes the device names.

Beacons

Detects iBeacons in the regions you configure and estimates their distance from the phone.

Measure types

The package has four event-based measure types, all collected on the phone:

Measure typeDataAndroidiOS
dk.cachet.carp.connectivityNetwork types in use, such as wifi or mobileYesYes
dk.cachet.carp.wifiName, access point and IP address of the connected Wi-Fi networkYesYes
dk.cachet.carp.bluetoothBLE devices found in a scan windowYesForeground only
dk.cachet.carp.beaconiBeacons in a configured regionYesYes

For the measure types of the other sampling packages, see Measure types.

Requirements

ComponentRequirement
Dart SDK3.10 or later
Flutter3.38.1 or later
carp_mobile_sensing2.3.0 or later
AndroidAPI level 24 (Android 7.0) or later, the CAMS minimum
iOS15.0 or later, the CAMS minimum
Android buildAndroid Gradle Plugin 8.12.1 or later, Gradle 8.13 or later, Java 17 and Kotlin 2.2.0, as connectivity_plus and network_info_plus require
Xcode26.1.1 or later, as connectivity_plus requires
TestingA physical phone. The iOS simulator returns no Wi-Fi information and has no Bluetooth.

How it works

Adding the package to a study takes three steps:

  1. Register the package

    Registering a ConnectivitySamplingPackage in the SamplingPackageRegistry makes the four measure types and their data and configuration classes known to CAMS. It also adds the Wi-Fi and Bluetooth name hashing to the default privacy schema.

  2. Add the measures to a protocol

    The measures run on the phone. Start them with an ImmediateTrigger, and they run until the study pauses. Wi-Fi and Bluetooth sample at their own interval, and beacons need the regions to monitor.

  3. Deploy the protocol

    CAMS asks for the Bluetooth and location permissions that the measures declare, then starts them. Wi-Fi also needs location access, which CAMS does not ask for. To ask for it in the app, see Location permission.

This example registers the package and collects the connectivity status and nearby Bluetooth devices:

import 'package:carp_core/carp_core.dart' hide Smartphone;
import 'package:carp_mobile_sensing/carp_mobile_sensing.dart';
import 'package:carp_connectivity_package/connectivity.dart';

void main() {
  CarpMobileSensing.ensureInitialized();
  SamplingPackageRegistry().register(ConnectivitySamplingPackage());

  final phone = Smartphone();
  final protocol = SmartphoneStudyProtocol(
    ownerId: 'owner@example.com',
    name: 'Phone connectivity',
    dataEndPoint: SQLiteDataEndPoint(),
  )..addPrimaryDevice(phone);

  // Event-based measures run from the time the study starts
  protocol.addTaskControl(
    ImmediateTrigger(),
    BackgroundTask(
      measures: [
        Measure(type: ConnectivitySamplingPackage.CONNECTIVITY),
        Measure(type: ConnectivitySamplingPackage.BLUETOOTH),
      ],
    ),
    phone,
  );

  // ... deploy the protocol and start sampling
}

Next steps

Installation

Add the package and the permissions that each measure needs.

Quickstart

Build an app that collects all four measures and prints them.

Bluetooth scanning

Nearby Bluetooth Low Energy devices found in periodic scan windows.

Beacons

iBeacons in configured regions, with their estimated distance.

Quick links

Page · DocumentationCARP DocumentationPage · DocumentationIntroductionPage · DocumentationQuickstartPage · DocumentationTerminologyPage · DocumentationArchitecture