show pairing and mqtt status in configuration page
This commit is contained in:
@@ -68,6 +68,7 @@ bool Network::reconnect()
|
|||||||
// Attempt to connect
|
// Attempt to connect
|
||||||
if (_mqttClient.connect("nukiHub")) {
|
if (_mqttClient.connect("nukiHub")) {
|
||||||
Serial.println(F("MQTT connected"));
|
Serial.println(F("MQTT connected"));
|
||||||
|
_mqttConnected = true;
|
||||||
|
|
||||||
// ... and resubscribe
|
// ... and resubscribe
|
||||||
_mqttClient.subscribe(mqtt_topic_lockstate_action);
|
_mqttClient.subscribe(mqtt_topic_lockstate_action);
|
||||||
@@ -76,12 +77,13 @@ bool Network::reconnect()
|
|||||||
{
|
{
|
||||||
Serial.print(F("MQTT connect failed, rc="));
|
Serial.print(F("MQTT connect failed, rc="));
|
||||||
Serial.println(_mqttClient.state());
|
Serial.println(_mqttClient.state());
|
||||||
|
_mqttConnected = false;
|
||||||
_nextReconnect = millis() + 5000;
|
_nextReconnect = millis() + 5000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return _mqttConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Network::update()
|
void Network::update()
|
||||||
{
|
{
|
||||||
if(!WiFi.isConnected())
|
if(!WiFi.isConnected())
|
||||||
@@ -167,3 +169,8 @@ void Network::publishInt(const char *topic, const int value)
|
|||||||
itoa(value, str, 10);
|
itoa(value, str, 10);
|
||||||
_mqttClient.publish(topic, str);
|
_mqttClient.publish(topic, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Network::isMqttConnected()
|
||||||
|
{
|
||||||
|
return _mqttConnected;
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ public:
|
|||||||
void initialize();
|
void initialize();
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
bool isMqttConnected();
|
||||||
|
|
||||||
void publishKeyTurnerState(const char* state, const char* trigger, const char* completionStatus);
|
void publishKeyTurnerState(const char* state, const char* trigger, const char* completionStatus);
|
||||||
void publishBatteryReport(const BatteryReport& batteryReport);
|
void publishBatteryReport(const BatteryReport& batteryReport);
|
||||||
|
|
||||||
@@ -32,6 +34,8 @@ private:
|
|||||||
WiFiClient _wifiClient;
|
WiFiClient _wifiClient;
|
||||||
Preferences* _preferences;
|
Preferences* _preferences;
|
||||||
|
|
||||||
|
bool _mqttConnected = false;
|
||||||
|
|
||||||
unsigned long _nextReconnect = 0;
|
unsigned long _nextReconnect = 0;
|
||||||
char _mqttBrokerAddr[100] = {0};
|
char _mqttBrokerAddr[100] = {0};
|
||||||
|
|
||||||
|
|||||||
5
Nuki.cpp
5
Nuki.cpp
@@ -251,3 +251,8 @@ void Nuki::onLockActionReceived(const char *value)
|
|||||||
Serial.print(F("Action: "));
|
Serial.print(F("Action: "));
|
||||||
Serial.println((int)nukiInst->_nextLockAction);
|
Serial.println((int)nukiInst->_nextLockAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool Nuki::isPaired()
|
||||||
|
{
|
||||||
|
return _paired;
|
||||||
|
}
|
||||||
|
|||||||
2
Nuki.h
2
Nuki.h
@@ -12,6 +12,8 @@ public:
|
|||||||
void initialize();
|
void initialize();
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
const bool isPaired();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void onLockActionReceived(const char* value);
|
static void onLockActionReceived(const char* value);
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
#include "PreferencesKeys.h"
|
#include "PreferencesKeys.h"
|
||||||
|
|
||||||
WebCfgServer::WebCfgServer(Preferences* preferences)
|
WebCfgServer::WebCfgServer(Nuki* nuki, Network* network, Preferences* preferences)
|
||||||
: _wifiServer(80),
|
: _wifiServer(80),
|
||||||
|
_nuki(nuki),
|
||||||
|
_network(network),
|
||||||
_preferences(preferences)
|
_preferences(preferences)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -112,6 +114,16 @@ void WebCfgServer::serveHtml(WiFiClient &client)
|
|||||||
client.println("</HEAD>");
|
client.println("</HEAD>");
|
||||||
client.println("<BODY>");
|
client.println("<BODY>");
|
||||||
|
|
||||||
|
|
||||||
|
client.println("<br><br><h3>");
|
||||||
|
client.print("Paired: ");
|
||||||
|
client.println(_nuki->isPaired() ? "Yes" : "No");
|
||||||
|
client.println("</h3>");
|
||||||
|
client.println("<h3>");
|
||||||
|
client.print("MQTT Connected: ");
|
||||||
|
client.println(_network->isMqttConnected() ? "Yes" : "No");
|
||||||
|
client.println("</h3><br><br>");
|
||||||
|
|
||||||
client.println("<FORM ACTION=method=get >");
|
client.println("<FORM ACTION=method=get >");
|
||||||
|
|
||||||
client.print("MQTT Broker: <INPUT TYPE=TEXT VALUE=\"");
|
client.print("MQTT Broker: <INPUT TYPE=TEXT VALUE=\"");
|
||||||
@@ -130,7 +142,7 @@ void WebCfgServer::serveHtml(WiFiClient &client)
|
|||||||
client.print(_preferences->getInt(preference_query_interval_battery));
|
client.print(_preferences->getInt(preference_query_interval_battery));
|
||||||
client.println("\" NAME=\"BATINT\" SIZE=\"25\" MAXLENGTH=\"16\"><BR>");
|
client.println("\" NAME=\"BATINT\" SIZE=\"25\" MAXLENGTH=\"16\"><BR>");
|
||||||
|
|
||||||
client.println("<INPUT TYPE=SUBMIT NAME=\"submit\" VALUE=\"Save\">");
|
client.println("<br><INPUT TYPE=SUBMIT NAME=\"submit\" VALUE=\"Save\">");
|
||||||
|
|
||||||
client.println("</FORM>");
|
client.println("</FORM>");
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <WiFiServer.h>
|
#include <WiFiServer.h>
|
||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
|
#include "Nuki.h"
|
||||||
|
#include "Network.h"
|
||||||
|
|
||||||
enum class TokenType
|
enum class TokenType
|
||||||
{
|
{
|
||||||
@@ -15,7 +17,7 @@ enum class TokenType
|
|||||||
class WebCfgServer
|
class WebCfgServer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WebCfgServer(Preferences* preferences);
|
WebCfgServer(Nuki* nuki, Network* network, Preferences* preferences);
|
||||||
~WebCfgServer() = default;
|
~WebCfgServer() = default;
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
@@ -28,6 +30,8 @@ private:
|
|||||||
TokenType getParameterType(char*& token);
|
TokenType getParameterType(char*& token);
|
||||||
|
|
||||||
WiFiServer _wifiServer;
|
WiFiServer _wifiServer;
|
||||||
|
Nuki* _nuki;
|
||||||
|
Network* _network;
|
||||||
Preferences* _preferences;
|
Preferences* _preferences;
|
||||||
|
|
||||||
bool _enabled = true;
|
bool _enabled = true;
|
||||||
|
|||||||
2
main.cpp
2
main.cpp
@@ -39,8 +39,8 @@ void setup()
|
|||||||
preferences = new Preferences();
|
preferences = new Preferences();
|
||||||
preferences->begin("nukihub", false);
|
preferences->begin("nukihub", false);
|
||||||
network = new Network(preferences);
|
network = new Network(preferences);
|
||||||
webCfgServer = new WebCfgServer(preferences);
|
|
||||||
nuki = new Nuki("Main Door", 2020001, network, preferences);
|
nuki = new Nuki("Main Door", 2020001, network, preferences);
|
||||||
|
webCfgServer = new WebCfgServer(nuki, network, preferences);
|
||||||
|
|
||||||
network->initialize();
|
network->initialize();
|
||||||
webCfgServer->initialize();
|
webCfgServer->initialize();
|
||||||
|
|||||||
Reference in New Issue
Block a user