add MqttLogger
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "W5500Device.h"
|
||||
#include "../Pins.h"
|
||||
#include "../PreferencesKeys.h"
|
||||
#include "../Logger.h"
|
||||
|
||||
W5500Device::W5500Device(const String &hostname, Preferences* preferences)
|
||||
: NetworkDevice(hostname),
|
||||
@@ -10,20 +11,20 @@ W5500Device::W5500Device(const String &hostname, Preferences* preferences)
|
||||
{
|
||||
initializeMacAddress(_mac);
|
||||
|
||||
Serial.print("MAC Adress: ");
|
||||
Log->print("MAC Adress: ");
|
||||
for(int i=0; i < 6; i++)
|
||||
{
|
||||
if(_mac[i] < 10)
|
||||
{
|
||||
Serial.print(F("0"));
|
||||
Log->print(F("0"));
|
||||
}
|
||||
Serial.print(_mac[i], 16);
|
||||
Log->print(_mac[i], 16);
|
||||
if(i < 5)
|
||||
{
|
||||
Serial.print(F(":"));
|
||||
Log->print(F(":"));
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
Log->println();
|
||||
}
|
||||
|
||||
W5500Device::~W5500Device()
|
||||
@@ -39,6 +40,7 @@ void W5500Device::initialize()
|
||||
_ethClient = new EthernetClient();
|
||||
_mqttClient = new PubSubClient(*_ethClient);
|
||||
_mqttClient->setBufferSize(_mqttMaxBufferSize);
|
||||
Log = new MqttLogger(*_mqttClient, "nuki/log");
|
||||
|
||||
reconnect();
|
||||
}
|
||||
@@ -46,33 +48,31 @@ void W5500Device::initialize()
|
||||
|
||||
bool W5500Device::reconnect()
|
||||
{
|
||||
|
||||
|
||||
_hasDHCPAddress = false;
|
||||
|
||||
// start the Ethernet connection:
|
||||
Serial.println(F("Initialize Ethernet with DHCP:"));
|
||||
Log->println(F("Initialize Ethernet with DHCP:"));
|
||||
|
||||
int dhcpRetryCnt = 0;
|
||||
|
||||
while(dhcpRetryCnt < 3)
|
||||
{
|
||||
Serial.print(F("DHCP connect try #"));
|
||||
Serial.print(dhcpRetryCnt);
|
||||
Serial.println();
|
||||
Log->print(F("DHCP connect try #"));
|
||||
Log->print(dhcpRetryCnt);
|
||||
Log->println();
|
||||
dhcpRetryCnt++;
|
||||
|
||||
if (Ethernet.begin(_mac, 1000, 1000) == 0)
|
||||
{
|
||||
Serial.println(F("Failed to configure Ethernet using DHCP"));
|
||||
Log->println(F("Failed to configure Ethernet using DHCP"));
|
||||
// Check for Ethernet hardware present
|
||||
if (Ethernet.hardwareStatus() == EthernetNoHardware)
|
||||
{
|
||||
Serial.println(F("Ethernet module not found"));
|
||||
Log->println(F("Ethernet module not found"));
|
||||
}
|
||||
if (Ethernet.linkStatus() == LinkOFF)
|
||||
{
|
||||
Serial.println(F("Ethernet cable is not connected."));
|
||||
Log->println(F("Ethernet cable is not connected."));
|
||||
}
|
||||
|
||||
IPAddress ip;
|
||||
@@ -91,8 +91,8 @@ bool W5500Device::reconnect()
|
||||
{
|
||||
_hasDHCPAddress = true;
|
||||
dhcpRetryCnt = 1000;
|
||||
Serial.print(F(" DHCP assigned IP "));
|
||||
Serial.println(Ethernet.localIP());
|
||||
Log->print(F(" DHCP assigned IP "));
|
||||
Log->println(Ethernet.localIP());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,12 +102,12 @@ bool W5500Device::reconnect()
|
||||
|
||||
void W5500Device::reconfigure()
|
||||
{
|
||||
Serial.println(F("Reconfigure W5500 not implemented."));
|
||||
Log->println(F("Reconfigure W5500 not implemented."));
|
||||
}
|
||||
|
||||
void W5500Device::resetDevice()
|
||||
{
|
||||
Serial.println(F("Resetting network hardware."));
|
||||
Log->println(F("Resetting network hardware."));
|
||||
pinMode(ETHERNET_RESET_PIN, OUTPUT);
|
||||
digitalWrite(ETHERNET_RESET_PIN, HIGH);
|
||||
delay(250);
|
||||
@@ -120,8 +120,8 @@ void W5500Device::resetDevice()
|
||||
|
||||
void W5500Device::printError()
|
||||
{
|
||||
Serial.print(F("Free Heap: "));
|
||||
Serial.println(ESP.getFreeHeap());
|
||||
Log->print(F("Free Heap: "));
|
||||
Log->println(ESP.getFreeHeap());
|
||||
}
|
||||
|
||||
PubSubClient *W5500Device::mqttClient()
|
||||
|
||||
Reference in New Issue
Block a user