Fix when device config alias comes in late (#638)
Add support for device config rssi@1m and name Fixes #623
This commit is contained in:
parent
55c66bbfed
commit
11a61d2087
|
@ -11,7 +11,7 @@
|
|||
#include <NimBLEEddystoneURL.h>
|
||||
#include <SoftFilters.h>
|
||||
|
||||
#define NO_RSSI (-32768)
|
||||
#define NO_RSSI (-128)
|
||||
|
||||
#define ID_TYPE_TX_POW short(1)
|
||||
|
||||
|
@ -73,6 +73,8 @@ public:
|
|||
|
||||
String getName() { return name; }
|
||||
|
||||
void setName(String &name) { this->name = name; }
|
||||
|
||||
bool setId(const String &newId, short int newIdType, const String &newName = "");
|
||||
|
||||
void setInitial(int rssi, float distance);
|
||||
|
@ -91,6 +93,8 @@ public:
|
|||
|
||||
int get1mRssi() const;
|
||||
|
||||
void set1mRssi(int8_t rssi) { this->calRssi = rssi; }
|
||||
|
||||
NimBLEAddress const getAddress() { return address; }
|
||||
|
||||
unsigned long getMsSinceLastSeen() const { return lastSeenMillis ? millis() - lastSeenMillis : 4294967295; };
|
||||
|
@ -127,7 +131,8 @@ private:
|
|||
NimBLEAddress address;
|
||||
String id, name, disc;
|
||||
short int idType = NO_ID_TYPE;
|
||||
int rssi = -100, calRssi = NO_RSSI, mdRssi = NO_RSSI, asRssi = NO_RSSI, newest = NO_RSSI, recent = NO_RSSI, oldest = NO_RSSI;
|
||||
int rssi = NO_RSSI, newest = NO_RSSI, recent = NO_RSSI, oldest = NO_RSSI;
|
||||
int8_t calRssi = NO_RSSI, mdRssi = NO_RSSI, asRssi = NO_RSSI;
|
||||
unsigned int qryAttempts = 0, qryDelayMillis = 0;
|
||||
float raw = 0, lastReported = 0, temp = 0, humidity = 0;
|
||||
unsigned long firstSeenMillis, lastSeenMillis = 0, lastReportedMillis = 0, lastQryMillis = 0;
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
#include "BleFingerprintCollection.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <Arduino.h>
|
||||
|
||||
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;
|
||||
int refRssi = 0, forgetMs = 0, skipMs = 0, countMs = 10000;
|
||||
int8_t refRssi = -65;
|
||||
int forgetMs = 0, skipMs = 0, countMs = 10000;
|
||||
std::vector<DeviceConfig> deviceConfigs;
|
||||
std::vector<uint8_t *> irks;
|
||||
std::vector<BleFingerprint *> fingerprints;
|
||||
|
@ -19,7 +21,6 @@ TCallbackFingerprint onCountAdd = nullptr;
|
|||
TCallbackFingerprint onCountDel = nullptr;
|
||||
|
||||
// Private
|
||||
bool _disable = false;
|
||||
unsigned long lastCleanup = 0;
|
||||
SemaphoreHandle_t fingerprintSemaphore;
|
||||
|
||||
|
@ -27,7 +28,6 @@ void Setup() {
|
|||
fingerprintSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(fingerprintSemaphore);
|
||||
}
|
||||
void SetDisable(bool disable) { _disable = disable; }
|
||||
|
||||
void Count(BleFingerprint *f, bool counting) {
|
||||
if (counting) {
|
||||
|
@ -46,15 +46,25 @@ void Close(BleFingerprint *f, bool close) {
|
|||
}
|
||||
|
||||
void Seen(BLEAdvertisedDevice *advertisedDevice) {
|
||||
if (_disable) return;
|
||||
|
||||
BLEAdvertisedDevice copy = *advertisedDevice;
|
||||
|
||||
if (onSeen) onSeen(true);
|
||||
BleFingerprint *f = GetFingerprint(©);
|
||||
if (f->seen(©) && onAdd)
|
||||
onAdd(f);
|
||||
if (onSeen) onSeen(false);
|
||||
if (onSeen) onSeen(true);
|
||||
BleFingerprint *f = GetFingerprint(©);
|
||||
if (f->seen(©) && onAdd)
|
||||
onAdd(f);
|
||||
if (onSeen) onSeen(false);
|
||||
}
|
||||
|
||||
bool addOrReplace(DeviceConfig config) {
|
||||
bool found = false;
|
||||
for (auto &it : deviceConfigs) {
|
||||
if (it.id == config.id) {
|
||||
it = config;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
deviceConfigs.push_back(config);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Config(String &id, String &json) {
|
||||
|
@ -63,21 +73,35 @@ bool Config(String &id, String &json) {
|
|||
|
||||
DeviceConfig config = {};
|
||||
config.id = id;
|
||||
auto alias = doc["id"].as<String>();
|
||||
if (alias != id) config.alias = alias;
|
||||
config.calRssi = doc["rssi@1m"];
|
||||
config.name = doc["name"].as<String>();
|
||||
deviceConfigs.push_back(config);
|
||||
if (doc.containsKey("id")) {
|
||||
auto alias = doc["id"].as<String>();
|
||||
if (alias != id) config.alias = alias;
|
||||
}
|
||||
if (doc.containsKey("rssi@1m"))
|
||||
config.calRssi = doc["rssi@1m"].as<int8_t>();
|
||||
if (doc.containsKey("name"))
|
||||
config.name = doc["name"].as<String>();
|
||||
auto isNew = addOrReplace(config);
|
||||
|
||||
auto p = id.indexOf("irk:");
|
||||
if (p == 0) {
|
||||
auto irk_hex = id.substring(4);
|
||||
uint8_t *irk = new uint8_t[16];
|
||||
if (!hextostr(irk_hex, irk, 16))
|
||||
return false;
|
||||
irks.push_back(irk);
|
||||
if (isNew) {
|
||||
auto p = id.indexOf("irk:");
|
||||
if (p == 0) {
|
||||
auto irk_hex = id.substring(4);
|
||||
uint8_t *irk = new uint8_t[16];
|
||||
if (!hextostr(irk_hex, irk, 16))
|
||||
return false;
|
||||
irks.push_back(irk);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& it : fingerprints)
|
||||
for (auto &it : fingerprints) {
|
||||
auto it_id = it->getId();
|
||||
if (it_id == id || it_id == config.alias) {
|
||||
it->setName(config.name);
|
||||
it->setId(config.alias.length() > 0 ? config.alias : config.id, ID_TYPE_ALIAS, config.name);
|
||||
if (config.calRssi != NO_RSSI)
|
||||
it->set1mRssi(config.calRssi);
|
||||
} else
|
||||
it->fingerprintAddress();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ struct DeviceConfig {
|
|||
String id;
|
||||
String alias;
|
||||
String name;
|
||||
uint8_t calRssi = 127;
|
||||
int8_t calRssi = NO_RSSI;
|
||||
};
|
||||
|
||||
namespace BleFingerprintCollection {
|
||||
|
@ -35,7 +35,6 @@ BleFingerprint *GetFingerprint(BLEAdvertisedDevice *advertisedDevice);
|
|||
void CleanupOldFingerprints();
|
||||
const std::vector<BleFingerprint *> GetCopy();
|
||||
bool FindDeviceConfig(const String &id, DeviceConfig &config);
|
||||
void SetDisable(bool disable);
|
||||
|
||||
extern TCallbackBool onSeen;
|
||||
extern TCallbackFingerprint onAdd;
|
||||
|
@ -47,7 +46,8 @@ extern TCallbackFingerprint onCountDel;
|
|||
|
||||
extern String include, exclude, query, knownMacs, knownIrks, countIds;
|
||||
extern float skipDistance, maxDistance, absorption, countEnter, countExit;
|
||||
extern int refRssi, forgetMs, skipMs, countMs;
|
||||
extern int8_t refRssi;
|
||||
extern int forgetMs, skipMs, countMs;
|
||||
extern std::vector<DeviceConfig> deviceConfigs;
|
||||
extern std::vector<uint8_t *> irks;
|
||||
extern std::vector<BleFingerprint *> fingerprints;
|
||||
|
|
1706
src/ui_index_js.h
1706
src/ui_index_js.h
File diff suppressed because it is too large
Load Diff
|
@ -123,7 +123,7 @@ const columns = [
|
|||
classNameSelect="px-1 py-1 border rounded-md text-sm leading-5 font-medium text-gray-900 placeholder-gray-500 focus:outline-none focus:shadow-outline-blue focus:border-blue-300 focus:z-10 sm:text-sm sm:leading-5"
|
||||
></SvelteTable>
|
||||
{:else}
|
||||
<h1>Error while loading devices</h1>
|
||||
<h1>Loading fingerprints...</h1>
|
||||
{/if}
|
||||
</main>
|
||||
|
||||
|
|
Loading…
Reference in New Issue