Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
4dbb575a15 | |||
d021d7c29d | |||
ae7e408b4e | |||
7b3b746a1b | |||
37989e25ae | |||
922dbf98b9 | |||
34089f1add | |||
4c710f7a0a | |||
b766c0ce04 | |||
32fe442cce |
@ -19,7 +19,7 @@ class ClientCallbacks : public BLEClientCallbacks {
|
||||
static ClientCallbacks clientCB;
|
||||
|
||||
BleFingerprint::BleFingerprint(BLEAdvertisedDevice *advertisedDevice, float fcmin, float beta, float dcutoff) : filteredDistance{FilteredDistance(fcmin, beta, dcutoff)} {
|
||||
firstSeenMillis = millis();
|
||||
firstSeenMillis = esphome::millis();
|
||||
address = NimBLEAddress(advertisedDevice->getAddress());
|
||||
addressType = advertisedDevice->getAddressType();
|
||||
rssi = advertisedDevice->getRSSI();
|
||||
@ -70,10 +70,10 @@ bool BleFingerprint::setId(const std::string &newId, short newIdType, const std:
|
||||
qryAttempts = 0;
|
||||
if (rssi < -80) {
|
||||
qryDelayMillis = 30000;
|
||||
lastQryMillis = millis();
|
||||
lastQryMillis = esphome::millis();
|
||||
} else if (rssi < -70) {
|
||||
qryDelayMillis = 5000;
|
||||
lastQryMillis = millis();
|
||||
lastQryMillis = esphome::millis();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -411,7 +411,7 @@ void BleFingerprint::fingerprintManufactureData(NimBLEAdvertisedDevice *advertis
|
||||
}
|
||||
|
||||
bool BleFingerprint::seen(BLEAdvertisedDevice *advertisedDevice) {
|
||||
lastSeenMillis = millis();
|
||||
lastSeenMillis = esphome::millis();
|
||||
reported = false;
|
||||
|
||||
seenCount++;
|
||||
@ -443,17 +443,17 @@ bool BleFingerprint::fill(JsonObject *doc) {
|
||||
(*doc)["rssi@1m"] = get1mRssi();
|
||||
(*doc)["rssi"] = rssi;
|
||||
|
||||
if (isnormal(raw)) (*doc)["raw"] = serialized(std::string(raw, 2));
|
||||
if (isnormal(dist)) (*doc)["distance"] = serialized(std::string(dist, 2));
|
||||
if (isnormal(vari)) (*doc)["var"] = serialized(std::string(vari, 2));
|
||||
if (isnormal(raw)) (*doc)["raw"] = serialized(std::to_string(raw));
|
||||
if (isnormal(dist)) (*doc)["distance"] = serialized(std::to_string(dist));
|
||||
if (isnormal(vari)) (*doc)["var"] = serialized(std::to_string(vari));
|
||||
if (close) (*doc)["close"] = true;
|
||||
|
||||
(*doc)["int"] = (millis() - firstSeenMillis) / seenCount;
|
||||
|
||||
if (mv) (*doc)["mV"] = mv;
|
||||
if (battery != 0xFF) (*doc)["batt"] = battery;
|
||||
if (temp) (*doc)["temp"] = serialized(std::string(temp, 1));
|
||||
if (humidity) (*doc)["rh"] = serialized(std::string(humidity, 1));
|
||||
if (temp) (*doc)["temp"] = serialized(std::to_string(temp));
|
||||
if (humidity) (*doc)["rh"] = serialized(std::to_string(humidity));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -465,7 +465,7 @@ bool BleFingerprint::report(JsonObject *doc) {
|
||||
if (maxDistance > 0 && dist > maxDistance)
|
||||
return false;
|
||||
|
||||
auto now = millis();
|
||||
auto now = esphome::millis();
|
||||
if ((abs(dist - lastReported) < BleFingerprintCollection::skipDistance) && (lastReportedMillis > 0) && (now - lastReportedMillis < BleFingerprintCollection::skipMs))
|
||||
return false;
|
||||
|
||||
@ -483,7 +483,7 @@ bool BleFingerprint::query() {
|
||||
if (!allowQuery || isQuerying) return false;
|
||||
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 - lastQryMillis < qryDelayMillis) return false; // Too soon
|
||||
|
||||
|
@ -20,8 +20,6 @@
|
||||
#include "esphome/core/time.h"
|
||||
|
||||
#define TAG "esp32_presense"
|
||||
#define millis esphome::millis
|
||||
// #define delay esphome::delay
|
||||
|
||||
#define NO_RSSI int8_t(-128)
|
||||
|
||||
|
@ -35,7 +35,7 @@ async def to_code(config):
|
||||
cg.add(var.set_room(config[CONF_ROOM_KEY]))
|
||||
# cg.add(var.set_base_topic(config[CONF_BASE_TOPIC_KEY]))
|
||||
# cg.add(var.set_addresses(config[CONF_MAC_KEY]))
|
||||
# cg.add(var.set_max_distance(config[CONF_MAX_DISTANCE]))
|
||||
cg.add(var.set_max_distance(config[CONF_MAX_DISTANCE]))
|
||||
|
||||
add_idf_sdkconfig_option("CONFIG_BT_ENABLED", True)
|
||||
add_idf_sdkconfig_option("CONFIG_BT_BLUEDROID_ENABLED", False)
|
||||
|
@ -78,6 +78,7 @@ namespace esphome
|
||||
{
|
||||
BleFingerprintCollection::Setup();
|
||||
xTaskCreatePinnedToCore(scanTask, "scanTask", SCAN_TASK_STACK_SIZE, nullptr, 1, &scanTaskHandle, CONFIG_BT_NIMBLE_PINNED_TO_CORE);
|
||||
publishDevices = true;
|
||||
}
|
||||
|
||||
void ESP32Presense::loop()
|
||||
@ -113,8 +114,9 @@ namespace esphome
|
||||
}
|
||||
|
||||
if (f->hasReport()) {
|
||||
if (reportBuffer(f))
|
||||
if (reportBuffer(f)) {
|
||||
f->clearReport();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user