make network hardware selectable
This commit is contained in:
29
Network.cpp
29
Network.cpp
@@ -29,6 +29,8 @@ Network::Network(Preferences *preferences, const String& maintenancePathPrefix)
|
||||
|
||||
void Network::setupDevice()
|
||||
{
|
||||
int hardwareDetect = _preferences->getInt(preference_network_hardware);
|
||||
int hardwareDetectGpio = _preferences->getInt(preference_network_hardware_gpio);
|
||||
|
||||
if(strcmp(WiFi_fallbackDetect, "wifi_fallback") == 0)
|
||||
{
|
||||
@@ -37,35 +39,38 @@ void Network::setupDevice()
|
||||
}
|
||||
else
|
||||
{
|
||||
int hardwareDetect = _preferences->getInt(preference_network_hardware_detect);
|
||||
if(hardwareDetectGpio == 0)
|
||||
{
|
||||
hardwareDetectGpio = 26;
|
||||
_preferences->putInt(preference_network_hardware_gpio, hardwareDetectGpio);
|
||||
}
|
||||
|
||||
if(hardwareDetect == 0)
|
||||
{
|
||||
hardwareDetect = 26;
|
||||
_preferences->putInt(preference_network_hardware_detect, hardwareDetect);
|
||||
}
|
||||
|
||||
if(hardwareDetect == -1)
|
||||
{
|
||||
Log->println(F("W5500 hardware is disable, using Wifi."));
|
||||
Log->println(F("W5500 hardware is disabled, using Wifi."));
|
||||
_networkDeviceType = NetworkDeviceType::WiFi;
|
||||
}
|
||||
else
|
||||
else if(hardwareDetect == 1)
|
||||
{
|
||||
Log->print(F("Using PIN "));
|
||||
Log->print(hardwareDetect);
|
||||
Log->print(hardwareDetectGpio);
|
||||
Log->println(F(" for network device selection"));
|
||||
|
||||
pinMode(hardwareDetect, INPUT_PULLUP);
|
||||
_networkDeviceType = digitalRead(hardwareDetect) == HIGH ? NetworkDeviceType::WiFi : NetworkDeviceType::W5500;
|
||||
}
|
||||
else if(hardwareDetect == 2)
|
||||
{
|
||||
Log->print(F("W5500 on M5Sack Atom POE"));
|
||||
_networkDeviceType = NetworkDeviceType::W5500;
|
||||
}
|
||||
}
|
||||
_networkDeviceType = NetworkDeviceType::W5500;
|
||||
|
||||
switch(_networkDeviceType)
|
||||
{
|
||||
case NetworkDeviceType::W5500:
|
||||
Log->println(F("Network device: W5500"));
|
||||
_device = new W5500Device(_hostname, _preferences);
|
||||
_device = new W5500Device(_hostname, _preferences, hardwareDetect);
|
||||
break;
|
||||
case NetworkDeviceType::WiFi:
|
||||
Log->println(F("Network device: Builtin WiFi"));
|
||||
|
||||
3
Pins.h
3
Pins.h
@@ -1,8 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define ETHERNET_SCK_PIN 22
|
||||
#define ETHERNET_MISO_PIN 23
|
||||
#define ETHERNET_MOSI_PIN 33
|
||||
#define ETHERNET_CS_PIN 19
|
||||
#define ETHERNET_RESET_PIN -1
|
||||
#define TRIGGER_LOCK_PIN 32
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
#define preference_mqtt_crt "mqttcrt"
|
||||
#define preference_mqtt_key "mqttkey"
|
||||
#define preference_mqtt_hass_discovery "hassdiscovery"
|
||||
#define preference_network_hardware_detect "nwhwdt"
|
||||
#define preference_network_hardware "nwhw"
|
||||
#define preference_network_hardware_gpio "nwhwdt"
|
||||
#define preference_rssi_publish_interval "rssipb"
|
||||
#define preference_hostname "hostname"
|
||||
#define preference_network_timeout "nettmout"
|
||||
|
||||
@@ -239,9 +239,14 @@ bool WebCfgServer::processArgs(String& message)
|
||||
_preferences->putString(preference_mqtt_key, value);
|
||||
configChanged = true;
|
||||
}
|
||||
else if(key == "NWHW")
|
||||
{
|
||||
_preferences->putInt(preference_network_hardware, value.toInt());
|
||||
configChanged = true;
|
||||
}
|
||||
else if(key == "NWHWDT")
|
||||
{
|
||||
_preferences->putInt(preference_network_hardware_detect, value.toInt());
|
||||
_preferences->putInt(preference_network_hardware_gpio, value.toInt());
|
||||
configChanged = true;
|
||||
}
|
||||
else if(key == "RSSI")
|
||||
@@ -607,7 +612,8 @@ void WebCfgServer::buildMqttConfigHtml(String &response)
|
||||
printTextarea(response, "MQTTCA", "MQTT SSL CA Certificate (*, optional)", _preferences->getString(preference_mqtt_ca).c_str(), TLS_CA_MAX_SIZE, _network->encryptionSupported());
|
||||
printTextarea(response, "MQTTCRT", "MQTT SSL Client Certificate (*, optional)", _preferences->getString(preference_mqtt_crt).c_str(), TLS_CERT_MAX_SIZE, _network->encryptionSupported());
|
||||
printTextarea(response, "MQTTKEY", "MQTT SSL Client Key (*, optional)", _preferences->getString(preference_mqtt_key).c_str(), TLS_KEY_MAX_SIZE, _network->encryptionSupported());
|
||||
printDropDown(response, "NWHWDT", "Network hardware detection", String(_preferences->getInt(preference_network_hardware_detect)), getNetworkDetectionOptions());
|
||||
printDropDown(response, "NWHW", "Network hardware", String(_preferences->getInt(preference_network_hardware)), getNetworkDetectionOptions());
|
||||
printDropDown(response, "NWHWDT", "Network hardware detection", String(_preferences->getInt(preference_network_hardware_gpio)), getNetworkGpioOptions());
|
||||
printInputField(response, "RSSI", "RSSI Publish interval (seconds; -1 to disable)", _preferences->getInt(preference_rssi_publish_interval), 6);
|
||||
printInputField(response, "NETTIMEOUT", "Network Timeout until restart (seconds; -1 to disable)", _preferences->getInt(preference_network_timeout), 5);
|
||||
printCheckBox(response, "RSTDISC", "Restart on disconnect", _preferences->getBool(preference_restart_on_disconnect));
|
||||
@@ -956,7 +962,16 @@ const std::vector<std::pair<String, String>> WebCfgServer::getNetworkDetectionOp
|
||||
{
|
||||
std::vector<std::pair<String, String>> options;
|
||||
|
||||
options.push_back(std::make_pair("-1", "Disable W5500"));
|
||||
options.push_back(std::make_pair("0", "Disable W5500 (Wifi only)"));
|
||||
options.push_back(std::make_pair("1", "W5500 (GPIO CS=5; SCK=18; MISO=19; MOSI=23; RST=33)"));
|
||||
options.push_back(std::make_pair("2", "M5Stack Atom POE (W5500)"));
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
const std::vector<std::pair<String, String>> WebCfgServer::getNetworkGpioOptions() const
|
||||
{
|
||||
std::vector<std::pair<String, String>> options;
|
||||
|
||||
for(int i=16; i <= 33; i++)
|
||||
{
|
||||
@@ -966,4 +981,4 @@ const std::vector<std::pair<String, String>> WebCfgServer::getNetworkDetectionOp
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,7 @@ private:
|
||||
void buildNavigationButton(String& response, const char* caption, const char* targetPath);
|
||||
|
||||
const std::vector<std::pair<String, String>> getNetworkDetectionOptions() const;
|
||||
const std::vector<std::pair<String, String>> getNetworkGpioOptions() const;
|
||||
|
||||
void printParameter(String& response, const char* description, const char* value);
|
||||
|
||||
|
||||
@@ -6,9 +6,10 @@
|
||||
#include "../Logger.h"
|
||||
#include "../MqttTopics.h"
|
||||
|
||||
W5500Device::W5500Device(const String &hostname, Preferences* preferences)
|
||||
W5500Device::W5500Device(const String &hostname, Preferences* preferences, int variant)
|
||||
: NetworkDevice(hostname),
|
||||
_preferences(preferences)
|
||||
_preferences(preferences),
|
||||
_variant((W5500Variant)variant)
|
||||
{
|
||||
initializeMacAddress(_mac);
|
||||
|
||||
@@ -37,7 +38,15 @@ void W5500Device::initialize()
|
||||
|
||||
resetDevice();
|
||||
|
||||
Ethernet.init(ETHERNET_CS_PIN, ETHERNET_SCK_PIN, ETHERNET_MISO_PIN, ETHERNET_MOSI_PIN);
|
||||
switch(_variant)
|
||||
{
|
||||
case W5500Variant::M5StackAtomPoe:
|
||||
Ethernet.init(ETHERNET_CS_PIN, 22, 23, 33);
|
||||
break;
|
||||
default:
|
||||
Ethernet.init(ETHERNET_CS_PIN);
|
||||
break;
|
||||
}
|
||||
|
||||
if(_preferences->getBool(preference_mqtt_log_enabled))
|
||||
{
|
||||
|
||||
@@ -6,10 +6,16 @@
|
||||
#include <Ethernet.h>
|
||||
#include <Preferences.h>
|
||||
|
||||
enum class W5500Variant
|
||||
{
|
||||
Generic = 1,
|
||||
M5StackAtomPoe = 2
|
||||
};
|
||||
|
||||
class W5500Device : public NetworkDevice
|
||||
{
|
||||
public:
|
||||
explicit W5500Device(const String& hostname, Preferences* _preferences);
|
||||
explicit W5500Device(const String& hostname, Preferences* _preferences, int variant);
|
||||
~W5500Device();
|
||||
|
||||
virtual void initialize();
|
||||
@@ -61,6 +67,7 @@ private:
|
||||
int _maintainResult = 0;
|
||||
bool _hasDHCPAddress = false;
|
||||
char* _path;
|
||||
W5500Variant _variant;
|
||||
|
||||
byte _mac[6];
|
||||
};
|
||||
Reference in New Issue
Block a user