Nuki BLE ESP32
Loading...
Searching...
No Matches
Nuki::NukiBle Class Referenceabstract

#include <NukiBle.h>

+ Inheritance diagram for Nuki::NukiBle:
+ Collaboration diagram for Nuki::NukiBle:

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
 

Constructor & Destructor Documentation

◆ NukiBle()

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 )

◆ ~NukiBle()

Nuki::NukiBle::~NukiBle ( )
virtual

Member Function Documentation

◆ addAuthorizationEntry()

Nuki::CmdResult Nuki::NukiBle::addAuthorizationEntry ( NewAuthorizationEntry newAuthorizationEntry)

Sends a new authorization entry to the lock via BLE.

Parameters
newAuthorizationEntryNuki api based datatype to send
+ Here is the call graph for this function:

◆ addKeypadEntry()

Nuki::CmdResult Nuki::NukiBle::addKeypadEntry ( NewKeypadEntry newKeypadEntry)

Send a new keypad entry to the lock via BLE.

Parameters
newKeypadEntryNuki api based datatype to be sent Keypad Codes that start with 12 are not allowed 0 is not allowed Duplicates are not allowed
+ Here is the call graph for this function:

◆ cmdChallAccStateMachine()

template<typename TDeviceAction >
Nuki::CmdResult Nuki::NukiBle::cmdChallAccStateMachine ( const TDeviceAction action)
protected
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cmdChallStateMachine()

template<typename TDeviceAction >
Nuki::CmdResult Nuki::NukiBle::cmdChallStateMachine ( const TDeviceAction action,
const bool sendPinCode = false )
protected
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cmdStateMachine()

template<typename TDeviceAction >
Nuki::CmdResult Nuki::NukiBle::cmdStateMachine ( const TDeviceAction action)
protected
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ connectBle()

bool Nuki::NukiBle::connectBle ( const BLEAddress bleAddress,
bool pairing )
protected
+ Here is the caller graph for this function:

◆ deleteAuthorizationEntry()

Nuki::CmdResult Nuki::NukiBle::deleteAuthorizationEntry ( const uint32_t id)

Deletes the authorization entry from the lock.

Parameters
idid to be deleted
+ Here is the call graph for this function:

◆ deleteKeypadEntry()

CmdResult Nuki::NukiBle::deleteKeypadEntry ( uint16_t id)

Delete a Keypad Entry.

Parameters
idId to be deleted
+ Here is the call graph for this function:

◆ executeAction()

template<typename TDeviceAction >
Nuki::CmdResult Nuki::NukiBle::executeAction ( const TDeviceAction action)
protected
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ extendDisconnectTimeout()

void Nuki::NukiBle::extendDisconnectTimeout ( )
protected
+ Here is the caller graph for this function:

◆ getAuthorizationEntries()

void Nuki::NukiBle::getAuthorizationEntries ( std::list< AuthorizationEntry > * requestedAuthorizationEntries)

Get the Authorization Entries stored on the esp (after executing retreiveAuthorizationEntries)

Parameters
requestedAuthorizationEntrieslist to store the returned Authorization entries

◆ getBleAddress()

const BLEAddress Nuki::NukiBle::getBleAddress ( ) const

Returns the BLE address of the device if paired.

Returns
BLE address

◆ getKeypadEntries()

void Nuki::NukiBle::getKeypadEntries ( std::list< KeypadEntry > * requestedKeyPadEntries)

Get the Keypad Entries stored on the esp (after executing retreieveLogKeypadEntries)

Parameters
requestedKeyPadEntrieslist to store the returned Keypad entries

◆ getKeypadEntryCount()

uint16_t Nuki::NukiBle::getKeypadEntryCount ( )

Returns the keypad entry count. Only available after executing retreiveKeypadEntries.

+ Here is the caller graph for this function:

◆ getLastHeartbeat()

unsigned long Nuki::NukiBle::getLastHeartbeat ( )

Returns the timestamp (millis) of the last received BLE beacon from the lock.

Returns
Last heartbeat value

◆ getLastReceivedBeaconTs()

unsigned long Nuki::NukiBle::getLastReceivedBeaconTs ( ) const

Returns the timestamp in milliseconds when the last ble beacon has been received from the device.

Returns
Timestamp in milliseconds

◆ getLogEntryCount()

uint16_t Nuki::NukiBle::getLogEntryCount ( )

Returns the log entry count. Only available after executing retreiveLogEntries.

◆ getMacAddress()

void Nuki::NukiBle::getMacAddress ( char * macAddress)

Gets the ble mac address of the paired lock stored on the esp.

Returns
18 byte Char array with mac address

◆ getRssi()

int Nuki::NukiBle::getRssi ( ) const

Returns the RSSI of the last received ble beacon broadcast.

Returns
RSSI value

◆ getSecurityPincode()

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.

Returns
pincode

◆ handleReturnMessage()

void Nuki::NukiBle::handleReturnMessage ( Command returnCode,
unsigned char * data,
uint16_t dataLen )
protectedvirtual

Reimplemented in NukiLock::NukiLock, and NukiOpener::NukiOpener.

+ Here is the caller graph for this function:

◆ initialize()

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)

◆ isPairedWithLock()

const bool Nuki::NukiBle::isPairedWithLock ( ) const

Returns pairing state (if credentials are stored or not)

◆ logErrorCode()

virtual void Nuki::NukiBle::logErrorCode ( uint8_t errorCode)
protectedpure virtual

◆ pairNuki()

PairingResult Nuki::NukiBle::pairNuki ( AuthorizationIdType idType = AuthorizationIdType::Bridge)

Checks if credentials are stored in preferences, if not initiate pairing.

Returns
+ Here is the call graph for this function:

◆ registerBleScanner()

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.

Parameters
bleScannerthe publisher of the BLE scanner

◆ requestCalibration()

Nuki::CmdResult Nuki::NukiBle::requestCalibration ( )

Sends an calibration (mechanical) request to the lock via BLE.

+ Here is the call graph for this function:

◆ requestReboot()

Nuki::CmdResult Nuki::NukiBle::requestReboot ( )

Sends an reboot request to the lock via BLE.

+ Here is the call graph for this function:

◆ retrieveAuthorizationEntries()

Nuki::CmdResult Nuki::NukiBle::retrieveAuthorizationEntries ( const uint16_t offset,
const uint16_t count )

Request the lock via BLE to send the existing authorizationentries.

Parameters
offsetThe start offset to be read.
countThe number of entries to be read, starting at the specified offset.
+ Here is the call graph for this function:

◆ retrieveKeypadEntries()

Nuki::CmdResult Nuki::NukiBle::retrieveKeypadEntries ( const uint16_t offset,
const uint16_t count )

Request the lock via BLE to send the existing keypad entries.

Parameters
offsetThe start offset to be read.
countThe number of entries to be read, starting at the specified offset.
+ Here is the call graph for this function:

◆ saveSecurityPincode()

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.

Parameters
pinCode
Returns
true if stored successfully

◆ setConnectRetries()

void Nuki::NukiBle::setConnectRetries ( uint8_t retries)

Set the BLE Connect number of retries.

Parameters
retries

◆ setConnectTimeout()

void Nuki::NukiBle::setConnectTimeout ( uint8_t timeout)

Set the BLE Connect Timeout in seconds.

Parameters
timeout

◆ setDisconnectTimeout()

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.

Parameters
timeoutMs

◆ setEventHandler()

void Nuki::NukiBle::setEventHandler ( Nuki::SmartlockEventHandler * handler)

Set the Event Handler object.

Parameters
handlermethod to handle the event

◆ setPower()

void Nuki::NukiBle::setPower ( esp_power_level_t powerLevel)

the transmission power.

Parameters
[in]powerLevelThe power level to set, can be one of:
  • ESP_PWR_LVL_N12 = 0, Corresponding to -12dbm
  • ESP_PWR_LVL_N9 = 1, Corresponding to -9dbm
  • ESP_PWR_LVL_N6 = 2, Corresponding to -6dbm
  • ESP_PWR_LVL_N3 = 3, Corresponding to -3dbm
  • ESP_PWR_LVL_N0 = 4, Corresponding to 0dbm
  • ESP_PWR_LVL_P3 = 5, Corresponding to +3dbm
  • ESP_PWR_LVL_P6 = 6, Corresponding to +6dbm
  • ESP_PWR_LVL_P9 = 7, Corresponding to +9dbm

◆ setSecurityPin()

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)

Parameters
newSecurityPin
Returns
Nuki::CmdResult
+ Here is the call graph for this function:

◆ unPairNuki()

void Nuki::NukiBle::unPairNuki ( )

Delete stored credentials.

◆ updateAuthorizationEntry()

Nuki::CmdResult Nuki::NukiBle::updateAuthorizationEntry ( UpdatedAuthorizationEntry updatedAuthorizationEntry)

Sends an updated authorization entry to the lock via BLE.

Parameters
updatedAuthorizationEntryNuki api based datatype to send
+ Here is the call graph for this function:

◆ updateConnectionState()

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.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateKeypadEntry()

Nuki::CmdResult Nuki::NukiBle::updateKeypadEntry ( UpdatedKeypadEntry updatedKeyPadEntry)

Send an updated keypad entry to the lock via BLE.

Parameters
updatedKeypadEntryNuki api based datatype to be sent Keypad Codes that start with 12 are not allowed 0 is not allowed Duplicates are not allowed
+ Here is the call graph for this function:

◆ updateTime()

Nuki::CmdResult Nuki::NukiBle::updateTime ( TimeValue time)

Sends the time to be set to the lock via BLE.

Parameters
timeNuki api based datatype to send
+ Here is the call graph for this function:

◆ verifySecurityPin()

Nuki::CmdResult Nuki::NukiBle::verifySecurityPin ( )

Send the verify pincode command via BLE to the lock. This command uses the earlier by saveSecurityPincode() stored pincode.

Returns
Nuki::CmdResult returns success when the pin code is correct (same as stored in the lock)
+ Here is the call graph for this function:

Member Data Documentation

◆ errorCode

uint8_t Nuki::NukiBle::errorCode = 0
protected

◆ lastMsgCodeReceived

Command Nuki::NukiBle::lastMsgCodeReceived = Command::Empty
protected

The documentation for this class was generated from the following files: