/* bleTempCalibrationScanner for Adafruit Bluefruit nRF52832 Feather (c)2022 Forward Computing and Control Pty. Ltd. This code is not warranted to be fit for any purpose. You may only use it at your own risk. This code may be freely used for both private and commercial use Provide this copyright is maintained. // based on /********************************************************************* This is an example for our nRF52 based Bluefruit LE modules Pick one up today in the adafruit shop! Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! MIT license, check LICENSE for more information All text above, and the splash screen below must be included in any redistribution *********************************************************************/ #include // install the SafeString library via the Arduino Library manager #include void scan_callback(ble_gap_evt_adv_report_t* report); char DEVICE_NAME[] = "T_0,"; unsigned long lastSeen = -(100l * 1000); // when was the device last seen, initally a long time ago so first scan will be printed // note -ve longs => large unsigned numbers, -1 => maxUnsigned, -2 => maxUnsigned -1 etc //so 0ul - lastSeen(as set above) = 100ul * 1000; const unsigned long SKIP_TIME_MS = 11ul * 1000; // skip adverts for 11sec after first one seen void setup() { Serial.begin(115200); while ( !Serial ) delay(10); // for nrf52840 with native usb SafeString::setOutput(Serial); Serial.println("bleTempCalibrationScanner for calibrating uC temperature sensor"); Serial.println("------------------------------------\n"); // Initialize Bluefruit with maximum connections as Peripheral = 0, Central = 1 // SRAM usage required by SoftDevice will increase dramatically with number of connections Bluefruit.begin(0, 1); Bluefruit.setTxPower(4); // Check bluefruit.h for supported values /* Set the device name */ Bluefruit.setName("Bluefruit52"); /* Set the LED interval for blinky pattern on BLUE LED */ Bluefruit.setConnLedInterval(250); /* Start Central Scanning - Enable auto scan if disconnected - Filter out packet with a min rssi - Interval = 100 ms, window = 50 ms - Use active scan (used to retrieve the optional scan response adv packet) - Start(0) = will scan forever since no timeout is given */ Bluefruit.Scanner.setRxCallback(scan_callback); Bluefruit.Scanner.restartOnDisconnect(true); Bluefruit.Scanner.filterRssi(-80); Bluefruit.Scanner.setInterval(160, 80); // in units of 0.625 ms Bluefruit.Scanner.useActiveScan(false); // Don't Request scan response data Bluefruit.Scanner.start(0); // 0 = Don't stop scanning after n seconds Serial.print("Scanning for "); Serial.println(DEVICE_NAME); } /** Callback invoked when scanner pick up an advertising data @param report Structural advertising data */ void scan_callback(ble_gap_evt_adv_report_t* report) { char nameBuffer[32 + 1]; // for trailing null memset(nameBuffer, 0, sizeof(nameBuffer)); // terminate buffer cSFA(sfName, nameBuffer); // wrap buffer in SF if (Bluefruit.Scanner.parseReportByType(report, BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME, (uint8_t*)nameBuffer, sizeof(nameBuffer))) { /* Complete Local Name */ } else if (Bluefruit.Scanner.parseReportByType(report, BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME, (uint8_t*)nameBuffer, sizeof(nameBuffer))) { /* Shortened Local Name */ } else { Serial.println("Error: Invalid -- No Scan Name in Advert Packet"); } sfName.trim(); if (sfName.startsWith(DEVICE_NAME)) { unsigned long ms = millis(); if ((ms - lastSeen) > SKIP_TIME_MS) { // new temp print name to Serial for log file Serial.println(sfName); } lastSeen = ms; } // For Softdevice v6: after received a report, scanner will be paused // We need to call Scanner resume() to continue scanning Bluefruit.Scanner.resume(); } void loop() { // nothing to do }