forked from tamberg/fhnw-iot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nRF52840_ScannerBleCentral.ino
40 lines (33 loc) · 1.41 KB
/
nRF52840_ScannerBleCentral.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Scanner BLE central. Copyright (c) Thomas Amberg, FHNW
// Based on https://github.com/adafruit/Adafruit_nRF52_Arduino
// /tree/master/libraries/Bluefruit52Lib/examples/Central
// Copyright (c) Adafruit.com, all rights reserved.
// Licensed under the MIT license, see LICENSE or
// https://choosealicense.com/licenses/mit/
#include <bluefruit.h>
void scanCallback(ble_gap_evt_adv_report_t* report) {
Serial.printBufferReverse(report->peer_addr.addr, 6, ':'); // MAC address is little endian
Serial.print(", RSSI = ");
Serial.print(report->rssi);
Serial.print(", data = ");
Serial.printBuffer(report->data.p_data, report->data.len, '-');
// See https://www.bluetooth.com/specifications/gatt/services
BLEUuid hrmServiceUuid = BLEUuid(UUID16_SVC_HEART_RATE); // 0x180D
if (Bluefruit.Scanner.checkReportForUuid(report, hrmServiceUuid)) {
Serial.print(", Heart Rate Monitor");
}
Serial.println();
Bluefruit.Scanner.resume(); // required for Softdevice v6
}
void setup() {
Serial.begin(115200);
while (!Serial) { delay(10); } // only if usb connected
Bluefruit.begin(0, 1); // 0 peripheral, max 1 central connection, save SoftDevice SRAM
Bluefruit.setTxPower(4); // -40, -30, -20, -16, -12, -8, -4, 0, 4
Bluefruit.setName("nRF52840");
Bluefruit.setConnLedInterval(250);
Bluefruit.Scanner.setRxCallback(scanCallback);
Bluefruit.Scanner.start(0);
Serial.println("Scanning ...");
}
void loop() {}