I’m using continuous mode and running scanner.loop regularly…
code sample:
/**
* @brief main setup
*
*/
void setup()
{
Tracker::instance().init();
Tracker::instance().location.regLocGenCallback(locationGenerationCallback);
TrackerLocation::instance().regEnhancedLocCallback(enhancedCb);
memory.begin();
Scanner.setScanPeriod(SCAN_PERIOD);
Scanner.setMissedCount(MAX_MISSED_PERIODS);
Scanner.setCallback(scanCB);
Scanner.startContinuous(SCAN_IBEACON);
publishInterval = PUBLISH_INTERVAL_MS;
}
/**
* @brief main loop
*
*/
void loop()
{
// call tracker loop
Tracker::instance().loop();
Scanner.loop();
if (!publishedTime || millis() - publishedTime > publishInterval) {
publishData();
}
}
callback:
void scanCB(Beacon& beacon, callback_type type) {
// filter unwanted beacon types
if (beacon.type != SCAN_IBEACON) {
return;
}
iBeaconScan ibeacon = (iBeaconScan&)beacon;
int numTag = -1;
bool newTag = false;
for (int i = 0; i < numTags; i++) {
if (tag[i].beacon.getAddress() == ibeacon.getAddress() && !tag[i].doNotTrack) {
numTag = i;
tag[i].power = ibeacon.getPower();
tag[i].rssi = ibeacon.getRssi();
break;
}
}
if (numTag < 0) {
numTag = numTags;
newTag = true;
memcpy((void*)&tag[numTag].beacon, (void*)&ibeacon, sizeof(ibeacon));
tag[numTag].power = ibeacon.getPower();
tag[numTag].rssi = ibeacon.getRssi();
numTags++;
}
Log.info("UUID: %s, Address: %s, major: %u, minor: %u", ibeacon.getUuid(), ibeacon.getAddress().toString().c_str(), ibeacon.getMajor(), ibeacon.getMinor());
if (type == NEW) {
if (strstr(tag[numTag].beacon.getUuid(),"01020304-0506-0708")) {
tag[numTag].seen();
if (tag[numTag].alarm) {
onTagFound(tag[numTag]);
Log.info("Tag found again");
}
if (newTag) {
onNewTag(tag[numTag]);
Log.info("New tag scanned");
}
}
else {
tag[numTag].doNotTrack = true;
}
}
else if (type == REMOVED) {
if (!tag[numTag].doNotTrack) {
// this beacon was not updated -> missing
onMissingTag(tag[numTag]);
}
}
}
Note I do my own handling of which beacons show up and disappear, based on the NEW/REMOVED callback, but that shouldn’t interfere…
that line:
Log.info("UUID: %s, Address: %s, major: %u, minor: %u", ibeacon.getUuid(), ibeacon.getAddress().toString().c_str(), ibeacon.getMajor(), ibeacon.getMinor());
should show me any beacon passed to the callback.
some output:
0000003225 [app.gps.ubx] INFO: enable PUBX-POSITION
0000003232 [app.gps.ubx] INFO: enable PUBX-SVSTATUS
0000003235 [app.gps.ubx] INFO: enable PUBX-TIME
0000003258 [app.gps.ubx] INFO: enable GPS
0000003258 [app.gps.ubx] INFO: enable QZSS
0000003259 [app.gps.ubx] INFO: enable SBAS
0000003259 [app.gps.ubx] INFO: enable Galileo
0000003259 [app.gps.ubx] INFO: enable BeiDou
0000003260 [app.gps.ubx] INFO: enable GLONASS
0000003263 [app.gps.ubx] INFO: set to power management mode 0
0000003266 [app.gps.ubx] INFO: set dynamic platform model to 0
0000010728 [app] INFO: UUID: 50765CB7-D9EA-4E21-99A4-FA879613A492, Address: 10:5B:AD:A5:BF:D2, major: 42462, minor: 38685
0000010732 [app] INFO: UUID: 01020304-0506-0708-090A-0B0C0D0E0F5B, Address: E4:2C:C4:EA:22:C2, major: 523, minor: 266
0000010733 [app] INFO: New tag discovered: 01020304-0506-0708-090A-0B0C0D0E0F5B
0000010734 [app] INFO: New tag scanned
0000010734 [app] INFO: UUID: 01020304-0506-0708-090A-0B0C0D0E0FDC, Address: DC:15:4E:1A:DC:DF, major: 523, minor: 266
0000010735 [app] INFO: New tag discovered: 01020304-0506-0708-090A-0B0C0D0E0FDC
0000010736 [app] INFO: New tag scanned
0000090958 [ncp.client] ERROR: Failed to perform early initialization
0000102924 [net.pppncp] ERROR: Failed to initialize cellular NCP client: -210
0000108236 [mux] INFO: Stopping GSM07.10 muxer
0000108237 [mux] INFO: Gracefully stopping GSM07.10 muxer
0000108237 [mux] INFO: Closing all muxed channels
0000108237 [mux] INFO: Closing mux channel 1
I wonder if the cell module interferes somehow with BLE… read about someone complaining about that in another thread…