replace all Serial. with Log->
This commit is contained in:
7
Gpio.cpp
7
Gpio.cpp
@@ -2,6 +2,7 @@
|
|||||||
#include "Gpio.h"
|
#include "Gpio.h"
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "Pins.h"
|
#include "Pins.h"
|
||||||
|
#include "Logger.h"
|
||||||
|
|
||||||
Gpio* Gpio::_inst = nullptr;
|
Gpio* Gpio::_inst = nullptr;
|
||||||
NukiWrapper* Gpio::_nuki = nullptr;
|
NukiWrapper* Gpio::_nuki = nullptr;
|
||||||
@@ -26,7 +27,7 @@ void Gpio::isrLock()
|
|||||||
if(millis() < _lockedTs) return;
|
if(millis() < _lockedTs) return;
|
||||||
_nuki->lock();
|
_nuki->lock();
|
||||||
_lockedTs = millis() + _debounceTime;
|
_lockedTs = millis() + _debounceTime;
|
||||||
Serial.println(F("Lock via GPIO"));;
|
Log->println(F("Lock via GPIO"));;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gpio::isrUnlock()
|
void Gpio::isrUnlock()
|
||||||
@@ -34,7 +35,7 @@ void Gpio::isrUnlock()
|
|||||||
if(millis() < _lockedTs) return;
|
if(millis() < _lockedTs) return;
|
||||||
_nuki->unlock();
|
_nuki->unlock();
|
||||||
_lockedTs = millis() + _debounceTime;
|
_lockedTs = millis() + _debounceTime;
|
||||||
Serial.println(F("Unlock via GPIO"));;
|
Log->println(F("Unlock via GPIO"));;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gpio::isrUnlatch()
|
void Gpio::isrUnlatch()
|
||||||
@@ -42,5 +43,5 @@ void Gpio::isrUnlatch()
|
|||||||
if(millis() < _lockedTs) return;
|
if(millis() < _lockedTs) return;
|
||||||
_nuki->unlatch();
|
_nuki->unlatch();
|
||||||
_lockedTs = millis() + _debounceTime;
|
_lockedTs = millis() + _debounceTime;
|
||||||
Serial.println(F("Unlatch via GPIO"));;
|
Log->println(F("Unlatch via GPIO"));;
|
||||||
}
|
}
|
||||||
|
|||||||
41
Network.cpp
41
Network.cpp
@@ -3,6 +3,7 @@
|
|||||||
#include "MqttTopics.h"
|
#include "MqttTopics.h"
|
||||||
#include "networkDevices/W5500Device.h"
|
#include "networkDevices/W5500Device.h"
|
||||||
#include "networkDevices/WifiDevice.h"
|
#include "networkDevices/WifiDevice.h"
|
||||||
|
#include "Logger.h"
|
||||||
|
|
||||||
|
|
||||||
Network* Network::_inst = nullptr;
|
Network* Network::_inst = nullptr;
|
||||||
@@ -29,15 +30,15 @@ void Network::setupDevice(const NetworkDeviceType hardware)
|
|||||||
switch(hardware)
|
switch(hardware)
|
||||||
{
|
{
|
||||||
case NetworkDeviceType::W5500:
|
case NetworkDeviceType::W5500:
|
||||||
Serial.println(F("Network device: W5500"));
|
Log->println(F("Network device: W5500"));
|
||||||
_device = new W5500Device(_hostname, _preferences);
|
_device = new W5500Device(_hostname, _preferences);
|
||||||
break;
|
break;
|
||||||
case NetworkDeviceType::WiFi:
|
case NetworkDeviceType::WiFi:
|
||||||
Serial.println(F("Network device: Builtin WiFi"));
|
Log->println(F("Network device: Builtin WiFi"));
|
||||||
_device = new WifiDevice(_hostname, _preferences);
|
_device = new WifiDevice(_hostname, _preferences);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Serial.println(F("Unknown network device type, defaulting to WiFi"));
|
Log->println(F("Unknown network device type, defaulting to WiFi"));
|
||||||
_device = new WifiDevice(_hostname, _preferences);
|
_device = new WifiDevice(_hostname, _preferences);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -55,8 +56,8 @@ void Network::initialize()
|
|||||||
|
|
||||||
_device->initialize();
|
_device->initialize();
|
||||||
|
|
||||||
Serial.print(F("Host name: "));
|
Log->print(F("Host name: "));
|
||||||
Serial.println(_hostname);
|
Log->println(_hostname);
|
||||||
|
|
||||||
String brokerAddr = _preferences->getString(preference_mqtt_broker);
|
String brokerAddr = _preferences->getString(preference_mqtt_broker);
|
||||||
strcpy(_mqttBrokerAddr, brokerAddr.c_str());
|
strcpy(_mqttBrokerAddr, brokerAddr.c_str());
|
||||||
@@ -88,10 +89,10 @@ void Network::initialize()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.print(F("MQTT Broker: "));
|
Log->print(F("MQTT Broker: "));
|
||||||
Serial.print(_mqttBrokerAddr);
|
Log->print(_mqttBrokerAddr);
|
||||||
Serial.print(F(":"));
|
Log->print(F(":"));
|
||||||
Serial.println(port);
|
Log->println(port);
|
||||||
|
|
||||||
_device->mqttClient()->setServer(_mqttBrokerAddr, port);
|
_device->mqttClient()->setServer(_mqttBrokerAddr, port);
|
||||||
_device->mqttClient()->setCallback(Network::onMqttDataReceivedCallback);
|
_device->mqttClient()->setCallback(Network::onMqttDataReceivedCallback);
|
||||||
@@ -117,16 +118,16 @@ int Network::update()
|
|||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println(F("Network not connected. Trying reconnect."));
|
Log->println(F("Network not connected. Trying reconnect."));
|
||||||
bool success = _device->reconnect();
|
bool success = _device->reconnect();
|
||||||
Serial.println(success ? F("Reconnect successful") : F("Reconnect failed"));
|
Log->println(success ? F("Reconnect successful") : F("Reconnect failed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!_device->isConnected())
|
if(!_device->isConnected())
|
||||||
{
|
{
|
||||||
if(_networkTimeout > 0 && (ts - _lastConnectedTs > _networkTimeout * 1000))
|
if(_networkTimeout > 0 && (ts - _lastConnectedTs > _networkTimeout * 1000))
|
||||||
{
|
{
|
||||||
Serial.println("Network timeout has been reached, restarting ...");
|
Log->println("Network timeout has been reached, restarting ...");
|
||||||
delay(200);
|
delay(200);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
@@ -149,8 +150,8 @@ int Network::update()
|
|||||||
bool success = publishString(_mqttPresencePrefix, mqtt_topic_presence, _presenceCsv);
|
bool success = publishString(_mqttPresencePrefix, mqtt_topic_presence, _presenceCsv);
|
||||||
if(!success)
|
if(!success)
|
||||||
{
|
{
|
||||||
Serial.println(F("Failed to publish presence CSV data."));
|
Log->println(F("Failed to publish presence CSV data."));
|
||||||
Serial.println(_presenceCsv);
|
Log->println(_presenceCsv);
|
||||||
}
|
}
|
||||||
_presenceCsv = nullptr;
|
_presenceCsv = nullptr;
|
||||||
}
|
}
|
||||||
@@ -184,23 +185,23 @@ bool Network::reconnect()
|
|||||||
|
|
||||||
while (!_device->mqttClient()->connected() && millis() > _nextReconnect)
|
while (!_device->mqttClient()->connected() && millis() > _nextReconnect)
|
||||||
{
|
{
|
||||||
Serial.println(F("Attempting MQTT connection"));
|
Log->println(F("Attempting MQTT connection"));
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
if(strlen(_mqttUser) == 0)
|
if(strlen(_mqttUser) == 0)
|
||||||
{
|
{
|
||||||
Serial.println(F("MQTT: Connecting without credentials"));
|
Log->println(F("MQTT: Connecting without credentials"));
|
||||||
success = _device->mqttClient()->connect(_preferences->getString(preference_hostname).c_str());
|
success = _device->mqttClient()->connect(_preferences->getString(preference_hostname).c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.print(F("MQTT: Connecting with user: ")); Serial.println(_mqttUser);
|
Log->print(F("MQTT: Connecting with user: ")); Log->println(_mqttUser);
|
||||||
success = _device->mqttClient()->connect(_preferences->getString(preference_hostname).c_str(), _mqttUser, _mqttPass);
|
success = _device->mqttClient()->connect(_preferences->getString(preference_hostname).c_str(), _mqttUser, _mqttPass);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
Serial.println(F("MQTT connected"));
|
Log->println(F("MQTT connected"));
|
||||||
_mqttConnected = true;
|
_mqttConnected = true;
|
||||||
delay(100);
|
delay(100);
|
||||||
for(const String& topic : _subscribedTopics)
|
for(const String& topic : _subscribedTopics)
|
||||||
@@ -218,8 +219,8 @@ bool Network::reconnect()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.print(F("MQTT connect failed, rc="));
|
Log->print(F("MQTT connect failed, rc="));
|
||||||
Serial.println(_device->mqttClient()->state());
|
Log->println(_device->mqttClient()->state());
|
||||||
_device->printError();
|
_device->printError();
|
||||||
_device->mqttClient()->disconnect();
|
_device->mqttClient()->disconnect();
|
||||||
_mqttConnected = false;
|
_mqttConnected = false;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "MqttTopics.h"
|
#include "MqttTopics.h"
|
||||||
#include "PreferencesKeys.h"
|
#include "PreferencesKeys.h"
|
||||||
#include "Pins.h"
|
#include "Pins.h"
|
||||||
|
#include "Logger.h"
|
||||||
|
|
||||||
NetworkOpener::NetworkOpener(Network* network, Preferences* preferences)
|
NetworkOpener::NetworkOpener(Network* network, Preferences* preferences)
|
||||||
: _preferences(preferences),
|
: _preferences(preferences),
|
||||||
@@ -70,8 +71,8 @@ void NetworkOpener::onMqttDataReceived(char *&topic, byte *&payload, unsigned in
|
|||||||
{
|
{
|
||||||
if(strcmp(value, "") == 0 || strcmp(value, "--") == 0 || strcmp(value, "ack") == 0 || strcmp(value, "unknown_action") == 0) return;
|
if(strcmp(value, "") == 0 || strcmp(value, "--") == 0 || strcmp(value, "ack") == 0 || strcmp(value, "unknown_action") == 0) return;
|
||||||
|
|
||||||
Serial.print(F("Opener lock action received: "));
|
Log->print(F("Opener lock action received: "));
|
||||||
Serial.println(value);
|
Log->println(value);
|
||||||
bool success = false;
|
bool success = false;
|
||||||
if(_lockActionReceivedCallback != NULL)
|
if(_lockActionReceivedCallback != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "PreferencesKeys.h"
|
#include "PreferencesKeys.h"
|
||||||
#include "Version.h"
|
#include "Version.h"
|
||||||
#include "hardware/WifiEthServer.h"
|
#include "hardware/WifiEthServer.h"
|
||||||
|
#include "Logger.h"
|
||||||
#include <esp_task_wdt.h>
|
#include <esp_task_wdt.h>
|
||||||
|
|
||||||
WebCfgServer::WebCfgServer(NukiWrapper* nuki, NukiOpenerWrapper* nukiOpener, Network* network, EthServer* ethServer, Preferences* preferences, bool allowRestartToPortal)
|
WebCfgServer::WebCfgServer(NukiWrapper* nuki, NukiOpenerWrapper* nukiOpener, Network* network, EthServer* ethServer, Preferences* preferences, bool allowRestartToPortal)
|
||||||
@@ -130,7 +131,7 @@ void WebCfgServer::initialize()
|
|||||||
String response = "";
|
String response = "";
|
||||||
buildConfirmHtml(response, message);
|
buildConfirmHtml(response, message);
|
||||||
_server.send(200, "text/html", response);
|
_server.send(200, "text/html", response);
|
||||||
Serial.println(F("Restarting"));
|
Log->println(F("Restarting"));
|
||||||
|
|
||||||
waitAndProcess(true, 1000);
|
waitAndProcess(true, 1000);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
@@ -413,7 +414,7 @@ void WebCfgServer::update()
|
|||||||
{
|
{
|
||||||
if(_otaStartTs > 0 && (millis() - _otaStartTs) > 120000)
|
if(_otaStartTs > 0 && (millis() - _otaStartTs) > 120000)
|
||||||
{
|
{
|
||||||
Serial.println(F("OTA time out, restarting"));
|
Log->println(F("OTA time out, restarting"));
|
||||||
delay(200);
|
delay(200);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
@@ -849,7 +850,7 @@ void WebCfgServer::handleOtaUpload()
|
|||||||
|
|
||||||
if(upload.filename == "")
|
if(upload.filename == "")
|
||||||
{
|
{
|
||||||
Serial.println("Invalid file for OTA upload");
|
Log->println("Invalid file for OTA upload");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -861,7 +862,7 @@ void WebCfgServer::handleOtaUpload()
|
|||||||
_otaStartTs = millis();
|
_otaStartTs = millis();
|
||||||
esp_task_wdt_init(30, false);
|
esp_task_wdt_init(30, false);
|
||||||
_network->disableAutoRestarts();
|
_network->disableAutoRestarts();
|
||||||
Serial.print("handleFileUpload Name: "); Serial.println(filename);
|
Log->print("handleFileUpload Name: "); Serial.println(filename);
|
||||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||||
_transferredSize = _transferredSize + upload.currentSize;
|
_transferredSize = _transferredSize + upload.currentSize;
|
||||||
Serial.println(_transferredSize);
|
Serial.println(_transferredSize);
|
||||||
|
|||||||
6
main.cpp
6
main.cpp
@@ -94,7 +94,7 @@ void checkMillisTask(void *pvParameters)
|
|||||||
// millis() is about to overflow. Restart device to prevent problems with overflow
|
// millis() is about to overflow. Restart device to prevent problems with overflow
|
||||||
if(millis() > restartTs)
|
if(millis() > restartTs)
|
||||||
{
|
{
|
||||||
Serial.println(F("Restart timer expired, restarting device."));
|
Log->println(F("Restart timer expired, restarting device."));
|
||||||
delay(200);
|
delay(200);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
@@ -196,7 +196,7 @@ void setup()
|
|||||||
bleScanner->setScanDuration(10);
|
bleScanner->setScanDuration(10);
|
||||||
|
|
||||||
lockEnabled = preferences->getBool(preference_lock_enabled);
|
lockEnabled = preferences->getBool(preference_lock_enabled);
|
||||||
Serial.println(lockEnabled ? F("NUKI Lock enabled") : F("NUKI Lock disabled"));
|
Log->println(lockEnabled ? F("NUKI Lock enabled") : F("NUKI Lock disabled"));
|
||||||
if(lockEnabled)
|
if(lockEnabled)
|
||||||
{
|
{
|
||||||
nuki = new NukiWrapper("NukiHub", deviceId, bleScanner, networkLock, preferences);
|
nuki = new NukiWrapper("NukiHub", deviceId, bleScanner, networkLock, preferences);
|
||||||
@@ -209,7 +209,7 @@ void setup()
|
|||||||
}
|
}
|
||||||
|
|
||||||
openerEnabled = preferences->getBool(preference_opener_enabled);
|
openerEnabled = preferences->getBool(preference_opener_enabled);
|
||||||
Serial.println(openerEnabled ? F("NUKI Opener enabled") : F("NUKI Opener disabled"));
|
Log->println(openerEnabled ? F("NUKI Opener enabled") : F("NUKI Opener disabled"));
|
||||||
if(openerEnabled)
|
if(openerEnabled)
|
||||||
{
|
{
|
||||||
nukiOpener = new NukiOpenerWrapper("NukiHub", deviceId, bleScanner, networkOpener, preferences);
|
nukiOpener = new NukiOpenerWrapper("NukiHub", deviceId, bleScanner, networkOpener, preferences);
|
||||||
|
|||||||
@@ -21,22 +21,22 @@ WifiDevice::WifiDevice(const String& hostname, Preferences* _preferences)
|
|||||||
|
|
||||||
if(caLength > 1) // length is 1 when empty
|
if(caLength > 1) // length is 1 when empty
|
||||||
{
|
{
|
||||||
Serial.println(F("MQTT over TLS."));
|
Log->println(F("MQTT over TLS."));
|
||||||
Serial.println(_ca);
|
Log->println(_ca);
|
||||||
_wifiClientSecure = new WiFiClientSecure();
|
_wifiClientSecure = new WiFiClientSecure();
|
||||||
_wifiClientSecure->setCACert(_ca);
|
_wifiClientSecure->setCACert(_ca);
|
||||||
if(crtLength > 1 && keyLength > 1) // length is 1 when empty
|
if(crtLength > 1 && keyLength > 1) // length is 1 when empty
|
||||||
{
|
{
|
||||||
Serial.println(F("MQTT with client certificate."));
|
Log->println(F("MQTT with client certificate."));
|
||||||
Serial.println(_cert);
|
Log->println(_cert);
|
||||||
Serial.println(_key);
|
Log->println(_key);
|
||||||
_wifiClientSecure->setCertificate(_cert);
|
_wifiClientSecure->setCertificate(_cert);
|
||||||
_wifiClientSecure->setPrivateKey(_key);
|
_wifiClientSecure->setPrivateKey(_key);
|
||||||
}
|
}
|
||||||
_mqttClient = new PubSubClient(*_wifiClientSecure);
|
_mqttClient = new PubSubClient(*_wifiClientSecure);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
Serial.println(F("MQTT without TLS."));
|
Log->println(F("MQTT without TLS."));
|
||||||
_wifiClient = new WiFiClient();
|
_wifiClient = new WiFiClient();
|
||||||
_mqttClient = new PubSubClient(*_wifiClient);
|
_mqttClient = new PubSubClient(*_wifiClient);
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ void WifiDevice::initialize()
|
|||||||
|
|
||||||
if(_startAp)
|
if(_startAp)
|
||||||
{
|
{
|
||||||
Serial.println(F("Opening WiFi configuration portal."));
|
Log->println(F("Opening WiFi configuration portal."));
|
||||||
res = _wm.startConfigPortal();
|
res = _wm.startConfigPortal();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -76,13 +76,13 @@ void WifiDevice::initialize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!res) {
|
if(!res) {
|
||||||
Serial.println(F("Failed to connect. Wait for ESP restart."));
|
Log->println(F("Failed to connect. Wait for ESP restart."));
|
||||||
delay(1000);
|
delay(1000);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Serial.print(F("WiFi connected: "));
|
Log->print(F("WiFi connected: "));
|
||||||
Serial.println(WiFi.localIP().toString());
|
Log->println(WiFi.localIP().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_restartOnDisconnect)
|
if(_restartOnDisconnect)
|
||||||
@@ -108,10 +108,10 @@ void WifiDevice::printError()
|
|||||||
{
|
{
|
||||||
char lastError[100];
|
char lastError[100];
|
||||||
_wifiClientSecure->lastError(lastError,100);
|
_wifiClientSecure->lastError(lastError,100);
|
||||||
Serial.println(lastError);
|
Log->println(lastError);
|
||||||
}
|
}
|
||||||
Serial.print(F("Free Heap: "));
|
Log->print(F("Free Heap: "));
|
||||||
Serial.println(ESP.getFreeHeap());
|
Log->println(ESP.getFreeHeap());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WifiDevice::isConnected()
|
bool WifiDevice::isConnected()
|
||||||
|
|||||||
Reference in New Issue
Block a user