wip
This commit is contained in:
parent
3da62ad3c9
commit
928ee7b152
@ -1,4 +1,5 @@
|
||||
#include "MiFloraHandler.h"
|
||||
#include "NimBLEAttValue.h"
|
||||
|
||||
namespace MiFloraHandler {
|
||||
|
||||
|
@ -42,11 +42,7 @@ async def to_code(config):
|
||||
add_idf_sdkconfig_option("CONFIG_BT_NIMBLE_ENABLED", True)
|
||||
add_idf_sdkconfig_option("CONFIG_MBEDTLS_HARDWARE_AES", False)
|
||||
|
||||
cg.add_library(
|
||||
name="esp-nimble-cpp",
|
||||
repository="https://github.com/h2zero/esp-nimble-cpp",
|
||||
version="1.4.1"
|
||||
)
|
||||
cg.add_library("esp-nimble-cpp", repository="https://github.com/h2zero/esp-nimble-cpp#v1.4.1", version="v1.4.1")
|
||||
|
||||
# await nimble_tracker.device_listener_to_code(var, config)
|
||||
# await nimble_tracker.register_ble_device(var, config)
|
3
components/esp32_presense/defaults.h
Normal file
3
components/esp32_presense/defaults.h
Normal file
@ -0,0 +1,3 @@
|
||||
#define BLE_SCAN_INTERVAL 0x80
|
||||
#define BLE_SCAN_WINDOW 0x80
|
||||
#define SCAN_TASK_STACK_SIZE 2562
|
@ -1,4 +1,5 @@
|
||||
#include "esp32_presense.h"
|
||||
#include "defaults.h"
|
||||
|
||||
namespace esphome
|
||||
{
|
||||
@ -8,17 +9,83 @@ namespace esphome
|
||||
unsigned int totalFpSeen = 0;
|
||||
unsigned int totalFpQueried = 0;
|
||||
unsigned int totalFpReported = 0;
|
||||
|
||||
TimerHandle_t reconnectTimer;
|
||||
TaskHandle_t scanTaskHandle;
|
||||
|
||||
unsigned long updateStartedMillis = 0;
|
||||
unsigned long lastTeleMillis = 0;
|
||||
int reconnectTries = 0;
|
||||
int teleFails = 0;
|
||||
int reportFailed = 0;
|
||||
bool online = false; // Have we successfully sent status=online
|
||||
bool sentDiscovery = false; // Have we successfully sent discovery
|
||||
UBaseType_t bleStack = 0;
|
||||
|
||||
bool discovery, publishTele, publishRooms, publishDevices;
|
||||
|
||||
class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
|
||||
void onResult(BLEAdvertisedDevice *advertisedDevice) {
|
||||
bleStack = uxTaskGetStackHighWaterMark(nullptr);
|
||||
BleFingerprintCollection::Seen(advertisedDevice);
|
||||
}
|
||||
};
|
||||
|
||||
void scanTask(void *parameter) {
|
||||
NimBLEDevice::init("ESPresense");
|
||||
// Enrollment::Setup();
|
||||
NimBLEDevice::setMTU(23);
|
||||
|
||||
auto pBLEScan = NimBLEDevice::getScan();
|
||||
pBLEScan->setInterval(BLE_SCAN_INTERVAL);
|
||||
pBLEScan->setWindow(BLE_SCAN_WINDOW);
|
||||
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks(), true);
|
||||
pBLEScan->setActiveScan(false);
|
||||
pBLEScan->setDuplicateFilter(false);
|
||||
pBLEScan->setMaxResults(0);
|
||||
if (!pBLEScan->start(0, nullptr, false))
|
||||
ESP_LOGE(TAG, "Error starting continuous ble scan");
|
||||
|
||||
while (true) {
|
||||
for (auto &f : BleFingerprintCollection::fingerprints)
|
||||
if (f->query())
|
||||
totalFpQueried++;
|
||||
|
||||
// Enrollment::Loop();
|
||||
|
||||
if (!pBLEScan->isScanning()) {
|
||||
if (!pBLEScan->start(0, nullptr, true))
|
||||
ESP_LOGE(TAG, "Error re-starting continuous ble scan");
|
||||
delay(3000); // If we stopped scanning, don't query for 3 seconds in order for us to catch any missed broadcasts
|
||||
} else {
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ESP32Presense::setup()
|
||||
{
|
||||
BleFingerprintCollection::Setup();
|
||||
xTaskCreatePinnedToCore(scanTask, "scanTask", SCAN_TASK_STACK_SIZE, nullptr, 1, &scanTaskHandle, CONFIG_BT_NIMBLE_PINNED_TO_CORE);
|
||||
}
|
||||
|
||||
void ESP32Presense::loop()
|
||||
{
|
||||
reportLoop();
|
||||
}
|
||||
|
||||
void ESP32Presense::reportLoop()
|
||||
{
|
||||
auto copy = BleFingerprintCollection::GetCopy();
|
||||
unsigned int count = 0;
|
||||
|
||||
for (auto &i : copy)
|
||||
if (i->shouldCount())
|
||||
count++;
|
||||
|
||||
yield();
|
||||
sendTelemetry(totalSeen, totalFpSeen, totalFpQueried, totalFpReported, count);
|
||||
yield();
|
||||
|
||||
auto reported = 0;
|
||||
for (auto &f : copy) {
|
||||
|
@ -26,8 +26,8 @@ namespace esphome
|
||||
unsigned int count
|
||||
);
|
||||
public:
|
||||
void setup() {};
|
||||
void loop() {};
|
||||
void setup();
|
||||
void loop();
|
||||
void reportLoop();
|
||||
// void on_result(nimble_distance_custom::NimbleDistanceCustomResult&) override;
|
||||
void set_room(std::string room) { room_ = room; }
|
||||
|
Loading…
Reference in New Issue
Block a user