add NetworkUtil, move NetworkDeviceType to seperate file
This commit is contained in:
@@ -54,6 +54,8 @@ set(SRCFILES
|
|||||||
../lib/BleScanner/src/BleScanner.cpp
|
../lib/BleScanner/src/BleScanner.cpp
|
||||||
../lib/MqttLogger/src/MqttLogger.cpp
|
../lib/MqttLogger/src/MqttLogger.cpp
|
||||||
../lib/AsyncTCP/src/AsyncTCP.cpp
|
../lib/AsyncTCP/src/AsyncTCP.cpp
|
||||||
|
../src/util/NetworkUtil.cpp
|
||||||
|
../src/enums/NetworkDeviceType.h
|
||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB_RECURSE SRCFILESREC
|
file(GLOB_RECURSE SRCFILESREC
|
||||||
|
|||||||
@@ -116,66 +116,7 @@ void NukiNetwork::setupDevice()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log->print(F("Network device: "));
|
_networkDeviceType = NetworkUtil::GetDeviceTypeFromPreference(hardwareDetect, _preferences->getInt(preference_network_custom_phy, 0));
|
||||||
switch (hardwareDetect)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
Log->println(F("Wi-Fi only"));
|
|
||||||
_networkDeviceType = NetworkDeviceType::WiFi;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
Log->println(F("Generic W5500"));
|
|
||||||
_networkDeviceType = NetworkDeviceType::W5500;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
Log->println(F("W5500 on M5Stack Atom POE"));
|
|
||||||
_networkDeviceType = NetworkDeviceType::W5500M5;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
Log->println(F("Olimex ESP32-POE / ESP-POE-ISO"));
|
|
||||||
_networkDeviceType = NetworkDeviceType::Olimex_LAN8720;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
Log->println(F("WT32-ETH01"));
|
|
||||||
_networkDeviceType = NetworkDeviceType::WT32_LAN8720;
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
Log->println(F("M5STACK PoESP32 Unit"));
|
|
||||||
_networkDeviceType = NetworkDeviceType::M5STACK_PoESP32_Unit;
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
Log->println(F("LilyGO T-ETH-POE"));
|
|
||||||
_networkDeviceType = NetworkDeviceType::LilyGO_T_ETH_POE;
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
Log->println(F("GL-S10"));
|
|
||||||
_networkDeviceType = NetworkDeviceType::GL_S10;
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
Log->println(F("ETH01-Evo"));
|
|
||||||
_networkDeviceType = NetworkDeviceType::ETH01_Evo;
|
|
||||||
break;
|
|
||||||
case 10:
|
|
||||||
Log->println(F("W5500 on M5Stack Atom POE S3"));
|
|
||||||
_networkDeviceType = NetworkDeviceType::W5500M5S3;
|
|
||||||
break;
|
|
||||||
case 11:
|
|
||||||
Log->println(F("Custom LAN Module"));
|
|
||||||
if(_preferences->getInt(preference_network_custom_phy, 0) > 0)
|
|
||||||
{
|
|
||||||
_networkDeviceType = NetworkDeviceType::CUSTOM;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log->println(F("Custom LAN Module not setup correctly, falling back to Wi-Fi"));
|
|
||||||
_networkDeviceType = NetworkDeviceType::WiFi;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Log->println(F("Unknown hardware selected, falling back to Wi-Fi."));
|
|
||||||
_networkDeviceType = NetworkDeviceType::WiFi;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (_networkDeviceType)
|
switch (_networkDeviceType)
|
||||||
@@ -378,6 +319,10 @@ void NukiNetwork::setupDevice()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log->print(F("Network device: "));
|
||||||
|
Log->print(_device->deviceName());
|
||||||
|
|
||||||
|
|
||||||
#ifndef NUKI_HUB_UPDATER
|
#ifndef NUKI_HUB_UPDATER
|
||||||
_device->mqttOnConnect([&](bool sessionPresent)
|
_device->mqttOnConnect([&](bool sessionPresent)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include "networkDevices/NetworkDevice.h"
|
#include "networkDevices/NetworkDevice.h"
|
||||||
#include "networkDevices/IPConfiguration.h"
|
#include "networkDevices/IPConfiguration.h"
|
||||||
|
#include "util/NetworkUtil.h"
|
||||||
|
|
||||||
#ifndef NUKI_HUB_UPDATER
|
#ifndef NUKI_HUB_UPDATER
|
||||||
#include "MqttReceiver.h"
|
#include "MqttReceiver.h"
|
||||||
@@ -13,23 +14,9 @@
|
|||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include "NukiConstants.h"
|
#include "NukiConstants.h"
|
||||||
#include "PresenceDetection.h"
|
#include "PresenceDetection.h"
|
||||||
|
#include "enums/NetworkDeviceType.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum class NetworkDeviceType
|
|
||||||
{
|
|
||||||
WiFi,
|
|
||||||
W5500,
|
|
||||||
W5500M5,
|
|
||||||
W5500M5S3,
|
|
||||||
Olimex_LAN8720,
|
|
||||||
WT32_LAN8720,
|
|
||||||
M5STACK_PoESP32_Unit,
|
|
||||||
LilyGO_T_ETH_POE,
|
|
||||||
GL_S10,
|
|
||||||
ETH01_Evo,
|
|
||||||
CUSTOM
|
|
||||||
};
|
|
||||||
|
|
||||||
#define JSON_BUFFER_SIZE 1024
|
#define JSON_BUFFER_SIZE 1024
|
||||||
|
|
||||||
class NukiNetwork
|
class NukiNetwork
|
||||||
|
|||||||
16
src/enums/NetworkDeviceType.h
Normal file
16
src/enums/NetworkDeviceType.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
enum class NetworkDeviceType
|
||||||
|
{
|
||||||
|
WiFi,
|
||||||
|
W5500,
|
||||||
|
W5500M5,
|
||||||
|
W5500M5S3,
|
||||||
|
Olimex_LAN8720,
|
||||||
|
WT32_LAN8720,
|
||||||
|
M5STACK_PoESP32_Unit,
|
||||||
|
LilyGO_T_ETH_POE,
|
||||||
|
GL_S10,
|
||||||
|
ETH01_Evo,
|
||||||
|
CUSTOM
|
||||||
|
};
|
||||||
53
src/util/NetworkUtil.cpp
Normal file
53
src/util/NetworkUtil.cpp
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#include "NetworkUtil.h"
|
||||||
|
#include <Logger.h>
|
||||||
|
|
||||||
|
NetworkDeviceType NetworkUtil::GetDeviceTypeFromPreference(int hardwareDetect, int customPhy)
|
||||||
|
{
|
||||||
|
switch (hardwareDetect)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
return NetworkDeviceType::WiFi;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
return NetworkDeviceType::W5500;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
return NetworkDeviceType::W5500M5;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
return NetworkDeviceType::Olimex_LAN8720;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
return NetworkDeviceType::WT32_LAN8720;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
return NetworkDeviceType::M5STACK_PoESP32_Unit;
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
return NetworkDeviceType::LilyGO_T_ETH_POE;
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
return NetworkDeviceType::GL_S10;
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
return NetworkDeviceType::ETH01_Evo;
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
return NetworkDeviceType::W5500M5S3;
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
if(customPhy> 0)
|
||||||
|
{
|
||||||
|
return NetworkDeviceType::CUSTOM;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NetworkDeviceType::WiFi;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Log->println(F("Unknown hardware selected, falling back to Wi-Fi."));
|
||||||
|
return NetworkDeviceType::WiFi;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/util/NetworkUtil.h
Normal file
9
src/util/NetworkUtil.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <enums/NetworkDeviceType.h>
|
||||||
|
|
||||||
|
class NetworkUtil
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static NetworkDeviceType GetDeviceTypeFromPreference(int hardwareDetect, int customPhy);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user