Compare commits

...

7 Commits
0.0.17 ... main

Author SHA1 Message Date
4dbb575a15 wip 2023-12-30 18:50:12 +03:00
d021d7c29d remove log 2023-12-10 13:47:33 +03:00
ae7e408b4e fix 2023-12-10 13:38:37 +03:00
7b3b746a1b fix 2023-12-10 13:37:46 +03:00
37989e25ae fix 2023-12-10 13:30:58 +03:00
922dbf98b9 fix 2023-12-10 13:21:11 +03:00
34089f1add fix 2023-12-10 13:20:21 +03:00
3 changed files with 12 additions and 18 deletions

View File

@ -19,7 +19,7 @@ class ClientCallbacks : public BLEClientCallbacks {
static ClientCallbacks clientCB; static ClientCallbacks clientCB;
BleFingerprint::BleFingerprint(BLEAdvertisedDevice *advertisedDevice, float fcmin, float beta, float dcutoff) : filteredDistance{FilteredDistance(fcmin, beta, dcutoff)} { BleFingerprint::BleFingerprint(BLEAdvertisedDevice *advertisedDevice, float fcmin, float beta, float dcutoff) : filteredDistance{FilteredDistance(fcmin, beta, dcutoff)} {
firstSeenMillis = millis(); firstSeenMillis = esphome::millis();
address = NimBLEAddress(advertisedDevice->getAddress()); address = NimBLEAddress(advertisedDevice->getAddress());
addressType = advertisedDevice->getAddressType(); addressType = advertisedDevice->getAddressType();
rssi = advertisedDevice->getRSSI(); rssi = advertisedDevice->getRSSI();
@ -70,10 +70,10 @@ bool BleFingerprint::setId(const std::string &newId, short newIdType, const std:
qryAttempts = 0; qryAttempts = 0;
if (rssi < -80) { if (rssi < -80) {
qryDelayMillis = 30000; qryDelayMillis = 30000;
lastQryMillis = millis(); lastQryMillis = esphome::millis();
} else if (rssi < -70) { } else if (rssi < -70) {
qryDelayMillis = 5000; qryDelayMillis = 5000;
lastQryMillis = millis(); lastQryMillis = esphome::millis();
} }
} }
} }
@ -411,7 +411,7 @@ void BleFingerprint::fingerprintManufactureData(NimBLEAdvertisedDevice *advertis
} }
bool BleFingerprint::seen(BLEAdvertisedDevice *advertisedDevice) { bool BleFingerprint::seen(BLEAdvertisedDevice *advertisedDevice) {
lastSeenMillis = millis(); lastSeenMillis = esphome::millis();
reported = false; reported = false;
seenCount++; seenCount++;
@ -443,17 +443,17 @@ bool BleFingerprint::fill(JsonObject *doc) {
(*doc)["rssi@1m"] = get1mRssi(); (*doc)["rssi@1m"] = get1mRssi();
(*doc)["rssi"] = rssi; (*doc)["rssi"] = rssi;
if (isnormal(raw)) (*doc)["raw"] = serialized(std::string(raw, 2)); if (isnormal(raw)) (*doc)["raw"] = serialized(std::to_string(raw));
if (isnormal(dist)) (*doc)["distance"] = serialized(std::string(dist, 2)); if (isnormal(dist)) (*doc)["distance"] = serialized(std::to_string(dist));
if (isnormal(vari)) (*doc)["var"] = serialized(std::string(vari, 2)); if (isnormal(vari)) (*doc)["var"] = serialized(std::to_string(vari));
if (close) (*doc)["close"] = true; if (close) (*doc)["close"] = true;
(*doc)["int"] = (millis() - firstSeenMillis) / seenCount; (*doc)["int"] = (millis() - firstSeenMillis) / seenCount;
if (mv) (*doc)["mV"] = mv; if (mv) (*doc)["mV"] = mv;
if (battery != 0xFF) (*doc)["batt"] = battery; if (battery != 0xFF) (*doc)["batt"] = battery;
if (temp) (*doc)["temp"] = serialized(std::string(temp, 1)); if (temp) (*doc)["temp"] = serialized(std::to_string(temp));
if (humidity) (*doc)["rh"] = serialized(std::string(humidity, 1)); if (humidity) (*doc)["rh"] = serialized(std::to_string(humidity));
return true; return true;
} }
@ -465,7 +465,7 @@ bool BleFingerprint::report(JsonObject *doc) {
if (maxDistance > 0 && dist > maxDistance) if (maxDistance > 0 && dist > maxDistance)
return false; return false;
auto now = millis(); auto now = esphome::millis();
if ((abs(dist - lastReported) < BleFingerprintCollection::skipDistance) && (lastReportedMillis > 0) && (now - lastReportedMillis < BleFingerprintCollection::skipMs)) if ((abs(dist - lastReported) < BleFingerprintCollection::skipDistance) && (lastReportedMillis > 0) && (now - lastReportedMillis < BleFingerprintCollection::skipMs))
return false; return false;
@ -483,7 +483,7 @@ bool BleFingerprint::query() {
if (!allowQuery || isQuerying) return false; if (!allowQuery || isQuerying) return false;
if (rssi < -90) return false; // Too far away if (rssi < -90) return false; // Too far away
auto now = millis(); auto now = esphome::millis();
if (now - lastSeenMillis > 5) return false; // Haven't seen lately if (now - lastSeenMillis > 5) return false; // Haven't seen lately
if (now - lastQryMillis < qryDelayMillis) return false; // Too soon if (now - lastQryMillis < qryDelayMillis) return false; // Too soon

View File

@ -20,8 +20,6 @@
#include "esphome/core/time.h" #include "esphome/core/time.h"
#define TAG "esp32_presense" #define TAG "esp32_presense"
#define millis esphome::millis
// #define delay esphome::delay
#define NO_RSSI int8_t(-128) #define NO_RSSI int8_t(-128)

View File

@ -78,6 +78,7 @@ namespace esphome
{ {
BleFingerprintCollection::Setup(); BleFingerprintCollection::Setup();
xTaskCreatePinnedToCore(scanTask, "scanTask", SCAN_TASK_STACK_SIZE, nullptr, 1, &scanTaskHandle, CONFIG_BT_NIMBLE_PINNED_TO_CORE); xTaskCreatePinnedToCore(scanTask, "scanTask", SCAN_TASK_STACK_SIZE, nullptr, 1, &scanTaskHandle, CONFIG_BT_NIMBLE_PINNED_TO_CORE);
publishDevices = true;
} }
void ESP32Presense::loop() void ESP32Presense::loop()
@ -112,19 +113,14 @@ namespace esphome
totalFpSeen++; totalFpSeen++;
} }
ESP_LOGD(TAG, "F %s", f->getAddress());
if (f->hasReport()) { if (f->hasReport()) {
ESP_LOGD(TAG, "hasReport");
if (reportBuffer(f)) { if (reportBuffer(f)) {
ESP_LOGD(TAG, "reportBuffer");
f->clearReport(); f->clearReport();
} }
} }
if (this->reportDevice(f)) { if (this->reportDevice(f)) {
ESP_LOGD(TAG, "reportDevice");
totalFpReported++; totalFpReported++;
reported++; reported++;
} }