make W5500 detection GPIO configurable
This commit is contained in:
44
Network.cpp
44
Network.cpp
@@ -10,7 +10,7 @@ Network* Network::_inst = nullptr;
|
||||
|
||||
RTC_NOINIT_ATTR char WiFi_fallbackDetect[14];
|
||||
|
||||
Network::Network(const NetworkDeviceType networkDevice, Preferences *preferences, const String& maintenancePathPrefix)
|
||||
Network::Network(Preferences *preferences, const String& maintenancePathPrefix)
|
||||
: _preferences(preferences)
|
||||
{
|
||||
_inst = this;
|
||||
@@ -23,19 +23,44 @@ Network::Network(const NetworkDeviceType networkDevice, Preferences *preferences
|
||||
{
|
||||
_maintenancePathPrefix[i] = maintenancePathPrefix.charAt(i);
|
||||
}
|
||||
setupDevice(networkDevice);
|
||||
setupDevice();
|
||||
}
|
||||
|
||||
|
||||
void Network::setupDevice(NetworkDeviceType hardware)
|
||||
void Network::setupDevice()
|
||||
{
|
||||
|
||||
if(strcmp(WiFi_fallbackDetect, "wifi_fallback") == 0)
|
||||
{
|
||||
Log->println(F("Switching to WiFi device as fallabck."));
|
||||
hardware = NetworkDeviceType::WiFi;
|
||||
Log->println(F("Switching to WiFi device as fallback."));
|
||||
_networkDeviceType = NetworkDeviceType::WiFi;
|
||||
}
|
||||
else
|
||||
{
|
||||
int hardwareDetect = _preferences->getInt(preference_network_hardware_detect);
|
||||
|
||||
if(hardwareDetect == 0)
|
||||
{
|
||||
hardwareDetect = 26;
|
||||
_preferences->putInt(preference_network_hardware_detect, hardwareDetect);
|
||||
}
|
||||
|
||||
if(hardwareDetect == -1)
|
||||
{
|
||||
Log->println(F("W5500 hardware is disable, using Wifi."));
|
||||
_networkDeviceType = NetworkDeviceType::WiFi;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log->print(F("Using PIN "));
|
||||
Log->print(hardwareDetect);
|
||||
Log->println(F(" for network device selection"));
|
||||
|
||||
pinMode(hardwareDetect, INPUT_PULLUP);
|
||||
_networkDeviceType = digitalRead(hardwareDetect) == HIGH ? NetworkDeviceType::WiFi : NetworkDeviceType::W5500;
|
||||
}
|
||||
}
|
||||
|
||||
switch(hardware)
|
||||
switch(_networkDeviceType)
|
||||
{
|
||||
case NetworkDeviceType::W5500:
|
||||
Log->println(F("Network device: W5500"));
|
||||
@@ -775,3 +800,8 @@ void Network::publishPresenceDetection(char *csv)
|
||||
{
|
||||
_presenceCsv = csv;
|
||||
}
|
||||
|
||||
const NetworkDeviceType Network::networkDeviceType()
|
||||
{
|
||||
return _networkDeviceType;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ enum class NetworkDeviceType
|
||||
class Network
|
||||
{
|
||||
public:
|
||||
explicit Network(const NetworkDeviceType networkDevice, Preferences* preferences, const String& maintenancePathPrefix);
|
||||
explicit Network(Preferences* preferences, const String& maintenancePathPrefix);
|
||||
|
||||
void initialize();
|
||||
int update();
|
||||
@@ -46,10 +46,12 @@ public:
|
||||
PubSubClient* mqttClient();
|
||||
bool isMqttConnected();
|
||||
|
||||
const NetworkDeviceType networkDeviceType();
|
||||
|
||||
private:
|
||||
static void onMqttDataReceivedCallback(char* topic, byte* payload, unsigned int length);
|
||||
void onMqttDataReceived(char*& topic, byte*& payload, unsigned int& length);
|
||||
void setupDevice(NetworkDeviceType hardware);
|
||||
void setupDevice();
|
||||
bool reconnect();
|
||||
|
||||
void buildMqttPath(const char* prefix, const char* path, char* outPath);
|
||||
@@ -78,5 +80,7 @@ private:
|
||||
unsigned long _lastMaintenanceTs = 0;
|
||||
unsigned long _lastRssiTs = 0;
|
||||
|
||||
NetworkDeviceType _networkDeviceType = (NetworkDeviceType)-1;
|
||||
|
||||
int8_t _lastRssi = 127;
|
||||
};
|
||||
|
||||
1
Pins.h
1
Pins.h
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define NETWORK_SELECT 26
|
||||
#define ETHERNET_CS_PIN 5
|
||||
#define ETHERNET_RESET_PIN 33
|
||||
#define TRIGGER_LOCK_PIN 32
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#define preference_mqtt_crt "mqttcrt"
|
||||
#define preference_mqtt_key "mqttkey"
|
||||
#define preference_mqtt_hass_discovery "hassdiscovery"
|
||||
#define preference_network_hardware_detect "nwhwdt"
|
||||
#define preference_hostname "hostname"
|
||||
#define preference_network_timeout "nettmout"
|
||||
#define preference_restart_on_disconnect "restdisc"
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define nuki_hub_version "6.7"
|
||||
#define nuki_hub_version "6.8"
|
||||
@@ -240,6 +240,11 @@ bool WebCfgServer::processArgs(String& message)
|
||||
_preferences->putString(preference_mqtt_key, value);
|
||||
configChanged = true;
|
||||
}
|
||||
else if(key == "NWHWDT")
|
||||
{
|
||||
_preferences->putInt(preference_network_hardware_detect, value.toInt());
|
||||
configChanged = true;
|
||||
}
|
||||
else if(key == "HASSDISCOVERY")
|
||||
{
|
||||
if(_preferences->getString(preference_mqtt_hass_discovery) != value)
|
||||
@@ -588,6 +593,7 @@ void WebCfgServer::buildMqttConfigHtml(String &response)
|
||||
printTextarea(response, "MQTTCA", "MQTT SSL CA Certificate (*, optional)", _preferences->getString(preference_mqtt_ca).c_str(), TLS_CA_MAX_SIZE);
|
||||
printTextarea(response, "MQTTCRT", "MQTT SSL Client Certificate (*, optional)", _preferences->getString(preference_mqtt_crt).c_str(), TLS_CERT_MAX_SIZE);
|
||||
printTextarea(response, "MQTTKEY", "MQTT SSL Client Key (*, optional)", _preferences->getString(preference_mqtt_key).c_str(), TLS_KEY_MAX_SIZE);
|
||||
printDropDown(response, "NWHWDT", "Network hardward detection", String(_preferences->getInt(preference_network_hardware_detect)), getNetworkDetectionOptions());
|
||||
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));
|
||||
printInputField(response, "RSTTMR", "Restart timer (minutes; -1 to disable)", _preferences->getInt(preference_restart_timer), 10);
|
||||
@@ -793,6 +799,36 @@ void WebCfgServer::printTextarea(String& response,
|
||||
response.concat("</td></tr>");
|
||||
}
|
||||
|
||||
void WebCfgServer::printDropDown(String &response, const char *token, const char *description, const String preselectedValue, const std::vector<std::pair<String, String>> options)
|
||||
{
|
||||
response.concat("<tr><td>");
|
||||
response.concat(description);
|
||||
response.concat("</td><td>");
|
||||
|
||||
response.concat("<select name=\"");
|
||||
response.concat(token);
|
||||
response.concat("\">");
|
||||
|
||||
for(const auto option : options)
|
||||
{
|
||||
if(option.first == preselectedValue)
|
||||
{
|
||||
response.concat("<option selected=\"selected\" value=\"");
|
||||
}
|
||||
else
|
||||
{
|
||||
response.concat("<option value=\"");
|
||||
}
|
||||
response.concat(option.first);
|
||||
response.concat("\">");
|
||||
response.concat(option.second);
|
||||
response.concat("</option>");
|
||||
}
|
||||
|
||||
response.concat("</select>");
|
||||
response.concat("</td></tr>");
|
||||
}
|
||||
|
||||
void WebCfgServer::buildNavigationButton(String &response, const char *caption, const char *targetPath)
|
||||
{
|
||||
response.concat("<form method=\"get\" action=\"");
|
||||
@@ -895,3 +931,19 @@ void WebCfgServer::sendFavicon()
|
||||
{
|
||||
_server.send(200, "image/png", (const char*)favicon_32x32, sizeof(favicon_32x32));
|
||||
}
|
||||
|
||||
const std::vector<std::pair<String, String>> WebCfgServer::getNetworkDetectionOptions() const
|
||||
{
|
||||
std::vector<std::pair<String, String>> options;
|
||||
|
||||
options.push_back(std::make_pair("-1", "Disable W5500"));
|
||||
|
||||
for(int i=16; i <= 33; i++)
|
||||
{
|
||||
String txt = "Detect W5500 via GPIO ";
|
||||
txt.concat(i);
|
||||
options.push_back(std::make_pair(String(i), txt));
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
@@ -47,8 +47,11 @@ private:
|
||||
void printInputField(String& response, const char* token, const char* description, const int value, size_t maxLength);
|
||||
void printCheckBox(String& response, const char* token, const char* description, const bool value);
|
||||
void printTextarea(String& response, const char *token, const char *description, const char *value, const size_t maxLength);
|
||||
void printDropDown(String &response, const char *token, const char *description, const String preselectedValue, std::vector<std::pair<String, String>> options);
|
||||
void buildNavigationButton(String& response, const char* caption, const char* targetPath);
|
||||
|
||||
const std::vector<std::pair<String, String>> getNetworkDetectionOptions() const;
|
||||
|
||||
void printParameter(String& response, const char* description, const char* value);
|
||||
|
||||
String generateConfirmCode();
|
||||
|
||||
10
main.cpp
10
main.cpp
@@ -159,7 +159,6 @@ void initPreferences()
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(NETWORK_SELECT, INPUT_PULLUP);
|
||||
|
||||
Serial.begin(115200);
|
||||
Log = &Serial;
|
||||
@@ -171,11 +170,8 @@ void setup()
|
||||
restartTs = preferences->getInt(preference_restart_timer) * 60 * 1000;
|
||||
}
|
||||
|
||||
// const NetworkDeviceType networkDevice = NetworkDeviceType::WiFi;
|
||||
const NetworkDeviceType networkDevice = digitalRead(NETWORK_SELECT) == HIGH ? NetworkDeviceType::WiFi : NetworkDeviceType::W5500;
|
||||
|
||||
const String mqttLockPath = preferences->getString(preference_mqtt_lock_path);
|
||||
network = new Network(networkDevice, preferences, mqttLockPath);
|
||||
network = new Network(preferences, mqttLockPath);
|
||||
network->initialize();
|
||||
networkLock = new NetworkLock(network, preferences);
|
||||
networkLock->initialize();
|
||||
@@ -189,7 +185,7 @@ void setup()
|
||||
preferences->putUInt(preference_deviceId, deviceId);
|
||||
}
|
||||
|
||||
initEthServer(networkDevice);
|
||||
initEthServer(network->networkDeviceType());
|
||||
|
||||
bleScanner = new BleScanner::Scanner();
|
||||
bleScanner->initialize("NukiHub");
|
||||
@@ -216,7 +212,7 @@ void setup()
|
||||
nukiOpener->initialize();
|
||||
}
|
||||
|
||||
webCfgServer = new WebCfgServer(nuki, nukiOpener, network, ethServer, preferences, networkDevice == NetworkDeviceType::WiFi);
|
||||
webCfgServer = new WebCfgServer(nuki, nukiOpener, network, ethServer, preferences, network->networkDeviceType() == NetworkDeviceType::WiFi);
|
||||
webCfgServer->initialize();
|
||||
|
||||
presenceDetection = new PresenceDetection(preferences, bleScanner, network);
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user