Get best RSSI from advertising beacons

Declan gravatar image

asked 2017-12-07 08:25:56 +0100

jornfr gravatar image

updated 2017-12-07 10:22:08 +0100

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");
    }
  }
}
edit retag flag offensive close delete report spam

Comments

If I were you, I would take a look at this devzone case. You can download the latest SDK here. It is possible to use SDK example code on the Arduino Primo, but it might require a bit of debugging and removal of code to get it to work.

Unsure if it is possible to use EEPROM Write, as mentioned here. Might be worth a shot. Also, I believe this Github page provides some examples that might be worthwhile. Let me take a closer look at this tomorrow and get back to you then.

Bjørn Kvaale ( 2017-12-11 16:46:08 +0100 )editconvert to answer