Nuki BLE ESP32
|
#include <NukiBle.h>
Public Member Functions | |
NukiBle (const std::string &deviceName, const uint32_t deviceId, const NimBLEUUID pairingServiceUUID, const NimBLEUUID deviceServiceUUID, const NimBLEUUID gdioUUID, const NimBLEUUID userDataUUID, const std::string preferencedId) | |
virtual | ~NukiBle () |
Nuki::CmdResult | addAuthorizationEntry (NewAuthorizationEntry newAuthorizationEntry) |
Sends a new authorization entry to the lock via BLE. | |
Nuki::CmdResult | addKeypadEntry (NewKeypadEntry newKeypadEntry) |
Send a new keypad entry to the lock via BLE. | |
Nuki::CmdResult | deleteAuthorizationEntry (const uint32_t id) |
Deletes the authorization entry from the lock. | |
CmdResult | deleteKeypadEntry (uint16_t id) |
Delete a Keypad Entry. | |
void | getAuthorizationEntries (std::list< AuthorizationEntry > *requestedAuthorizationEntries) |
Get the Authorization Entries stored on the esp (after executing retreiveAuthorizationEntries) | |
const BLEAddress | getBleAddress () const |
Returns the BLE address of the device if paired. | |
void | getKeypadEntries (std::list< KeypadEntry > *requestedKeyPadEntries) |
Get the Keypad Entries stored on the esp (after executing retreieveLogKeypadEntries) | |
uint16_t | getKeypadEntryCount () |
Returns the keypad entry count. Only available after executing retreiveKeypadEntries. | |
unsigned long | getLastHeartbeat () |
Returns the timestamp (millis) of the last received BLE beacon from the lock. | |
unsigned long | getLastReceivedBeaconTs () const |
Returns the timestamp in milliseconds when the last ble beacon has been received from the device. | |
uint16_t | getLogEntryCount () |
Returns the log entry count. Only available after executing retreiveLogEntries. | |
void | getMacAddress (char *macAddress) |
Gets the ble mac address of the paired lock stored on the esp. | |
int | getRssi () const |
Returns the RSSI of the last received ble beacon broadcast. | |
uint16_t | getSecurityPincode () |
Gets the pincode stored on the esp. This pincode is used for sending/setting config via BLE to the lock by other methods and needs to be the same pincode as stored in the lock. | |
void | initialize () |
Initializes stored preferences based on the devicename passed in the constructor, creates the BLE client, sets the BLE callback and checks if the lock is paired (if credentials are stored in preferences) | |
const bool | isPairedWithLock () const |
Returns pairing state (if credentials are stored or not) | |
Nuki::PairingResult | pairNuki (AuthorizationIdType idType=AuthorizationIdType::Bridge) |
Checks if credentials are stored in preferences, if not initiate pairing. | |
void | registerBleScanner (BleScanner::Publisher *bleScanner) |
Registers the BLE scanner to be used for scanning for advertisements from the lock. BleScanner::Publisher is defined in dependent library https://github.com/I-Connect/BleScanner.git. | |
Nuki::CmdResult | requestCalibration () |
Sends an calibration (mechanical) request to the lock via BLE. | |
Nuki::CmdResult | requestReboot () |
Sends an reboot request to the lock via BLE. | |
Nuki::CmdResult | retrieveAuthorizationEntries (const uint16_t offset, const uint16_t count) |
Request the lock via BLE to send the existing authorizationentries. | |
Nuki::CmdResult | retrieveKeypadEntries (const uint16_t offset, const uint16_t count) |
Request the lock via BLE to send the existing keypad entries. | |
bool | saveSecurityPincode (const uint16_t pinCode) |
Saves the pincode on the esp. This pincode is used for sending/setting config via BLE to the lock by other methods and needs to be the same pincode as stored in the lock. | |
void | setConnectRetries (uint8_t retries) |
Set the BLE Connect number of retries. | |
void | setConnectTimeout (uint8_t timeout) |
Set the BLE Connect Timeout in seconds. | |
void | setDisconnectTimeout (uint32_t timeoutMs) |
Set the BLE Disconnect Timeout, if longer than ~20 sec the lock will disconnect by itself if there is no BLE communication. | |
void | setEventHandler (Nuki::SmartlockEventHandler *handler) |
Set the Event Handler object. | |
void | setPower (esp_power_level_t powerLevel) |
the transmission power. | |
Nuki::CmdResult | setSecurityPin (const uint16_t newSecurityPin) |
Send the new pincode command to the lock via BLE (this command uses the earlier by saveSecurityPincode() stored pincode which needs to be the same as the pincode stored in the lock) | |
void | unPairNuki () |
Delete stored credentials. | |
Nuki::CmdResult | updateAuthorizationEntry (UpdatedAuthorizationEntry updatedAuthorizationEntry) |
Sends an updated authorization entry to the lock via BLE. | |
void | updateConnectionState () |
checks the time past after last connect/communication sent, if the time past > timeout it will disconnect the BLE connection with the lock so that lock will start sending advertisements. | |
Nuki::CmdResult | updateKeypadEntry (UpdatedKeypadEntry updatedKeyPadEntry) |
Send an updated keypad entry to the lock via BLE. | |
Nuki::CmdResult | updateTime (TimeValue time) |
Sends the time to be set to the lock via BLE. | |
Nuki::CmdResult | verifySecurityPin () |
Send the verify pincode command via BLE to the lock. This command uses the earlier by saveSecurityPincode() stored pincode. | |
Protected Member Functions | |
template<typename TDeviceAction > | |
Nuki::CmdResult | cmdChallAccStateMachine (const TDeviceAction action) |
template<typename TDeviceAction > | |
Nuki::CmdResult | cmdChallStateMachine (const TDeviceAction action, const bool sendPinCode=false) |
template<typename TDeviceAction > | |
Nuki::CmdResult | cmdStateMachine (const TDeviceAction action) |
bool | connectBle (const BLEAddress bleAddress, bool pairing) |
template<typename TDeviceAction > | |
Nuki::CmdResult | executeAction (const TDeviceAction action) |
void | extendDisconnectTimeout () |
virtual void | handleReturnMessage (Command returnCode, unsigned char *data, uint16_t dataLen) |
virtual void | logErrorCode (uint8_t errorCode)=0 |
Protected Attributes | |
uint8_t | errorCode = 0 |
Command | lastMsgCodeReceived = Command::Empty |
Nuki::NukiBle::NukiBle | ( | const std::string & | deviceName, |
const uint32_t | deviceId, | ||
const NimBLEUUID | pairingServiceUUID, | ||
const NimBLEUUID | deviceServiceUUID, | ||
const NimBLEUUID | gdioUUID, | ||
const NimBLEUUID | userDataUUID, | ||
const std::string | preferencedId ) |
|
virtual |
Nuki::CmdResult Nuki::NukiBle::addAuthorizationEntry | ( | NewAuthorizationEntry | newAuthorizationEntry | ) |
Sends a new authorization entry to the lock via BLE.
newAuthorizationEntry | Nuki api based datatype to send |
Nuki::CmdResult Nuki::NukiBle::addKeypadEntry | ( | NewKeypadEntry | newKeypadEntry | ) |
Send a new keypad entry to the lock via BLE.
newKeypadEntry | Nuki api based datatype to be sent Keypad Codes that start with 12 are not allowed 0 is not allowed Duplicates are not allowed |
|
protected |
|
protected |
|
protected |
|
protected |
Nuki::CmdResult Nuki::NukiBle::deleteAuthorizationEntry | ( | const uint32_t | id | ) |
Deletes the authorization entry from the lock.
id | id to be deleted |
CmdResult Nuki::NukiBle::deleteKeypadEntry | ( | uint16_t | id | ) |
Delete a Keypad Entry.
id | Id to be deleted |
|
protected |
|
protected |
void Nuki::NukiBle::getAuthorizationEntries | ( | std::list< AuthorizationEntry > * | requestedAuthorizationEntries | ) |
Get the Authorization Entries stored on the esp (after executing retreiveAuthorizationEntries)
requestedAuthorizationEntries | list to store the returned Authorization entries |
const BLEAddress Nuki::NukiBle::getBleAddress | ( | ) | const |
Returns the BLE address of the device if paired.
void Nuki::NukiBle::getKeypadEntries | ( | std::list< KeypadEntry > * | requestedKeyPadEntries | ) |
Get the Keypad Entries stored on the esp (after executing retreieveLogKeypadEntries)
requestedKeyPadEntries | list to store the returned Keypad entries |
uint16_t Nuki::NukiBle::getKeypadEntryCount | ( | ) |
Returns the keypad entry count. Only available after executing retreiveKeypadEntries.
unsigned long Nuki::NukiBle::getLastHeartbeat | ( | ) |
Returns the timestamp (millis) of the last received BLE beacon from the lock.
unsigned long Nuki::NukiBle::getLastReceivedBeaconTs | ( | ) | const |
Returns the timestamp in milliseconds when the last ble beacon has been received from the device.
uint16_t Nuki::NukiBle::getLogEntryCount | ( | ) |
Returns the log entry count. Only available after executing retreiveLogEntries.
void Nuki::NukiBle::getMacAddress | ( | char * | macAddress | ) |
Gets the ble mac address of the paired lock stored on the esp.
int Nuki::NukiBle::getRssi | ( | ) | const |
Returns the RSSI of the last received ble beacon broadcast.
uint16_t Nuki::NukiBle::getSecurityPincode | ( | ) |
Gets the pincode stored on the esp. This pincode is used for sending/setting config via BLE to the lock by other methods and needs to be the same pincode as stored in the lock.
|
protectedvirtual |
Reimplemented in NukiLock::NukiLock, and NukiOpener::NukiOpener.
void Nuki::NukiBle::initialize | ( | ) |
Initializes stored preferences based on the devicename passed in the constructor, creates the BLE client, sets the BLE callback and checks if the lock is paired (if credentials are stored in preferences)
const bool Nuki::NukiBle::isPairedWithLock | ( | ) | const |
Returns pairing state (if credentials are stored or not)
|
protectedpure virtual |
Implemented in NukiLock::NukiLock, and NukiOpener::NukiOpener.
PairingResult Nuki::NukiBle::pairNuki | ( | AuthorizationIdType | idType = AuthorizationIdType::Bridge | ) |
Checks if credentials are stored in preferences, if not initiate pairing.
void Nuki::NukiBle::registerBleScanner | ( | BleScanner::Publisher * | bleScanner | ) |
Registers the BLE scanner to be used for scanning for advertisements from the lock. BleScanner::Publisher is defined in dependent library https://github.com/I-Connect/BleScanner.git.
bleScanner | the publisher of the BLE scanner |
Nuki::CmdResult Nuki::NukiBle::requestCalibration | ( | ) |
Sends an calibration (mechanical) request to the lock via BLE.
Nuki::CmdResult Nuki::NukiBle::requestReboot | ( | ) |
Sends an reboot request to the lock via BLE.
Nuki::CmdResult Nuki::NukiBle::retrieveAuthorizationEntries | ( | const uint16_t | offset, |
const uint16_t | count ) |
Request the lock via BLE to send the existing authorizationentries.
offset | The start offset to be read. |
count | The number of entries to be read, starting at the specified offset. |
Nuki::CmdResult Nuki::NukiBle::retrieveKeypadEntries | ( | const uint16_t | offset, |
const uint16_t | count ) |
Request the lock via BLE to send the existing keypad entries.
offset | The start offset to be read. |
count | The number of entries to be read, starting at the specified offset. |
bool Nuki::NukiBle::saveSecurityPincode | ( | const uint16_t | pinCode | ) |
Saves the pincode on the esp. This pincode is used for sending/setting config via BLE to the lock by other methods and needs to be the same pincode as stored in the lock.
pinCode |
void Nuki::NukiBle::setConnectRetries | ( | uint8_t | retries | ) |
Set the BLE Connect number of retries.
retries |
void Nuki::NukiBle::setConnectTimeout | ( | uint8_t | timeout | ) |
Set the BLE Connect Timeout in seconds.
timeout |
void Nuki::NukiBle::setDisconnectTimeout | ( | uint32_t | timeoutMs | ) |
Set the BLE Disconnect Timeout, if longer than ~20 sec the lock will disconnect by itself if there is no BLE communication.
timeoutMs |
void Nuki::NukiBle::setEventHandler | ( | Nuki::SmartlockEventHandler * | handler | ) |
Set the Event Handler object.
handler | method to handle the event |
void Nuki::NukiBle::setPower | ( | esp_power_level_t | powerLevel | ) |
the transmission power.
[in] | powerLevel | The power level to set, can be one of:
|
Nuki::CmdResult Nuki::NukiBle::setSecurityPin | ( | const uint16_t | newSecurityPin | ) |
Send the new pincode command to the lock via BLE (this command uses the earlier by saveSecurityPincode() stored pincode which needs to be the same as the pincode stored in the lock)
newSecurityPin |
void Nuki::NukiBle::unPairNuki | ( | ) |
Delete stored credentials.
Nuki::CmdResult Nuki::NukiBle::updateAuthorizationEntry | ( | UpdatedAuthorizationEntry | updatedAuthorizationEntry | ) |
Sends an updated authorization entry to the lock via BLE.
updatedAuthorizationEntry | Nuki api based datatype to send |
void Nuki::NukiBle::updateConnectionState | ( | ) |
checks the time past after last connect/communication sent, if the time past > timeout it will disconnect the BLE connection with the lock so that lock will start sending advertisements.
This method is optional since the lock will automatically disconnect after approximately 20 seconds. However, the lock might be unresponsive during this time if the connection is stale. For this reason, using this method is advised. If used, this method should be run in loop or a task.
Nuki::CmdResult Nuki::NukiBle::updateKeypadEntry | ( | UpdatedKeypadEntry | updatedKeyPadEntry | ) |
Send an updated keypad entry to the lock via BLE.
updatedKeypadEntry | Nuki api based datatype to be sent Keypad Codes that start with 12 are not allowed 0 is not allowed Duplicates are not allowed |
Nuki::CmdResult Nuki::NukiBle::updateTime | ( | TimeValue | time | ) |
Sends the time to be set to the lock via BLE.
time | Nuki api based datatype to send |
Nuki::CmdResult Nuki::NukiBle::verifySecurityPin | ( | ) |
Send the verify pincode command via BLE to the lock. This command uses the earlier by saveSecurityPincode() stored pincode.
|
protected |
|
protected |