update nuki lib
This commit is contained in:
@@ -77,7 +77,7 @@ void NukiWrapper::update()
|
|||||||
|
|
||||||
_bleScanner->update();
|
_bleScanner->update();
|
||||||
vTaskDelay( 5000 / portTICK_PERIOD_MS);
|
vTaskDelay( 5000 / portTICK_PERIOD_MS);
|
||||||
if (_nukiBle.pairNuki()) {
|
if (_nukiBle.pairNuki() == Nuki::PairingResult::Success) {
|
||||||
Serial.println(F("Nuki paired"));
|
Serial.println(F("Nuki paired"));
|
||||||
_paired = true;
|
_paired = true;
|
||||||
}
|
}
|
||||||
@@ -90,6 +90,7 @@ void NukiWrapper::update()
|
|||||||
|
|
||||||
vTaskDelay( 20 / portTICK_PERIOD_MS);
|
vTaskDelay( 20 / portTICK_PERIOD_MS);
|
||||||
_bleScanner->update();
|
_bleScanner->update();
|
||||||
|
_nukiBle.updateConnectionState();
|
||||||
|
|
||||||
unsigned long ts = millis();
|
unsigned long ts = millis();
|
||||||
|
|
||||||
@@ -214,20 +215,6 @@ void NukiWrapper::updateAuthData()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//struct __attribute__((packed)) LogEntry {
|
|
||||||
// uint32_t index;
|
|
||||||
// uint16_t timeStampYear;
|
|
||||||
// uint8_t timeStampMonth;
|
|
||||||
// uint8_t timeStampDay;
|
|
||||||
// uint8_t timeStampHour;
|
|
||||||
// uint8_t timeStampMinute;
|
|
||||||
// uint8_t timeStampSecond;
|
|
||||||
// uint32_t authId;
|
|
||||||
// uint8_t name[32];
|
|
||||||
// LoggingType loggingType;
|
|
||||||
// uint8_t data[5];
|
|
||||||
//};
|
|
||||||
|
|
||||||
Nuki::LockAction NukiWrapper::lockActionToEnum(const char *str)
|
Nuki::LockAction NukiWrapper::lockActionToEnum(const char *str)
|
||||||
{
|
{
|
||||||
if(strcmp(str, "unlock") == 0) return Nuki::LockAction::Unlock;
|
if(strcmp(str, "unlock") == 0) return Nuki::LockAction::Unlock;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ class Publisher {
|
|||||||
public:
|
public:
|
||||||
virtual void subscribe(Subscriber* subscriber) = 0;
|
virtual void subscribe(Subscriber* subscriber) = 0;
|
||||||
virtual void unsubscribe(Subscriber* subscriber) = 0;
|
virtual void unsubscribe(Subscriber* subscriber) = 0;
|
||||||
|
virtual void enableScanning(bool enable) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace BleScanner
|
} // namespace BleScanner
|
||||||
|
|||||||
@@ -32,12 +32,23 @@ void Scanner::initialize(const std::string& deviceName, const bool wantDuplicate
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Scanner::update() {
|
void Scanner::update() {
|
||||||
if (bleScan->isScanning()) {
|
if (!scanningEnabled || bleScan->isScanning()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = bleScan->start(scanDuration, nullptr, false);
|
bool result = bleScan->start(scanDuration, nullptr, false);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
log_w("BLE Scan error");
|
scanErrors++;
|
||||||
|
if (scanErrors % 100 == 0) {
|
||||||
|
log_w("BLE Scan error (100x)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Scanner::enableScanning(bool enable) {
|
||||||
|
scanningEnabled = enable;
|
||||||
|
if (!enable) {
|
||||||
|
bleScan->stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* Created: 2022
|
* Created: 2022
|
||||||
* License: GNU GENERAL PUBLIC LICENSE (see LICENSE)
|
* License: GNU GENERAL PUBLIC LICENSE (see LICENSE)
|
||||||
*
|
*
|
||||||
* This library provides a BLE scanner to be used by other libraries to
|
* This library provides a BLE scanner to be used by other libraries to
|
||||||
* receive advertisements from BLE devices
|
* receive advertisements from BLE devices
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -44,10 +44,17 @@ class Scanner : public Publisher, BLEAdvertisedDeviceCallbacks {
|
|||||||
/**
|
/**
|
||||||
* @brief Set the Scan Duration
|
* @brief Set the Scan Duration
|
||||||
*
|
*
|
||||||
* @param value scan duration in seconds
|
* @param value scan duration in seconds, 0 for indefinite scan
|
||||||
*/
|
*/
|
||||||
void setScanDuration(const uint32_t value);
|
void setScanDuration(const uint32_t value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief enable/disable scanning
|
||||||
|
*
|
||||||
|
* @param enable
|
||||||
|
*/
|
||||||
|
void enableScanning(bool enable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Subscribe to the scanner and receive results
|
* @brief Subscribe to the scanner and receive results
|
||||||
*
|
*
|
||||||
@@ -73,6 +80,8 @@ class Scanner : public Publisher, BLEAdvertisedDeviceCallbacks {
|
|||||||
uint32_t scanDuration = 3;
|
uint32_t scanDuration = 3;
|
||||||
BLEScan* bleScan = nullptr;
|
BLEScan* bleScan = nullptr;
|
||||||
std::vector<Subscriber*> subscribers;
|
std::vector<Subscriber*> subscribers;
|
||||||
|
uint16_t scanErrors = 0;
|
||||||
|
bool scanningEnabled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace BleScanner
|
} // namespace BleScanner
|
||||||
|
|||||||
Submodule lib/nuki_ble updated: e9fca7b48d...24fb438d80
Reference in New Issue
Block a user