Add Enter/Left messages for enrollment
This commit is contained in:
parent
5d649f1d2a
commit
270e3c475b
|
@ -46,7 +46,7 @@ BleFingerprint::BleFingerprint(BLEAdvertisedDevice *advertisedDevice, float init
|
||||||
auto nativeAddress = address.getNative();
|
auto nativeAddress = address.getNative();
|
||||||
String mac_address = Sprintf("%02x%02x%02x%02x%02x%02x", nativeAddress[5], nativeAddress[4], nativeAddress[3], nativeAddress[2], nativeAddress[1], nativeAddress[0]);
|
String mac_address = Sprintf("%02x%02x%02x%02x%02x%02x", nativeAddress[5], nativeAddress[4], nativeAddress[3], nativeAddress[2], nativeAddress[1], nativeAddress[0]);
|
||||||
|
|
||||||
Serial.print("MAC: ");
|
Serial.print("New | MAC: ");
|
||||||
Serial.print(mac_address);
|
Serial.print(mac_address);
|
||||||
|
|
||||||
if (advertisedDevice->haveName())
|
if (advertisedDevice->haveName())
|
||||||
|
@ -200,10 +200,19 @@ bool BleFingerprint::shouldReport()
|
||||||
StaticJsonDocument<512> BleFingerprint::report()
|
StaticJsonDocument<512> BleFingerprint::report()
|
||||||
{
|
{
|
||||||
StaticJsonDocument<512> doc;
|
StaticJsonDocument<512> doc;
|
||||||
#if VERBOSE
|
if (output.value.position < 0.5)
|
||||||
// if (id == "iBeacon:2c96d71f47569faddd487c93cc9dac2e-0-0")
|
{
|
||||||
// Serial.printf("%-36s %lu %5.1f %5.1f %5.1f\n", id.c_str(), output.timestamp, output.value.position, output.value.speed * 1e6, output.value.acceleration * 1e12);
|
if (!enroll)
|
||||||
#endif
|
{
|
||||||
|
Serial.printf("Enter | %-50s %lu %5.1f %5.1f %5.1f\n", id.c_str(), output.timestamp, output.value.position, output.value.speed * 1e6, output.value.acceleration * 1e12);
|
||||||
|
enroll = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (enroll && output.value.position > 1.5)
|
||||||
|
{
|
||||||
|
Serial.printf("Left | %-50s %lu %5.1f %5.1f %5.1f\n", id.c_str(), output.timestamp, output.value.position, output.value.speed * 1e6, output.value.acceleration * 1e12);
|
||||||
|
enroll = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (id != nullptr)
|
if (id != nullptr)
|
||||||
doc[F("id")] = id;
|
doc[F("id")] = id;
|
||||||
|
|
|
@ -24,7 +24,7 @@ public:
|
||||||
NimBLEAddress getAddress() { return address; }
|
NimBLEAddress getAddress() { return address; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool hasValue;
|
bool hasValue = false, enroll = false;
|
||||||
NimBLEAddress address;
|
NimBLEAddress address;
|
||||||
String id, name, url;
|
String id, name, url;
|
||||||
int rssi, calRssi;
|
int rssi, calRssi;
|
||||||
|
|
17
src/main.cpp
17
src/main.cpp
|
@ -283,10 +283,8 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks
|
||||||
void onResult(BLEAdvertisedDevice *advertisedDevice)
|
void onResult(BLEAdvertisedDevice *advertisedDevice)
|
||||||
{
|
{
|
||||||
digitalWrite(LED_BUILTIN, LED_BUILTIN_ON);
|
digitalWrite(LED_BUILTIN, LED_BUILTIN_ON);
|
||||||
//Serial.printf("Advertised Device: %s \n", advertisedDevice->toString().c_str());
|
|
||||||
BleFingerprint *f = getFingerprint(advertisedDevice);
|
BleFingerprint *f = getFingerprint(advertisedDevice);
|
||||||
f->seen(advertisedDevice);
|
f->seen(advertisedDevice);
|
||||||
vTaskDelay(advertisedDevice->getRSSI() > -60 ? 2 : 1);
|
|
||||||
digitalWrite(LED_BUILTIN, !LED_BUILTIN_ON);
|
digitalWrite(LED_BUILTIN, !LED_BUILTIN_ON);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -336,6 +334,13 @@ bool reportDevice(BLEAdvertisedDevice advertisedDevice)
|
||||||
|
|
||||||
void scanForDevices(void *parameter)
|
void scanForDevices(void *parameter)
|
||||||
{
|
{
|
||||||
|
BLEDevice::init("");
|
||||||
|
pBLEScan = BLEDevice::getScan(); //create new scan
|
||||||
|
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks(), true);
|
||||||
|
pBLEScan->setActiveScan(BLE_ACTIVE_SCAN);
|
||||||
|
pBLEScan->setInterval(BLE_SCAN_INTERVAL);
|
||||||
|
pBLEScan->setWindow(BLE_SCAN_WINDOW);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
@ -534,14 +539,6 @@ void setup()
|
||||||
connectToWifi();
|
connectToWifi();
|
||||||
setClock();
|
setClock();
|
||||||
connectToMqtt();
|
connectToMqtt();
|
||||||
|
|
||||||
BLEDevice::init("");
|
|
||||||
pBLEScan = BLEDevice::getScan(); //create new scan
|
|
||||||
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks(), true);
|
|
||||||
pBLEScan->setActiveScan(BLE_ACTIVE_SCAN);
|
|
||||||
pBLEScan->setInterval(BLE_SCAN_INTERVAL);
|
|
||||||
pBLEScan->setWindow(BLE_SCAN_WINDOW);
|
|
||||||
|
|
||||||
xTaskCreatePinnedToCore(scanForDevices, "BLE Scan", 4096, pBLEScan, 1, &thBLEScan, 1);
|
xTaskCreatePinnedToCore(scanForDevices, "BLE Scan", 4096, pBLEScan, 1, &thBLEScan, 1);
|
||||||
|
|
||||||
#ifdef M5STICK
|
#ifdef M5STICK
|
||||||
|
|
Loading…
Reference in New Issue