2021-03-22 14:11:42 +01:00
|
|
|
#ifndef _BLEFINGERPRINT_
|
|
|
|
#define _BLEFINGERPRINT_
|
|
|
|
|
2022-03-06 17:48:04 +01:00
|
|
|
#include "rssi.h"
|
2022-06-11 17:25:25 +02:00
|
|
|
#include "string_utils.h"
|
2021-04-05 04:12:46 +02:00
|
|
|
#include <ArduinoJson.h>
|
2021-03-22 14:11:42 +01:00
|
|
|
#include <NimBLEAdvertisedDevice.h>
|
|
|
|
#include <NimBLEBeacon.h>
|
2021-04-05 04:12:46 +02:00
|
|
|
#include <NimBLEDevice.h>
|
|
|
|
#include <NimBLEEddystoneTLM.h>
|
|
|
|
#include <NimBLEEddystoneURL.h>
|
2021-03-22 23:56:29 +01:00
|
|
|
#include <SoftFilters.h>
|
2021-03-22 14:11:42 +01:00
|
|
|
|
2022-03-06 17:48:04 +01:00
|
|
|
#define NO_RSSI (-32768)
|
2021-09-30 18:48:50 +02:00
|
|
|
|
2021-10-11 04:49:56 +02:00
|
|
|
#define ID_TYPE_TX_POW short(1)
|
2022-08-04 01:50:22 +02:00
|
|
|
|
2022-08-07 13:31:42 +02:00
|
|
|
#define NO_ID_TYPE short(0)
|
|
|
|
|
2022-08-04 01:50:22 +02:00
|
|
|
#define ID_TYPE_ECHO_LOST short(-10)
|
2022-03-14 02:54:50 +01:00
|
|
|
#define ID_TYPE_MISC_APPLE short(-5)
|
2022-03-06 17:48:04 +01:00
|
|
|
|
2022-08-07 13:31:42 +02:00
|
|
|
#define ID_TYPE_RAND_MAC short(1)
|
2022-03-06 17:48:04 +01:00
|
|
|
#define ID_TYPE_AD short(10)
|
|
|
|
#define ID_TYPE_SD short(15)
|
|
|
|
#define ID_TYPE_MD short(20)
|
|
|
|
#define ID_TYPE_MISC short(30)
|
2022-06-24 22:39:43 +02:00
|
|
|
#define ID_TYPE_FINDMY short(32)
|
2022-03-06 17:48:04 +01:00
|
|
|
#define ID_TYPE_NAME short(35)
|
2022-08-07 13:31:42 +02:00
|
|
|
#define ID_TYPE_MSFT short(40)
|
|
|
|
#define ID_TYPE_UNIQUE short(50)
|
|
|
|
#define ID_TYPE_PUBLIC_MAC short(55)
|
2022-03-09 13:54:32 +01:00
|
|
|
#define ID_TYPE_SONOS short(105)
|
2022-03-14 02:54:50 +01:00
|
|
|
#define ID_TYPE_GARMIN short(107)
|
2022-03-09 13:54:32 +01:00
|
|
|
#define ID_TYPE_MITHERM short(110)
|
|
|
|
#define ID_TYPE_MIFIT short(115)
|
|
|
|
#define ID_TYPE_EXPOSURE short(120)
|
2022-05-23 02:43:29 +02:00
|
|
|
#define ID_TYPE_SMARTTAG short(121)
|
2022-03-09 13:54:32 +01:00
|
|
|
#define ID_TYPE_ITAG short(125)
|
2022-06-18 22:30:42 +02:00
|
|
|
#define ID_TYPE_ITRACK short(127)
|
2022-07-18 08:30:20 +02:00
|
|
|
#define ID_TYPE_NUT short(128)
|
2022-03-09 13:54:32 +01:00
|
|
|
#define ID_TYPE_TRACKR short(130)
|
2022-08-07 13:31:42 +02:00
|
|
|
#define ID_TYPE_TILE short(135)
|
2022-03-09 13:54:32 +01:00
|
|
|
#define ID_TYPE_MEATER short(140)
|
2022-05-23 02:43:47 +02:00
|
|
|
#define ID_TYPE_TRACTIVE short(142)
|
2022-03-09 13:54:32 +01:00
|
|
|
#define ID_TYPE_VANMOOF short(145)
|
|
|
|
#define ID_TYPE_APPLE_NEARBY short(150)
|
|
|
|
#define ID_TYPE_QUERY_MODEL short(155)
|
|
|
|
#define ID_TYPE_QUERY_NAME short(160)
|
2022-07-18 08:30:20 +02:00
|
|
|
#define ID_TYPE_RM_ASST short(165)
|
2022-08-30 10:42:22 +02:00
|
|
|
#define ID_TYPE_EBEACON short(170)
|
|
|
|
#define ID_TYPE_ABEACON short(175)
|
|
|
|
#define ID_TYPE_IBEACON short(180)
|
2022-07-18 08:30:20 +02:00
|
|
|
#define ID_TYPE_KNOWN_IRK short(200)
|
|
|
|
#define ID_TYPE_KNOWN_MAC short(210)
|
2022-08-07 13:31:42 +02:00
|
|
|
#define ID_TYPE_ALIAS short(250)
|
2021-10-11 04:49:56 +02:00
|
|
|
|
2021-03-22 14:11:42 +01:00
|
|
|
class BleFingerprint
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
2022-08-23 12:55:04 +02:00
|
|
|
BleFingerprint(NimBLEAdvertisedDevice *advertisedDevice, float fcmin, float beta, float dcutoff);
|
2021-03-22 14:11:42 +01:00
|
|
|
|
2021-09-30 18:48:50 +02:00
|
|
|
bool seen(BLEAdvertisedDevice *advertisedDevice);
|
2022-03-06 17:48:04 +01:00
|
|
|
|
2022-07-31 06:51:34 +02:00
|
|
|
void fill(JsonObject *doc);
|
|
|
|
|
|
|
|
bool report(JsonObject *doc);
|
2022-03-06 17:48:04 +01:00
|
|
|
|
2021-10-05 13:54:41 +02:00
|
|
|
bool query();
|
2021-03-22 14:11:42 +01:00
|
|
|
|
2022-03-14 02:54:50 +01:00
|
|
|
String getId() { return id; }
|
2021-10-11 04:49:56 +02:00
|
|
|
|
2022-07-31 06:51:34 +02:00
|
|
|
String getName() { return name; }
|
|
|
|
|
2022-03-06 17:48:04 +01:00
|
|
|
bool setId(const String &newId, short int newIdType, const String &newName = "");
|
2021-10-11 04:49:56 +02:00
|
|
|
|
2022-03-06 17:48:04 +01:00
|
|
|
void setInitial(int rssi, float distance);
|
2021-03-30 00:12:59 +02:00
|
|
|
|
2022-03-06 17:48:04 +01:00
|
|
|
String getMac() const { return SMacf(address); }
|
2021-04-07 02:13:13 +02:00
|
|
|
|
2022-08-07 13:31:42 +02:00
|
|
|
short getIdType() const { return idType; }
|
|
|
|
|
2022-03-06 17:48:04 +01:00
|
|
|
String const getDiscriminator() { return disc; }
|
|
|
|
|
|
|
|
float getDistance() const { return output.value.position; }
|
|
|
|
|
|
|
|
int getRssi() const { return rssi; }
|
|
|
|
|
|
|
|
int getNewestRssi() const { return newest; }
|
|
|
|
|
|
|
|
int get1mRssi() const;
|
|
|
|
|
|
|
|
NimBLEAddress const getAddress() { return address; }
|
|
|
|
|
2022-08-07 13:31:42 +02:00
|
|
|
unsigned long getMsSinceLastSeen() const { return lastSeenMillis ? millis() - lastSeenMillis : 4294967295; };
|
2022-03-14 02:54:50 +01:00
|
|
|
|
|
|
|
unsigned long getMsSinceFirstSeen() const { return millis() - firstSeenMillis; };
|
2022-03-06 17:48:04 +01:00
|
|
|
|
2022-07-31 06:51:34 +02:00
|
|
|
bool getVisible() const { return !ignore && !hidden && hasValue; }
|
|
|
|
|
2022-03-06 17:48:04 +01:00
|
|
|
bool getAdded() const { return added; };
|
|
|
|
|
|
|
|
bool getIgnore() const { return ignore; };
|
|
|
|
|
|
|
|
bool getAllowQuery() const { return allowQuery; };
|
|
|
|
|
|
|
|
bool getRmAsst() const { return rmAsst; };
|
2021-03-22 14:11:42 +01:00
|
|
|
|
2022-03-14 02:54:50 +01:00
|
|
|
unsigned int getSeenCount()
|
2021-10-05 13:54:41 +02:00
|
|
|
{
|
2022-03-14 02:54:50 +01:00
|
|
|
auto sc = seenCount - lastSeenCount;
|
|
|
|
lastSeenCount = seenCount;
|
2021-10-05 13:54:41 +02:00
|
|
|
return sc;
|
|
|
|
}
|
2021-03-22 14:11:42 +01:00
|
|
|
|
2022-03-14 02:54:50 +01:00
|
|
|
bool shouldCount();
|
2022-07-18 08:30:20 +02:00
|
|
|
void fingerprintAddress();
|
2022-03-14 02:54:50 +01:00
|
|
|
|
2022-08-07 13:31:42 +02:00
|
|
|
void expire();
|
|
|
|
|
2021-03-22 14:11:42 +01:00
|
|
|
private:
|
2021-09-15 18:11:32 +02:00
|
|
|
|
2022-03-06 17:48:04 +01:00
|
|
|
static bool shouldHide(const String &s);
|
|
|
|
|
2022-03-14 02:54:50 +01:00
|
|
|
bool hasValue = false, added = false, close = false, reported = false, ignore = false, allowQuery = false, didQuery = false, rmAsst = false, hidden = false, connectable = false, countable = false, counting = false;
|
2021-03-28 20:35:54 +02:00
|
|
|
NimBLEAddress address;
|
2021-10-11 04:49:56 +02:00
|
|
|
String id, name, disc;
|
2022-08-07 13:31:42 +02:00
|
|
|
short int idType = NO_ID_TYPE;
|
2022-03-06 17:48:04 +01:00
|
|
|
int rssi = -100, calRssi = NO_RSSI, mdRssi = NO_RSSI, asRssi = NO_RSSI, newest = NO_RSSI, recent = NO_RSSI, oldest = NO_RSSI;
|
2022-03-14 02:54:50 +01:00
|
|
|
unsigned int qryAttempts = 0, qryDelayMillis = 0;
|
2021-11-11 03:55:10 +01:00
|
|
|
float raw = 0, lastReported = 0, temp = 0, humidity = 0;
|
2021-10-05 13:54:41 +02:00
|
|
|
unsigned long firstSeenMillis, lastSeenMillis = 0, lastReportedMillis = 0, lastQryMillis = 0;
|
2022-03-14 02:54:50 +01:00
|
|
|
unsigned long seenCount = 1, lastSeenCount = 0;
|
2021-11-11 03:55:10 +01:00
|
|
|
uint16_t mv = 0;
|
2022-07-18 08:30:20 +02:00
|
|
|
uint8_t battery = 0xFF, addressType = 0xFF;
|
2021-03-29 20:50:23 +02:00
|
|
|
|
2022-02-16 16:55:27 +01:00
|
|
|
Reading<Differential<float>> output;
|
2021-03-22 23:56:29 +01:00
|
|
|
|
2022-02-16 16:55:27 +01:00
|
|
|
OneEuroFilter<float, unsigned long> oneEuro;
|
|
|
|
DifferentialFilter<float, unsigned long> diffFilter;
|
2021-04-07 02:13:13 +02:00
|
|
|
|
|
|
|
bool filter();
|
2022-03-06 17:48:04 +01:00
|
|
|
|
|
|
|
void fingerprint(NimBLEAdvertisedDevice *advertisedDevice);
|
2022-03-14 02:54:50 +01:00
|
|
|
void fingerprintServiceAdvertisements(NimBLEAdvertisedDevice *advertisedDevice, size_t serviceAdvCount, bool haveTxPower, int8_t txPower);
|
|
|
|
void fingerprintServiceData(NimBLEAdvertisedDevice *advertisedDevice, size_t serviceDataCount, bool haveTxPower, int8_t txPower);
|
|
|
|
void fingerprintManufactureData(NimBLEAdvertisedDevice *advertisedDevice, bool haveTxPower, int8_t txPower);
|
2021-03-22 14:11:42 +01:00
|
|
|
};
|
2022-03-06 17:48:04 +01:00
|
|
|
|
2021-03-22 14:11:42 +01:00
|
|
|
#endif
|