I am using the Arduino Primo board. I have multiple beacons that advertise at a set interval. All beacons have the same Device_name. The Arduino Primo board scans for all beacons that have a set Device_name. If the correct Device_name is found, I read the advertised data and am able to extract the Device_Name, RSSI and MAC address of each beacon. What I now need to achieve is to write the MAC address of the beacon that has the best RSSI to memory. My Code is:
> void receiveAdvPck(BLEPeripheralPeer& peer) {
char advertisedName[31];
byte len;
// search for a device that advertises "ECO" name
peer.getFieldInAdvPck(BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME, advertisedName, len);
if ((len != 0) && (len == 3)) { // the field was found
if (!strcmp(advertisedName, "ECO")) // Name found.
{
Serial.println("Name ECO found");
const char* address = peer.address();
int8_t rssi = peer.rssi();
Serial.println(rssi);
Serial.println(address);
Serial.println("-------------------------------------------------------");
// Now compare current RSSI with previous RSSI
// If current RSSI is better (>) than previous RSSI
// keep current RSSI and MAC current address
// else if previous RSSI is better (>) than current RSSI
// keep previous RSSI and MAC previous MAC address
// When scan complete stop scan (bleCentral.stopScan();)
// Write MAC address to memory.
}
else // Name NOT found.
{
Serial.println("Name ECO not found");
}
}
}