Nuki BLE ESP32
|
Note that generated documentation can be found here: https://i-connect.github.io/NukiBleEsp32/
This lib is made for communicating directly to a Nuki smart lock or a Nuki opener via BLE without the need of a Nuki Bridge. Implementation is according to Nuki Smart Lock BLE API (kudo's to the Nuki developers for providing such an accurate and well made documentation!)
From v0.0.5 onwards Implementation is based on Espressif platform version 4.x.x
This library makes use of BLE scanner to receive the Ble advertisements sent by Nuki devices and other Ble devices (https://github.com/I-Connect/BleScanner.git).
When running main.cpp
which includes the example NukiSmartLockTest.h (with #define DEBUG_NUKI_CONNECT) there will initially be some logging "No nuki in pairing mode found", if you then press and hold the button on the Nuki lock for 10 secs (until the led ring lights up) the ESP should automatically find the lock in pairing mode and pair with it. Credentials will be saved in a persistent Preference
store with store name equal to the devicename specified on construction of the NukiBle object. No pairing needs to be done the next time the ESP starts.
There are some example methods in NukiSmartLockTest.h
to get/write data and execute actions on the lock.
Be aware that if you have set a pincode on the lock you will have to store this in the esp using nukiLock.savePincode()
otherwise the methods that need a pincode (most methods that write settings) will fail. This only needs to be done once as the pincode will be stored in the preferences.
Logging can be enabled by setting the following defines (these are also available in platformio.ini):
Handler
class derived from Nuki::SmartlockEventHandler
which will implement the notify(Nuki::EventType eventType)
method. This method will be called by the BleScanner
when an advertisement has been receivedBleScanner::Scanner
and the Handler
Nuki::NukiBle
with a devicename and the id of the Nuki App, Nuki Bridge or Nuki Fob to be authorized.Handler
with the nukiLock
notify(Nuki::EventType eventType)
method as this runs in the BleScanner context and BLE is not able to handle this simultaniously Nuki::NukiLock nukiLock{deviceName, deviceId}; BleScanner::Scanner scanner; Handler handler; void setup() { scanner.initialize(); nukiLock.registerBleScanner(&scanner); nukiLock.initialize(); nukiLock.setEventHandler(&handler); } void loop() { scanner.update(); delay(10); // Terminate stale Bluetooth connections updateConnectionState(); }
The setup for the opener is very much the same as for the lock, except you create a NukiOpener object instead of a NukiLock object. Most functionality is shared between lock and opener, except for device-specific functionality.
For example:
CmdResult setAdvertisingMode(AdvertisingMode mode);
), this interval determines the battery drain on the lock). When the lock state is changed a parameter is changed in the advertisement. This causes SmartLockEventHandler::notify(...)
to be called and then you could initiate a follow up like requesting the keyturner state.const
qualifiers where needed