Enable calibrating internal iBeacon ref rssi (#767)

This commit is contained in:
Darrell 2022-12-27 18:05:56 -05:00 committed by GitHub
parent 6cab63fee8
commit e9b13889b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 33 deletions

View File

@ -71,7 +71,7 @@ int BleFingerprint::get1mRssi() const
if (calRssi != NO_RSSI) return calRssi;
if (mdRssi != NO_RSSI) return mdRssi;
if (asRssi != NO_RSSI) return asRssi;
return BleFingerprintCollection::refRssi + DEFAULT_TX;
return BleFingerprintCollection::rxRefRssi + DEFAULT_TX;
}
BleFingerprint::BleFingerprint(BLEAdvertisedDevice *advertisedDevice, float fcmin, float beta, float dcutoff) : oneEuro{OneEuroFilter<float, unsigned long>(1, fcmin, beta, dcutoff)}
@ -202,7 +202,7 @@ void BleFingerprint::fingerprintServiceAdvertisements(NimBLEAdvertisedDevice *ad
#endif
if (uuid == roomAssistantService)
{
asRssi = BleFingerprintCollection::refRssi + RM_ASST_TX;
asRssi = BleFingerprintCollection::rxRefRssi + RM_ASST_TX;
if (!rmAsst)
{
rmAsst = true;
@ -217,56 +217,56 @@ void BleFingerprint::fingerprintServiceAdvertisements(NimBLEAdvertisedDevice *ad
}
else if (uuid == tileUUID)
{
asRssi = BleFingerprintCollection::refRssi + TILE_TX;
asRssi = BleFingerprintCollection::rxRefRssi + TILE_TX;
setId("tile:" + getMac(), ID_TYPE_TILE);
return;
}
else if (uuid == sonosUUID)
{
asRssi = haveTxPower ? BleFingerprintCollection::refRssi + txPower : NO_RSSI;
asRssi = haveTxPower ? BleFingerprintCollection::rxRefRssi + txPower : NO_RSSI;
setId("sonos:" + getMac(), ID_TYPE_SONOS);
return;
}
else if (uuid == itagUUID)
{
asRssi = BleFingerprintCollection::refRssi + (haveTxPower ? txPower : ITAG_TX);
asRssi = BleFingerprintCollection::rxRefRssi + (haveTxPower ? txPower : ITAG_TX);
setId("itag:" + getMac(), ID_TYPE_ITAG);
return;
}
else if (uuid == trackrUUID)
{
asRssi = haveTxPower ? BleFingerprintCollection::refRssi + txPower : NO_RSSI;
asRssi = haveTxPower ? BleFingerprintCollection::rxRefRssi + txPower : NO_RSSI;
setId("trackr:" + getMac(), ID_TYPE_TRACKR);
return;
}
else if (uuid == tractiveUUID)
{
asRssi = haveTxPower ? BleFingerprintCollection::refRssi + txPower : NO_RSSI;
asRssi = haveTxPower ? BleFingerprintCollection::rxRefRssi + txPower : NO_RSSI;
setId("tractive:" + getMac(), ID_TYPE_TRACTIVE);
return;
}
else if (uuid == vanmoofUUID)
{
asRssi = haveTxPower ? BleFingerprintCollection::refRssi + txPower : NO_RSSI;
asRssi = haveTxPower ? BleFingerprintCollection::rxRefRssi + txPower : NO_RSSI;
setId("vanmoof:" + getMac(), ID_TYPE_VANMOOF);
return;
}
else if (uuid == (meaterService))
{
asRssi = haveTxPower ? BleFingerprintCollection::refRssi + txPower : NO_RSSI;
asRssi = haveTxPower ? BleFingerprintCollection::rxRefRssi + txPower : NO_RSSI;
setId("meater:" + getMac(), ID_TYPE_MEATER);
return;
}
else if (uuid == nutUUID)
{
asRssi = BleFingerprintCollection::refRssi + (haveTxPower ? txPower : NUT_TX);
asRssi = BleFingerprintCollection::rxRefRssi + (haveTxPower ? txPower : NUT_TX);
setId("nut:" + getMac(), ID_TYPE_NUT);
return;
}
}
String fingerprint = "ad:";
asRssi = haveTxPower ? BleFingerprintCollection::refRssi + txPower : NO_RSSI;
asRssi = haveTxPower ? BleFingerprintCollection::rxRefRssi + txPower : NO_RSSI;
for (int i = 0; i < serviceAdvCount; i++)
{
std::string sid = advertisedDevice->getServiceUUID(i).toString();
@ -278,7 +278,7 @@ void BleFingerprint::fingerprintServiceAdvertisements(NimBLEAdvertisedDevice *ad
void BleFingerprint::fingerprintServiceData(NimBLEAdvertisedDevice *advertisedDevice, size_t serviceDataCount, bool haveTxPower, int8_t txPower)
{
asRssi = haveTxPower ? BleFingerprintCollection::refRssi + txPower : NO_RSSI;
asRssi = haveTxPower ? BleFingerprintCollection::rxRefRssi + txPower : NO_RSSI;
String fingerprint = "";
for (int i = 0; i < serviceDataCount; i++)
{
@ -290,18 +290,18 @@ void BleFingerprint::fingerprintServiceData(NimBLEAdvertisedDevice *advertisedDe
if (uuid == exposureUUID)
{ // found COVID-19 exposure tracker
calRssi = BleFingerprintCollection::refRssi + EXPOSURE_TX;
calRssi = BleFingerprintCollection::rxRefRssi + EXPOSURE_TX;
setId("exp:" + String(strServiceData.length()), ID_TYPE_EXPOSURE);
//disc = hexStr(strServiceData).c_str();
}
else if (uuid == smartTagUUID)
{ // found Samsung smart tag
asRssi = haveTxPower ? BleFingerprintCollection::refRssi + txPower : NO_RSSI;
asRssi = haveTxPower ? BleFingerprintCollection::rxRefRssi + txPower : NO_RSSI;
setId("smarttag:" + String(strServiceData.length()), ID_TYPE_SMARTTAG);
}
else if (uuid == miThermUUID)
{
asRssi = haveTxPower ? BleFingerprintCollection::refRssi + txPower : NO_RSSI;
asRssi = haveTxPower ? BleFingerprintCollection::rxRefRssi + txPower : NO_RSSI;
if (strServiceData.length() == 15)
{ // custom format
auto serviceData = strServiceData.c_str();
@ -397,45 +397,45 @@ void BleFingerprint::fingerprintManufactureData(NimBLEAdvertisedDevice *advertis
if (haveTxPower) pid += -txPower;
setId(pid, ID_TYPE_APPLE_NEARBY);
disc = hexStr(strManufacturerData.substr(4)).c_str();
mdRssi = BleFingerprintCollection::refRssi + APPLE_TX;
mdRssi = BleFingerprintCollection::rxRefRssi + APPLE_TX;
}
else if (strManufacturerData.length() >= 4 && strManufacturerData[2] == 0x12 && strManufacturerData.length() == 29)
{
String pid = "apple:findmy";
setId(pid, ID_TYPE_FINDMY);
mdRssi = BleFingerprintCollection::refRssi + APPLE_TX;
mdRssi = BleFingerprintCollection::rxRefRssi + APPLE_TX;
}
else if (strManufacturerData.length() >= 4)
{
String pid = Sprintf("apple:%02x%02x:%u", strManufacturerData[2], strManufacturerData[3], strManufacturerData.length());
if (haveTxPower) pid += -txPower;
setId(pid, ID_TYPE_MISC_APPLE);
mdRssi = BleFingerprintCollection::refRssi + APPLE_TX;
mdRssi = BleFingerprintCollection::rxRefRssi + APPLE_TX;
}
}
else if (manuf == "05a7") // Sonos
{
mdRssi = haveTxPower ? BleFingerprintCollection::refRssi + txPower : NO_RSSI;
mdRssi = haveTxPower ? BleFingerprintCollection::rxRefRssi + txPower : NO_RSSI;
setId("sonos:" + getMac(), ID_TYPE_SONOS);
}
else if (manuf == "0087") // Garmin
{
mdRssi = haveTxPower ? BleFingerprintCollection::refRssi + txPower : NO_RSSI;
mdRssi = haveTxPower ? BleFingerprintCollection::rxRefRssi + txPower : NO_RSSI;
setId("garmin:" + getMac(), ID_TYPE_GARMIN);
}
else if (manuf == "4d4b") // iTrack
{
mdRssi = haveTxPower ? BleFingerprintCollection::refRssi + txPower : NO_RSSI;
mdRssi = haveTxPower ? BleFingerprintCollection::rxRefRssi + txPower : NO_RSSI;
setId("iTrack:" + getMac(), ID_TYPE_ITRACK);
}
else if (manuf == "0157") // Mi-fit
{
mdRssi = haveTxPower ? BleFingerprintCollection::refRssi + txPower : NO_RSSI;
mdRssi = haveTxPower ? BleFingerprintCollection::rxRefRssi + txPower : NO_RSSI;
setId("mifit:" + getMac(), ID_TYPE_MIFIT);
}
else if (manuf == "0006" && strManufacturerData.length() == 29) // microsoft
{
mdRssi = haveTxPower ? BleFingerprintCollection::refRssi + txPower : NO_RSSI;
mdRssi = haveTxPower ? BleFingerprintCollection::rxRefRssi + txPower : NO_RSSI;
setId(Sprintf("msft:cdp:%02x%02x", strManufacturerData[3], strManufacturerData[5]), ID_TYPE_MSFT);
/*disc = Sprintf("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
strManufacturerData[6], strManufacturerData[7], strManufacturerData[8], strManufacturerData[9], strManufacturerData[10],
@ -446,7 +446,7 @@ void BleFingerprint::fingerprintManufactureData(NimBLEAdvertisedDevice *advertis
}
else if (manuf == "0075") // samsung
{
mdRssi = haveTxPower ? BleFingerprintCollection::refRssi + txPower : NO_RSSI;
mdRssi = haveTxPower ? BleFingerprintCollection::rxRefRssi + txPower : NO_RSSI;
setId("samsung:" + getMac(), ID_TYPE_MISC);
}
else if (manuf == "beac" && strManufacturerData.length() == 26)
@ -458,7 +458,7 @@ void BleFingerprint::fingerprintManufactureData(NimBLEAdvertisedDevice *advertis
}
else if (manuf != "0000")
{
mdRssi = haveTxPower ? BleFingerprintCollection::refRssi + txPower : NO_RSSI;
mdRssi = haveTxPower ? BleFingerprintCollection::rxRefRssi + txPower : NO_RSSI;
String fingerprint = Sprintf("md:%s:%u", manuf.c_str(), strManufacturerData.length());
if (haveTxPower) fingerprint = fingerprint + String(-txPower);
setId(fingerprint, ID_TYPE_MD);

View File

@ -7,7 +7,7 @@ namespace BleFingerprintCollection {
// Public (externed)
String include{}, exclude{}, query{}, knownMacs{}, knownIrks{}, countIds{};
float skipDistance = 0.0f, maxDistance = 0.0f, absorption = 3.5f, countEnter = 2, countExit = 4;
int8_t refRssi = -65;
int8_t rxRefRssi = -65, txRefRssi = -59;
int forgetMs = 0, skipMs = 0, countMs = 10000;
std::vector<DeviceConfig> deviceConfigs;
std::vector<uint8_t *> irks;

View File

@ -46,10 +46,9 @@ extern TCallbackFingerprint onCountDel;
extern String include, exclude, query, knownMacs, knownIrks, countIds;
extern float skipDistance, maxDistance, absorption, countEnter, countExit;
extern int8_t refRssi;
extern int8_t rxRefRssi, txRefRssi;
extern int forgetMs, skipMs, countMs;
extern std::vector<DeviceConfig> deviceConfigs;
extern std::vector<uint8_t *> irks;
extern std::vector<BleFingerprint *> fingerprints;
} // namespace BleFingerprintCollection

View File

@ -195,7 +195,7 @@ void Setup() {
oBeacon.setProximityUUID(espresenseUUID);
oBeacon.setMajor(major);
oBeacon.setMinor(minor);
oBeacon.setSignalPower(-59);
oBeacon.setSignalPower(BleFingerprintCollection::txRefRssi);
oAdvertisementData = new NimBLEAdvertisementData();
oAdvertisementData->setFlags(BLE_HS_ADV_F_BREDR_UNSUP);
oAdvertisementData->setManufacturerData(oBeacon.getData());

View File

@ -48,7 +48,8 @@
#define DEFAULT_INCLUDE ""
#define DEFAULT_EXCLUDE ""
#define DEFAULT_REF_RSSI (-65)
#define DEFAULT_RX_REF_RSSI (-65)
#define DEFAULT_TX_REF_RSSI (-59)
#define DEFAULT_ABSORPTION (3.5)
#define DEFAULT_FORGET_MS 150000 // Ms to remove fingerprint after not seeing it

View File

@ -158,9 +158,10 @@ void setupNetwork() {
BleFingerprintCollection::skipMs = AsyncWiFiSettings.integer("skip_ms", 0, 3000000, DEFAULT_SKIP_MS, "Skip reporting if message age is less that this (in milliseconds)");
AsyncWiFiSettings.heading("Calibration <a href='https://espresense.com/configuration/settings#calibration' target='_blank'></a>", false);
BleFingerprintCollection::refRssi = AsyncWiFiSettings.integer("ref_rssi", -100, 100, DEFAULT_REF_RSSI, "Rssi expected from a 0dBm transmitter at 1 meter (NOT used for iBeacons or Eddystone)");
BleFingerprintCollection::rxRefRssi = AsyncWiFiSettings.integer("ref_rssi", -100, 100, DEFAULT_RX_REF_RSSI, "Rssi expected from a 0dBm transmitter at 1 meter (NOT used for iBeacons or Eddystone)");
BleFingerprintCollection::absorption = AsyncWiFiSettings.floating("absorption", -100, 100, DEFAULT_ABSORPTION, "Factor used to account for absorption, reflection, or diffraction");
BleFingerprintCollection::forgetMs = AsyncWiFiSettings.integer("forget_ms", 0, 3000000, DEFAULT_FORGET_MS, "Forget beacon if not seen for (in milliseconds)");
BleFingerprintCollection::txRefRssi = AsyncWiFiSettings.integer("tx_ref_rssi", -100, 100, DEFAULT_TX_REF_RSSI, "Rssi expected from this tx power at 1m (used for node iBeacon)");
GUI::ConnectToWifi();
@ -442,8 +443,6 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
void scanTask(void *parameter) {
NimBLEDevice::init("ESPresense");
for (esp_ble_power_type_t i = ESP_BLE_PWR_TYPE_CONN_HDL0; i <= ESP_BLE_PWR_TYPE_CONN_HDL8; i = esp_ble_power_type_t((int)i + 1))
NimBLEDevice::setPower(ESP_PWR_LVL_P9, i);
Enrollment::Setup();
NimBLEDevice::setMTU(23);