Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8224b91
added feature for background monitoring beacons
YarnoVdW Jun 24, 2025
2768a7d
some refactoring
YarnoVdW Jun 25, 2025
f8e8494
cleanup
YarnoVdW Jun 25, 2025
d250aa7
added log
YarnoVdW Jun 25, 2025
ac5dd0c
added some more logging
YarnoVdW Jun 25, 2025
cee474b
added logging
YarnoVdW Jun 25, 2025
c0d8fdd
trying some things
YarnoVdW Jun 25, 2025
72e34e5
uncommenting stop monitoring
YarnoVdW Jun 25, 2025
33d40a9
edited log
YarnoVdW Jun 25, 2025
ebfdfd4
updated log
YarnoVdW Jun 26, 2025
9b5bc37
added some comments
YarnoVdW Jun 26, 2025
68a767f
removed commented code in pubspec
YarnoVdW Jun 26, 2025
d953302
small fix
YarnoVdW Jun 26, 2025
0105083
small cleanup
YarnoVdW Jun 26, 2025
42cd992
added scan distance
YarnoVdW Jun 27, 2025
471f35f
Merge pull request #503 from YarnoVdW/main
bardram Jul 17, 2025
e89dd39
Update connectivity.g.dart
bardram Jul 17, 2025
d6f18be
Updated beacon to be its own sampling method
YarnoVdW Jul 23, 2025
bc7dcff
updated some code, implemented a buffer
YarnoVdW Jul 23, 2025
4069973
ran build runner to fix issue in g file
YarnoVdW Jul 23, 2025
28831df
updated the buffer method, as it was not working like supposed to
YarnoVdW Jul 23, 2025
6ac63b7
trying out stream Probe
YarnoVdW Jul 23, 2025
049c43b
init data
YarnoVdW Jul 23, 2025
44e430f
Merge branch 'pr503-beacon-scan' into main
bardram Jul 25, 2025
983bd72
Merge pull request #505 from YarnoVdW/main
bardram Jul 25, 2025
647767b
Update connectivity.g.dart
bardram Jul 25, 2025
d50d5fc
major refactor of data model and probe for iBeacon scanning
bardram Jul 25, 2025
d871dea
Update of unit test to include beacon measure in test protocol
bardram Jul 25, 2025
55d87e0
Merge branch 'cph-cachet:main' into main
YarnoVdW Jul 25, 2025
fd4956f
Merge pull request #1 from cph-cachet/pr503-beacon-scan
YarnoVdW Aug 1, 2025
9b2f561
updated the stream probe
YarnoVdW Aug 1, 2025
05b34e8
Merge pull request #509 from YarnoVdW/main
bardram Aug 7, 2025
d2fe959
Added a BeaconData.fromRegionAndBeacons constructor to pretty syntax
bardram Aug 7, 2025
37df2e8
update of example and docs
bardram Aug 7, 2025
b703ed5
Merge pull request #2 from cph-cachet/pr503-beacon-scan
YarnoVdW Aug 14, 2025
be62b49
added smll test
YarnoVdW Aug 14, 2025
b7cb457
Merge pull request #510 from YarnoVdW/main
bardram Sep 5, 2025
acba94d
update to linter stuff
bardram Sep 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions carp_mobile_sensing/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
include: package:flutter_lints/flutter.yaml

analyzer:
errors:
deprecated_member_use_from_same_package: ignore
exclude: [build/**]
language:
strict-casts: true
Expand All @@ -17,3 +19,5 @@ linter:
depend_on_referenced_packages: true
avoid_print: false
use_string_in_part_of_directives: true
deprecated_member_use_from_same_package: false

2 changes: 2 additions & 0 deletions carp_mobile_sensing/example/lib/example.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: unused_local_variable

/*
* Copyright 2018-2024 the Technical University of Denmark (DTU).
* Use of this source code is governed by a MIT-style license that can be
Expand Down
5 changes: 5 additions & 0 deletions packages/carp_connectivity_package/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.9.0

* added support for scanning iBeacons using the [dchs_flutter_beacon](https://pub.dev/packages/dchs_flutter_beacon) plugin
* use the `BEACON` measure type for collecting `BeaconData` within a set of specific regions as specified in a `BeaconRangingPeriodicSamplingConfiguration`

## 1.8.1+1

* added `BluetoothScanPeriodicSamplingConfiguration`
Expand Down
64 changes: 57 additions & 7 deletions packages/carp_connectivity_package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This packages supports sampling of the following [`Measure`](https://github.com/
* `dk.cachet.carp.wifi`
* `dk.cachet.carp.connectivity`
* `dk.cachet.carp.bluetooth`
* `dk.cachet.carp.beacon`

See the [wiki](https://github.com/cph-cachet/carp.sensing-flutter/wiki) for further documentation, particularly on available [measure types](https://github.com/cph-cachet/carp.sensing-flutter/wiki/A.-Measure-Types).
See the [CARP Mobile Sensing App](https://github.com/cph-cachet/carp.sensing-flutter/tree/master/apps/carp_mobile_sensing_app) for an example of how to build a mobile sensing app in Flutter.
Expand Down Expand Up @@ -55,7 +56,7 @@ Add the following to your app's `AndroidManifest.xml` file located in `android/a
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
</manifest>
````

Expand All @@ -70,8 +71,10 @@ and here for the [iOS](https://developer.apple.com/documentation/systemconfigura
To enable bluetooth tracking, add these permissions in the `Info.plist` file located in `ios/Runner`:

````xml
<!-- Bluetooth Privacy -->
<!-- for iOS 13 + -->
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Bluetooth needed</string>
<string>Reason why app needs bluetooth</string>
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
Expand All @@ -81,7 +84,23 @@ To enable bluetooth tracking, add these permissions in the `Info.plist` file loc
</array>
````

> Note that on iOS, it is [impossible to do a general Bluetooth scan when the screen is off or the app is in background](https://developer.apple.com/forums/thread/652592). This will simply result in an empty scan. Hence, bluetooth devices are only collected when the app is in the foreground.
> [!NOTE]
> On iOS, it is [impossible to do a general Bluetooth scan when the screen is off or the app is in background](https://developer.apple.com/forums/thread/652592). This will simply result in an empty scan. Hence, bluetooth devices are only collected when the app is in the foreground.

To collect iBeacon measurements, please follow the setup described in the [dchs_flutter_beacon](https://pub.dev/packages/dchs_flutter_beacon) plugin. Especially, for iOS you need permissions to access location information in the `Info.plist` file:

````xml
<!-- When in use -->
<key>NSLocationWhenInUseUsageDescription</key>
<string>Reason why app needs location</string>
<!-- Always -->
<!-- for iOS 11 + -->
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Reason why app needs location</string>
<!-- for iOS 9/10 -->
<key>NSLocationAlwaysUsageDescription</key>
<string>Reason why app needs location</string>
````

## Using it

Expand Down Expand Up @@ -116,13 +135,13 @@ Smartphone phone = Smartphone();
protocol.addPrimaryDevice(phone);

// Add an automatic task that immediately starts collecting connectivity,
// nearby bluetooth devices, and wifi information.
// wifi information, and nearby bluetooth devices.
protocol.addTaskControl(
ImmediateTrigger(),
BackgroundTask(measures: [
Measure(type: ConnectivitySamplingPackage.CONNECTIVITY),
Measure(type: ConnectivitySamplingPackage.BLUETOOTH),
Measure(type: ConnectivitySamplingPackage.WIFI),
Measure(type: ConnectivitySamplingPackage.BLUETOOTH),
]),
phone);
```
Expand All @@ -136,11 +155,42 @@ protocol.addTaskControl(
Measure(
type: ConnectivitySamplingPackage.BLUETOOTH,
samplingConfiguration: BluetoothScanPeriodicSamplingConfiguration(
interval: const Duration(minutes: 10),
duration: const Duration(seconds: 10),
interval: const Duration(minutes: 20),
duration: const Duration(seconds: 15),
withRemoteIds: ['123', '456'],
withServices: ['service1', 'service2'],
))
]),
phone);
```

The default configuration scans every 10 minutes for 10 seconds, and does not specify any remote IDs or services.

If you want to collect iBeacon measurements, you need to configure the scanning by setting a [`BeaconRangingPeriodicSamplingConfiguration`](https://pub.dev/documentation/carp_connectivity_package/latest/connectivity/BeaconRangingPeriodicSamplingConfiguration-class.html).
The following example will scan for iBeacons in the specified regions which are closer than 2 meters. The regions are specified by their identifier and UUID. See the [dchs_flutter_beacon](https://pub.dev/packages/dchs_flutter_beacon) plugin for more information on how to set up iBeacon regions.

> [!NOTE]
> There is no default sampling configuration for iBeacons. You need to specify at least one region to scan for.

```dart
protocol.addTaskControl(
ImmediateTrigger(),
BackgroundTask(measures: [
Measure(
type: ConnectivitySamplingPackage.BEACON,
samplingConfiguration: BeaconRangingPeriodicSamplingConfiguration(
beaconDistance: 2,
beaconRegions: [
BeaconRegion(
identifier: 'region1',
uuid: '12345678-1234-1234-1234-123456789012',
),
BeaconRegion(
identifier: 'region2',
uuid: '12345678-1234-1234-1234-123456789012',
),
],
))
]),
phone);
```
52 changes: 50 additions & 2 deletions packages/carp_connectivity_package/example/lib/example.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: unused_local_variable

import 'package:carp_core/carp_core.dart';
import 'package:carp_mobile_sensing/carp_mobile_sensing.dart';
import 'package:carp_connectivity_package/connectivity.dart';
Expand All @@ -22,13 +24,59 @@ void main() async {
protocol.addPrimaryDevice(phone);

// Add an automatic task that immediately starts collecting connectivity,
// nearby bluetooth devices, and wifi information.
// wifi information, and nearby bluetooth devices.
protocol.addTaskControl(
ImmediateTrigger(),
BackgroundTask(measures: [
Measure(type: ConnectivitySamplingPackage.CONNECTIVITY),
Measure(type: ConnectivitySamplingPackage.BLUETOOTH),
Measure(type: ConnectivitySamplingPackage.WIFI),
Measure(type: ConnectivitySamplingPackage.BLUETOOTH),
]),
phone);

// If you want to scan for nearby bluetooth devices, you can use a
// [BluetoothScanPeriodicSamplingConfiguration] to configure the scan.
// This will scan for bluetooth devices every 10 minutes for 10 seconds.
// You can also filter by remoteIds and services.
protocol.addTaskControl(
ImmediateTrigger(),
BackgroundTask(measures: [
Measure(
type: ConnectivitySamplingPackage.BLUETOOTH,
samplingConfiguration: BluetoothScanPeriodicSamplingConfiguration(
interval: const Duration(minutes: 20),
duration: const Duration(seconds: 15),
withRemoteIds: ['123', '456'],
withServices: ['service1', 'service2'],
))
]),
phone);

// If you want to collect iBeacon measurements, you can use a
// [BeaconRangingPeriodicSamplingConfiguration] to configure the scan.
// This will scan for iBeacons in the specified regions which are closer than
// 2 meters. The regions are specified by their identifier and UUID.
//
// See the dchs_flutter_beacon plugin for more information on how to set up
// iBeacon regions.
protocol.addTaskControl(
ImmediateTrigger(),
BackgroundTask(measures: [
Measure(
type: ConnectivitySamplingPackage.BEACON,
samplingConfiguration: BeaconRangingPeriodicSamplingConfiguration(
beaconDistance: 2,
beaconRegions: [
BeaconRegion(
identifier: 'region1',
uuid: '12345678-1234-1234-1234-123456789012',
),
BeaconRegion(
identifier: 'region2',
uuid: '12345678-1234-1234-1234-123456789012',
),
],
))
]),
phone);
}
1 change: 1 addition & 0 deletions packages/carp_connectivity_package/lib/connectivity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ library;
import 'dart:async';
import 'dart:convert';

import 'package:dchs_flutter_beacon/dchs_flutter_beacon.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:connectivity_plus/connectivity_plus.dart' as connectivity;
Expand Down
76 changes: 76 additions & 0 deletions packages/carp_connectivity_package/lib/connectivity.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading