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