Matthew Clisby
Matthew Clisby

Reputation: 43

Trying to access RSSI information on ESP32 for datalogging

As part of a project I'm comparing the effectiveness of different wireless communication methods for measuring distance. I am using RSSI for all forms (I'm aware it's imprecise but the extent of which is the point of the project). I'm planning on comparing Bluetooth Trad, BLE, Wi-Fi and ESP-NOW.

Currently Wi-Fi and ESP-NOW are working and I'm working on Bluetooth trad. I'm able to use the inbuilt examples to find my device and print it to the console. However, how can I access the data stored within BTScanResults.

For example the pseudo would be:

if name == "ESP32test":
    Serial print rssi of name:
delay(1s)

The reason it needs to be in this format is the serial output is being taken directly into Microsoft Excel for data formatting and there will be thousands of data points so manual recording is not feasible.

Thanks for any help, Matt

Console Output

Upvotes: 0

Views: 638

Answers (1)

Christian
Christian

Reputation: 307

I had made a little program to log all Blutooth devices advertised in the vicinity. To find the name and the RSSI I used:

String(advertisedDevice.getName().c_str()); to get the name

and

advertisedDevice.getRSSI(); to get the RSSI.

Below is how it looks in the actual code, with only the essentials left in for brevity. BleLog[] is just a struct array that holds a table of results.

It works in general but for some reason the RSSI is reported most of the time but not always.

class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks
{
    void onResult(BLEAdvertisedDevice advertisedDevice)
    {
      printResult(advertisedDevice);                                
      parseResult(advertisedDevice);                                  
        
        
        .............
    }
};


void parseResult(BLEAdvertisedDevice advertisedDevice)
{
  ......................
  
  // Fill in the data for the log entry
  BleLog[foundAddress].occurences      = oldBleLog[foundAddress].occurences+1;
  BleLog[foundAddress].lastRssi        = advertisedDevice.getRSSI();
  BleLog[foundAddress].lastSeen        = millis();
  BleLog[foundAddress].deviceName      = String(advertisedDevice.getName().c_str());
  BleLog[foundAddress].addressType     = advertisedDevice.getAddressType();
  
  ...................
}

Upvotes: 1

Related Questions