Fix rss@1m when multiple packets received

This commit is contained in:
DTTerastar 2021-09-16 19:36:52 -04:00
parent d723594e73
commit 2b5bd4b1ca
4 changed files with 21 additions and 16 deletions

View File

@ -12,10 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Breaking Change: iBeacon id's were backwards, they are now correct and match HA Companion - Breaking Change: iBeacon id's were backwards, they are now correct and match HA Companion
- Bump NimBLE to 1.3.1 - Bump NimBLE to 1.3.1
- Add support for blinking m5atom led, red=no wifi, blue=no mqtt, blinking white is packet seen - Add support for blinking m5atom led, red=no wifi, blue=no mqtt, blinking white is packet seen
- Fix rssi@1m when multiple packets from same mac
## [1.5.0] ## [1.5.0]
- Nothing changed, changes missed this release - Nothing changed, intended changes are in 1.5.1
## [1.4.4] ## [1.4.4]

View File

@ -10,15 +10,13 @@ BleFingerprint::BleFingerprint(BLEAdvertisedDevice *advertisedDevice, float fcmi
address = advertisedDevice->getAddress(); address = advertisedDevice->getAddress();
newest = recent = oldest = rssi = advertisedDevice->getRSSI(); newest = recent = oldest = rssi = advertisedDevice->getRSSI();
calRssi = advertisedDevice->haveTXPower() ? (-advertisedDevice->getTXPower()) - 41 : 0;
fingerprint(advertisedDevice); fingerprint(advertisedDevice);
if (calRssi > 0) calRssi = defaultTxPower;
} }
void BleFingerprint::fingerprint(BLEAdvertisedDevice *advertisedDevice) void BleFingerprint::fingerprint(BLEAdvertisedDevice *advertisedDevice)
{ {
calcRssi = advertisedDevice->haveTXPower() ? (-advertisedDevice->getTXPower()) - 41 : NO_RSSI;
if (advertisedDevice->haveName()) if (advertisedDevice->haveName())
name = String(advertisedDevice->getName().c_str()); name = String(advertisedDevice->getName().c_str());
@ -45,7 +43,7 @@ void BleFingerprint::fingerprint(BLEAdvertisedDevice *advertisedDevice)
BLEEddystoneURL oBeacon = BLEEddystoneURL(); BLEEddystoneURL oBeacon = BLEEddystoneURL();
oBeacon.setData(strServiceData); oBeacon.setData(strServiceData);
url = String(oBeacon.getDecodedURL().c_str()); url = String(oBeacon.getDecodedURL().c_str());
calRssi = oBeacon.getPower(); calRssi = oBeacon.getPower() - 41;
} }
else if (strServiceData[0] == EDDYSTONE_TLM_FRAME_TYPE) else if (strServiceData[0] == EDDYSTONE_TLM_FRAME_TYPE)
{ {
@ -150,9 +148,8 @@ void BleFingerprint::seen(BLEAdvertisedDevice *advertisedDevice)
rssi = median_of_3(oldest, recent, newest); rssi = median_of_3(oldest, recent, newest);
fingerprint(advertisedDevice); fingerprint(advertisedDevice);
if (!calRssi) calRssi = defaultTxPower;
float ratio = (calRssi - rssi) / 35.0f; float ratio = (get1mRssi() - rssi) / 35.0f;
raw = pow(10, ratio); raw = pow(10, ratio);
if (filter()) if (filter())
@ -210,7 +207,7 @@ bool BleFingerprint::report(JsonDocument *doc, int maxDistance)
(*doc)[F("id")] = getId(); (*doc)[F("id")] = getId();
if (!name.isEmpty()) (*doc)[F("name")] = name; if (!name.isEmpty()) (*doc)[F("name")] = name;
(*doc)[F("rssi@1m")] = calRssi; (*doc)[F("rssi@1m")] = get1mRssi();
(*doc)[F("rssi")] = rssi; (*doc)[F("rssi")] = rssi;
(*doc)[F("mac")] = mac; (*doc)[F("mac")] = mac;

View File

@ -9,6 +9,13 @@
#include <NimBLEEddystoneURL.h> #include <NimBLEEddystoneURL.h>
#include <SoftFilters.h> #include <SoftFilters.h>
#define NO_RSSI -32768
#ifdef TX_DEFAULT
static const int defaultTxPower = TX_DEFAULT;
#else
static const int defaultTxPower = -59;
#endif
#define Sprintf(f, ...) ( \ #define Sprintf(f, ...) ( \
{ \ { \
char *s; \ char *s; \
@ -40,6 +47,12 @@ public:
return getMac(); return getMac();
} }
String getMac() { return SMacf(address); } String getMac() { return SMacf(address); }
int get1mRssi()
{
if (calRssi != NO_RSSI) return calRssi;
if (calcRssi != NO_RSSI) return calcRssi;
return defaultTxPower;
}
float getDistance() { return output.value.position; } float getDistance() { return output.value.position; }
int getRSSI() { return rssi; } int getRSSI() { return rssi; }
@ -55,7 +68,7 @@ private:
bool hasValue = false, close = false, reported = false, macPublic = false; bool hasValue = false, close = false, reported = false, macPublic = false;
NimBLEAddress address; NimBLEAddress address;
String pid, sid, name, url; String pid, sid, name, url;
int rssi = -100, calRssi = 0; int rssi = -100, calRssi = NO_RSSI, calcRssi = NO_RSSI;
int newest = -100; int newest = -100;
int recent = -100; int recent = -100;
int oldest = -100; int oldest = -100;

View File

@ -4,12 +4,6 @@
#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00) >> 8) + (((x)&0xFF) << 8)) #define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00) >> 8) + (((x)&0xFF) << 8))
#ifdef TX_DEFAULT
static const int defaultTxPower = TX_DEFAULT;
#else
static const int defaultTxPower = -59;
#endif
static BLEUUID eddystoneUUID((uint16_t)0xFEAA); static BLEUUID eddystoneUUID((uint16_t)0xFEAA);
static BLEUUID tileUUID((uint16_t)0xFEED); static BLEUUID tileUUID((uint16_t)0xFEED);
static BLEUUID exposureUUID((uint16_t)0xFD6F); static BLEUUID exposureUUID((uint16_t)0xFD6F);