show pairing and mqtt status in configuration page
This commit is contained in:
@@ -68,6 +68,7 @@ bool Network::reconnect()
|
||||
// Attempt to connect
|
||||
if (_mqttClient.connect("nukiHub")) {
|
||||
Serial.println(F("MQTT connected"));
|
||||
_mqttConnected = true;
|
||||
|
||||
// ... and resubscribe
|
||||
_mqttClient.subscribe(mqtt_topic_lockstate_action);
|
||||
@@ -76,12 +77,13 @@ bool Network::reconnect()
|
||||
{
|
||||
Serial.print(F("MQTT connect failed, rc="));
|
||||
Serial.println(_mqttClient.state());
|
||||
_mqttConnected = false;
|
||||
_nextReconnect = millis() + 5000;
|
||||
}
|
||||
}
|
||||
return _mqttConnected;
|
||||
}
|
||||
|
||||
|
||||
void Network::update()
|
||||
{
|
||||
if(!WiFi.isConnected())
|
||||
@@ -167,3 +169,8 @@ void Network::publishInt(const char *topic, const int value)
|
||||
itoa(value, str, 10);
|
||||
_mqttClient.publish(topic, str);
|
||||
}
|
||||
|
||||
bool Network::isMqttConnected()
|
||||
{
|
||||
return _mqttConnected;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ public:
|
||||
void initialize();
|
||||
void update();
|
||||
|
||||
bool isMqttConnected();
|
||||
|
||||
void publishKeyTurnerState(const char* state, const char* trigger, const char* completionStatus);
|
||||
void publishBatteryReport(const BatteryReport& batteryReport);
|
||||
|
||||
@@ -32,6 +34,8 @@ private:
|
||||
WiFiClient _wifiClient;
|
||||
Preferences* _preferences;
|
||||
|
||||
bool _mqttConnected = false;
|
||||
|
||||
unsigned long _nextReconnect = 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.println((int)nukiInst->_nextLockAction);
|
||||
}
|
||||
|
||||
const bool Nuki::isPaired()
|
||||
{
|
||||
return _paired;
|
||||
}
|
||||
|
||||
2
Nuki.h
2
Nuki.h
@@ -12,6 +12,8 @@ public:
|
||||
void initialize();
|
||||
void update();
|
||||
|
||||
const bool isPaired();
|
||||
|
||||
private:
|
||||
static void onLockActionReceived(const char* value);
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
#include <WiFiClient.h>
|
||||
#include "PreferencesKeys.h"
|
||||
|
||||
WebCfgServer::WebCfgServer(Preferences* preferences)
|
||||
WebCfgServer::WebCfgServer(Nuki* nuki, Network* network, Preferences* preferences)
|
||||
: _wifiServer(80),
|
||||
_nuki(nuki),
|
||||
_network(network),
|
||||
_preferences(preferences)
|
||||
{}
|
||||
|
||||
@@ -112,6 +114,16 @@ void WebCfgServer::serveHtml(WiFiClient &client)
|
||||
client.println("</HEAD>");
|
||||
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.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.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>");
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <WiFiServer.h>
|
||||
#include <Preferences.h>
|
||||
#include "Nuki.h"
|
||||
#include "Network.h"
|
||||
|
||||
enum class TokenType
|
||||
{
|
||||
@@ -15,7 +17,7 @@ enum class TokenType
|
||||
class WebCfgServer
|
||||
{
|
||||
public:
|
||||
WebCfgServer(Preferences* preferences);
|
||||
WebCfgServer(Nuki* nuki, Network* network, Preferences* preferences);
|
||||
~WebCfgServer() = default;
|
||||
|
||||
void initialize();
|
||||
@@ -28,6 +30,8 @@ private:
|
||||
TokenType getParameterType(char*& token);
|
||||
|
||||
WiFiServer _wifiServer;
|
||||
Nuki* _nuki;
|
||||
Network* _network;
|
||||
Preferences* _preferences;
|
||||
|
||||
bool _enabled = true;
|
||||
|
||||
2
main.cpp
2
main.cpp
@@ -39,8 +39,8 @@ void setup()
|
||||
preferences = new Preferences();
|
||||
preferences->begin("nukihub", false);
|
||||
network = new Network(preferences);
|
||||
webCfgServer = new WebCfgServer(preferences);
|
||||
nuki = new Nuki("Main Door", 2020001, network, preferences);
|
||||
webCfgServer = new WebCfgServer(nuki, network, preferences);
|
||||
|
||||
network->initialize();
|
||||
webCfgServer->initialize();
|
||||
|
||||
Reference in New Issue
Block a user