update ble lib
This commit is contained in:
@@ -18,7 +18,7 @@ file(GLOB SRCFILES
|
||||
# "Lib/FreeRTOS/src/*.c"
|
||||
# "Lib/FreeRTOS/src/*.cpp"
|
||||
Network.cpp
|
||||
Nuki.cpp
|
||||
NukiWrapper.cpp
|
||||
MqttTopics.h
|
||||
WebCfgServer.cpp
|
||||
PreferencesKeys.h
|
||||
@@ -28,7 +28,8 @@ file(GLOB SRCFILES
|
||||
lib/Crc16/Crc16.h
|
||||
lib/nuki_ble/src/NukiBle.cpp
|
||||
lib/nuki_ble/src/NukiConstants.h
|
||||
lib/nuki_ble/src/NukiUtills.h
|
||||
lib/nuki_ble/src/NukiDataTypes.cpp
|
||||
lib/nuki_ble/src/NukiUtils.cpp
|
||||
lib/nuki_ble/src/BleScanner.cpp
|
||||
include_directories(Lib/PubSubClient)
|
||||
lib/pubsubclient/src/PubSubClient.cpp
|
||||
|
||||
@@ -127,7 +127,7 @@ void Network::onMqttDataReceived(char *&topic, byte *&payload, unsigned int &len
|
||||
{
|
||||
if(strcmp(value, "") == 0) return;
|
||||
|
||||
Serial.print(F("Lockstate action received: "));
|
||||
Serial.print(F("Lock action received: "));
|
||||
Serial.println(value);
|
||||
if(_lockActionReceivedCallback != NULL)
|
||||
{
|
||||
@@ -137,7 +137,7 @@ void Network::onMqttDataReceived(char *&topic, byte *&payload, unsigned int &len
|
||||
}
|
||||
}
|
||||
|
||||
void Network::publishKeyTurnerState(const KeyTurnerState& keyTurnerState, const KeyTurnerState& lastKeyTurnerState)
|
||||
void Network::publishKeyTurnerState(const Nuki::KeyTurnerState& keyTurnerState, const Nuki::KeyTurnerState& lastKeyTurnerState)
|
||||
{
|
||||
char str[50];
|
||||
|
||||
@@ -180,7 +180,7 @@ void Network::publishKeyTurnerState(const KeyTurnerState& keyTurnerState, const
|
||||
}
|
||||
}
|
||||
|
||||
void Network::publishBatteryReport(const BatteryReport& batteryReport)
|
||||
void Network::publishBatteryReport(const Nuki::BatteryReport& batteryReport)
|
||||
{
|
||||
publishFloat(mqtt_topic_battery_voltage, (float)batteryReport.batteryVoltage / 1000.0);
|
||||
publishInt(mqtt_topic_battery_drain, batteryReport.batteryDrain); // milliwatt seconds
|
||||
|
||||
@@ -16,8 +16,8 @@ public:
|
||||
|
||||
bool isMqttConnected();
|
||||
|
||||
void publishKeyTurnerState(const KeyTurnerState& keyTurnerState, const KeyTurnerState& lastKeyTurnerState);
|
||||
void publishBatteryReport(const BatteryReport& batteryReport);
|
||||
void publishKeyTurnerState(const Nuki::KeyTurnerState& keyTurnerState, const Nuki::KeyTurnerState& lastKeyTurnerState);
|
||||
void publishBatteryReport(const Nuki::BatteryReport& batteryReport);
|
||||
|
||||
void setLockActionReceived(void (*lockActionReceivedCallback)(const char* value));
|
||||
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
#include "Nuki.h"
|
||||
#include "NukiWrapper.h"
|
||||
#include <FreeRTOS.h>
|
||||
#include "PreferencesKeys.h"
|
||||
|
||||
Nuki* nukiInst;
|
||||
NukiWrapper* nukiInst;
|
||||
|
||||
Nuki::Nuki(const std::string& name, uint32_t id, Network* network, Preferences* preferences)
|
||||
NukiWrapper::NukiWrapper(const std::string& name, uint32_t id, Network* network, Preferences* preferences)
|
||||
: _nukiBle(name, id),
|
||||
_network(network),
|
||||
_preferences(preferences)
|
||||
{
|
||||
nukiInst = this;
|
||||
|
||||
memset(&_keyTurnerState, sizeof(KeyTurnerState), 0);
|
||||
memset(&_lastKeyTurnerState, sizeof(KeyTurnerState), 0);
|
||||
memset(&_lastBatteryReport, sizeof(BatteryReport), 0);
|
||||
memset(&_batteryReport, sizeof(BatteryReport), 0);
|
||||
memset(&_keyTurnerState, sizeof(Nuki::KeyTurnerState), 0);
|
||||
memset(&_lastKeyTurnerState, sizeof(Nuki::KeyTurnerState), 0);
|
||||
memset(&_lastBatteryReport, sizeof(Nuki::BatteryReport), 0);
|
||||
memset(&_batteryReport, sizeof(Nuki::BatteryReport), 0);
|
||||
|
||||
network->setLockActionReceived(nukiInst->onLockActionReceived);
|
||||
}
|
||||
|
||||
void Nuki::initialize()
|
||||
void NukiWrapper::initialize()
|
||||
{
|
||||
_bleScanner.initialize();
|
||||
_nukiBle.initialize();
|
||||
@@ -43,11 +43,11 @@ void Nuki::initialize()
|
||||
|
||||
Serial.print(F("Lock state interval: "));
|
||||
Serial.print(_intervalLockstate);
|
||||
Serial.print(F("| Battery interval: "));
|
||||
Serial.print(F(" | Battery interval: "));
|
||||
Serial.println(_intervalBattery);
|
||||
}
|
||||
|
||||
void Nuki::update()
|
||||
void NukiWrapper::update()
|
||||
{
|
||||
if (!_paired) {
|
||||
Serial.println(F("Nuki start pairing"));
|
||||
@@ -79,20 +79,20 @@ void Nuki::update()
|
||||
_nextBatteryReportTs = ts + _intervalBattery * 1000;
|
||||
updateBatteryState();
|
||||
}
|
||||
if(_nextLockAction != (LockAction)0xff)
|
||||
if(_nextLockAction != (Nuki::LockAction)0xff)
|
||||
{
|
||||
_nukiBle.lockAction(_nextLockAction, 0, 0);
|
||||
_nextLockAction = (LockAction)0xff;
|
||||
_nextLockAction = (Nuki::LockAction)0xff;
|
||||
if(_intervalLockstate > 10 * 1000)
|
||||
{
|
||||
_nextLockStateUpdateTs = ts + 10 * 1000;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(&_lastKeyTurnerState, &_keyTurnerState, sizeof(KeyTurnerState));
|
||||
memcpy(&_lastKeyTurnerState, &_keyTurnerState, sizeof(Nuki::KeyTurnerState));
|
||||
}
|
||||
|
||||
void Nuki::updateKeyTurnerState()
|
||||
void NukiWrapper::updateKeyTurnerState()
|
||||
{
|
||||
_nukiBle.requestKeyTurnerState(&_keyTurnerState);
|
||||
_network->publishKeyTurnerState(_keyTurnerState, _lastKeyTurnerState);
|
||||
@@ -106,7 +106,7 @@ void Nuki::updateKeyTurnerState()
|
||||
}
|
||||
}
|
||||
|
||||
void Nuki::updateBatteryState()
|
||||
void NukiWrapper::updateBatteryState()
|
||||
{
|
||||
_nukiBle.requestBatteryReport(&_batteryReport);
|
||||
|
||||
@@ -122,33 +122,33 @@ void Nuki::updateBatteryState()
|
||||
_network->publishBatteryReport(_batteryReport);
|
||||
}
|
||||
|
||||
LockAction Nuki::lockActionToEnum(const char *str)
|
||||
Nuki::LockAction NukiWrapper::lockActionToEnum(const char *str)
|
||||
{
|
||||
if(strcmp(str, "unlock") == 0) return LockAction::unlock;
|
||||
else if(strcmp(str, "lock") == 0) return LockAction::lock;
|
||||
else if(strcmp(str, "unlatch") == 0) return LockAction::unlatch;
|
||||
else if(strcmp(str, "lockNgo") == 0) return LockAction::lockNgo;
|
||||
else if(strcmp(str, "lockNgoUnlatch") == 0) return LockAction::lockNgoUnlatch;
|
||||
else if(strcmp(str, "fullLock") == 0) return LockAction::fullLock;
|
||||
else if(strcmp(str, "fobAction2") == 0) return LockAction::fobAction2;
|
||||
else if(strcmp(str, "fobAction1") == 0) return LockAction::fobAction1;
|
||||
else if(strcmp(str, "fobAction3") == 0) return LockAction::fobAction3;
|
||||
return (LockAction)0xff;
|
||||
if(strcmp(str, "unlock") == 0) return Nuki::LockAction::Unlock;
|
||||
else if(strcmp(str, "lock") == 0) return Nuki::LockAction::Lock;
|
||||
else if(strcmp(str, "unlatch") == 0) return Nuki::LockAction::Unlatch;
|
||||
else if(strcmp(str, "lockNgo") == 0) return Nuki::LockAction::LockNgo;
|
||||
else if(strcmp(str, "lockNgoUnlatch") == 0) return Nuki::LockAction::LockNgoUnlatch;
|
||||
else if(strcmp(str, "fullLock") == 0) return Nuki::LockAction::FullLock;
|
||||
else if(strcmp(str, "fobAction2") == 0) return Nuki::LockAction::FobAction2;
|
||||
else if(strcmp(str, "fobAction1") == 0) return Nuki::LockAction::FobAction1;
|
||||
else if(strcmp(str, "fobAction3") == 0) return Nuki::LockAction::FobAction3;
|
||||
return (Nuki::LockAction)0xff;
|
||||
}
|
||||
|
||||
void Nuki::onLockActionReceived(const char *value)
|
||||
void NukiWrapper::onLockActionReceived(const char *value)
|
||||
{
|
||||
nukiInst->_nextLockAction = nukiInst->lockActionToEnum(value);
|
||||
}
|
||||
|
||||
const bool Nuki::isPaired()
|
||||
const bool NukiWrapper::isPaired()
|
||||
{
|
||||
return _paired;
|
||||
}
|
||||
|
||||
void Nuki::notify(NukiEventType eventType)
|
||||
void NukiWrapper::notify(Nuki::EventType eventType)
|
||||
{
|
||||
if(eventType == NukiEventType::KeyTurnerStatusUpdated)
|
||||
if(eventType == Nuki::EventType::KeyTurnerStatusUpdated)
|
||||
{
|
||||
_statusUpdated = true;
|
||||
}
|
||||
@@ -3,18 +3,19 @@
|
||||
#include "NukiBle.h"
|
||||
#include "Network.h"
|
||||
#include "NukiConstants.h"
|
||||
#include "NukiDataTypes.h"
|
||||
|
||||
class Nuki : public NukiSmartlockEventHandler
|
||||
class NukiWrapper : public Nuki::SmartlockEventHandler
|
||||
{
|
||||
public:
|
||||
Nuki(const std::string& name, uint32_t id, Network* network, Preferences* preferences);
|
||||
NukiWrapper(const std::string& name, uint32_t id, Network* network, Preferences* preferences);
|
||||
|
||||
void initialize();
|
||||
void update();
|
||||
|
||||
const bool isPaired();
|
||||
|
||||
void notify(NukiEventType eventType) override;
|
||||
void notify(Nuki::EventType eventType) override;
|
||||
|
||||
private:
|
||||
static void onLockActionReceived(const char* value);
|
||||
@@ -22,24 +23,24 @@ private:
|
||||
void updateKeyTurnerState();
|
||||
void updateBatteryState();
|
||||
|
||||
LockAction lockActionToEnum(const char* str); // char array at least 14 characters
|
||||
Nuki::LockAction lockActionToEnum(const char* str); // char array at least 14 characters
|
||||
|
||||
NukiBle _nukiBle;
|
||||
Nuki::NukiBle _nukiBle;
|
||||
BleScanner _bleScanner;
|
||||
Network* _network;
|
||||
Preferences* _preferences;
|
||||
int _intervalLockstate = 0; // seconds
|
||||
int _intervalBattery = 0; // seconds
|
||||
|
||||
KeyTurnerState _lastKeyTurnerState;
|
||||
KeyTurnerState _keyTurnerState;
|
||||
Nuki::KeyTurnerState _lastKeyTurnerState;
|
||||
Nuki::KeyTurnerState _keyTurnerState;
|
||||
|
||||
BatteryReport _batteryReport;
|
||||
BatteryReport _lastBatteryReport;
|
||||
Nuki::BatteryReport _batteryReport;
|
||||
Nuki::BatteryReport _lastBatteryReport;
|
||||
|
||||
bool _paired = false;
|
||||
bool _statusUpdated = false;
|
||||
unsigned long _nextLockStateUpdateTs = 0;
|
||||
unsigned long _nextBatteryReportTs = 0;
|
||||
LockAction _nextLockAction = (LockAction)0xff;
|
||||
Nuki::LockAction _nextLockAction = (Nuki::LockAction)0xff;
|
||||
};
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <WiFiClient.h>
|
||||
#include "PreferencesKeys.h"
|
||||
|
||||
WebCfgServer::WebCfgServer(Nuki* nuki, Network* network, Preferences* preferences)
|
||||
WebCfgServer::WebCfgServer(NukiWrapper* nuki, Network* network, Preferences* preferences)
|
||||
: _wifiServer(80),
|
||||
_nuki(nuki),
|
||||
_network(network),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <WiFiServer.h>
|
||||
#include <Preferences.h>
|
||||
#include "Nuki.h"
|
||||
#include "NukiWrapper.h"
|
||||
#include "Network.h"
|
||||
|
||||
enum class TokenType
|
||||
@@ -17,7 +17,7 @@ enum class TokenType
|
||||
class WebCfgServer
|
||||
{
|
||||
public:
|
||||
WebCfgServer(Nuki* nuki, Network* network, Preferences* preferences);
|
||||
WebCfgServer(NukiWrapper* nuki, Network* network, Preferences* preferences);
|
||||
~WebCfgServer() = default;
|
||||
|
||||
void initialize();
|
||||
@@ -30,7 +30,7 @@ private:
|
||||
TokenType getParameterType(char*& token);
|
||||
|
||||
WiFiServer _wifiServer;
|
||||
Nuki* _nuki;
|
||||
NukiWrapper* _nuki;
|
||||
Network* _network;
|
||||
Preferences* _preferences;
|
||||
|
||||
|
||||
Submodule lib/nuki_ble updated: 8e7fd1ded1...a5239ad575
6
main.cpp
6
main.cpp
@@ -1,5 +1,5 @@
|
||||
#include "Arduino.h"
|
||||
#include "Nuki.h"
|
||||
#include "NukiWrapper.h"
|
||||
#include "Network.h"
|
||||
#include "WebCfgServer.h"
|
||||
#include <FreeRTOS.h>
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
Network* network;
|
||||
WebCfgServer* webCfgServer;
|
||||
Nuki* nuki;
|
||||
NukiWrapper* nuki;
|
||||
Preferences* preferences;
|
||||
|
||||
void networkTask(void *pvParameters)
|
||||
@@ -39,7 +39,7 @@ void setup()
|
||||
preferences = new Preferences();
|
||||
preferences->begin("nukihub", false);
|
||||
network = new Network(preferences);
|
||||
nuki = new Nuki("Main Door", 2020001, network, preferences);
|
||||
nuki = new NukiWrapper("Main Door", 2020001, network, preferences);
|
||||
webCfgServer = new WebCfgServer(nuki, network, preferences);
|
||||
|
||||
network->initialize();
|
||||
|
||||
Reference in New Issue
Block a user