add astylerc and apply code formatting
This commit is contained in:
@@ -7,44 +7,44 @@ RTC_NOINIT_ATTR bool criticalEthFailure;
|
||||
extern char WiFi_fallbackDetect[14];
|
||||
|
||||
EthernetDevice::EthernetDevice(const String& hostname, Preferences* preferences, const IPConfiguration* ipConfiguration, const std::string& deviceName, uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t ethtype, eth_clock_mode_t clock_mode)
|
||||
: NetworkDevice(hostname, ipConfiguration),
|
||||
_deviceName(deviceName),
|
||||
_phy_addr(phy_addr),
|
||||
_power(power),
|
||||
_mdc(mdc),
|
||||
_mdio(mdio),
|
||||
_type(ethtype),
|
||||
_clock_mode(clock_mode),
|
||||
_useSpi(false),
|
||||
_preferences(preferences)
|
||||
: NetworkDevice(hostname, ipConfiguration),
|
||||
_deviceName(deviceName),
|
||||
_phy_addr(phy_addr),
|
||||
_power(power),
|
||||
_mdc(mdc),
|
||||
_mdio(mdio),
|
||||
_type(ethtype),
|
||||
_clock_mode(clock_mode),
|
||||
_useSpi(false),
|
||||
_preferences(preferences)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
EthernetDevice::EthernetDevice(const String &hostname,
|
||||
Preferences *preferences,
|
||||
const IPConfiguration *ipConfiguration,
|
||||
const std::string &deviceName,
|
||||
uint8_t phy_addr,
|
||||
int cs,
|
||||
int irq,
|
||||
int rst,
|
||||
int spi_sck,
|
||||
int spi_miso,
|
||||
int spi_mosi,
|
||||
eth_phy_type_t ethtype)
|
||||
: NetworkDevice(hostname, ipConfiguration),
|
||||
_deviceName(deviceName),
|
||||
_phy_addr(phy_addr),
|
||||
_cs(cs),
|
||||
_irq(irq),
|
||||
_rst(rst),
|
||||
_spi_sck(spi_sck),
|
||||
_spi_miso(spi_miso),
|
||||
_spi_mosi(spi_mosi),
|
||||
_type(ethtype),
|
||||
_useSpi(true),
|
||||
_preferences(preferences)
|
||||
Preferences *preferences,
|
||||
const IPConfiguration *ipConfiguration,
|
||||
const std::string &deviceName,
|
||||
uint8_t phy_addr,
|
||||
int cs,
|
||||
int irq,
|
||||
int rst,
|
||||
int spi_sck,
|
||||
int spi_miso,
|
||||
int spi_mosi,
|
||||
eth_phy_type_t ethtype)
|
||||
: NetworkDevice(hostname, ipConfiguration),
|
||||
_deviceName(deviceName),
|
||||
_phy_addr(phy_addr),
|
||||
_cs(cs),
|
||||
_irq(irq),
|
||||
_rst(rst),
|
||||
_spi_sck(spi_sck),
|
||||
_spi_miso(spi_miso),
|
||||
_spi_mosi(spi_mosi),
|
||||
_type(ethtype),
|
||||
_useSpi(true),
|
||||
_preferences(preferences)
|
||||
{
|
||||
init();
|
||||
}
|
||||
@@ -78,7 +78,7 @@ void EthernetDevice::initialize()
|
||||
_hardwareInitialized = ETH.begin(_type, _phy_addr, _cs, _irq, _rst, SPI);
|
||||
criticalEthFailure = false;
|
||||
}
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
else
|
||||
{
|
||||
Log->println(F("Use RMII"));
|
||||
@@ -90,7 +90,7 @@ void EthernetDevice::initialize()
|
||||
_checkIpTs = (esp_timer_get_time() / 1000) + 2000;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if(_hardwareInitialized)
|
||||
{
|
||||
@@ -138,55 +138,56 @@ void EthernetDevice::update()
|
||||
|
||||
void EthernetDevice::onNetworkEvent(arduino_event_id_t event, arduino_event_info_t info)
|
||||
{
|
||||
switch (event) {
|
||||
case ARDUINO_EVENT_ETH_START:
|
||||
Log->println("ETH Started");
|
||||
ETH.setHostname(_hostname.c_str());
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_CONNECTED:
|
||||
Log->println("ETH Connected");
|
||||
if(!localIP().equals("0.0.0.0"))
|
||||
{
|
||||
_connected = true;
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_GOT_IP:
|
||||
Log->printf("ETH Got IP: '%s'\n", esp_netif_get_desc(info.got_ip.esp_netif));
|
||||
Log->println(ETH);
|
||||
|
||||
// For RMII devices, this check is handled in the update() method.
|
||||
if(_useSpi && !_ipConfiguration->dhcpEnabled() && _ipConfiguration->ipAddress() != ETH.localIP())
|
||||
{
|
||||
Log->printf("Static IP not used, retrying to set static IP");
|
||||
ETH.config(_ipConfiguration->ipAddress(), _ipConfiguration->defaultGateway(), _ipConfiguration->subnet(), _ipConfiguration->dnsServer());
|
||||
ETH.begin(_type, _phy_addr, _cs, _irq, _rst, SPI);
|
||||
}
|
||||
|
||||
switch (event)
|
||||
{
|
||||
case ARDUINO_EVENT_ETH_START:
|
||||
Log->println("ETH Started");
|
||||
ETH.setHostname(_hostname.c_str());
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_CONNECTED:
|
||||
Log->println("ETH Connected");
|
||||
if(!localIP().equals("0.0.0.0"))
|
||||
{
|
||||
_connected = true;
|
||||
if(_preferences->getBool(preference_ntw_reconfigure, false))
|
||||
{
|
||||
_preferences->putBool(preference_ntw_reconfigure, false);
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_LOST_IP:
|
||||
Log->println("ETH Lost IP");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_DISCONNECTED:
|
||||
Log->println("ETH Disconnected");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_STOP:
|
||||
Log->println("ETH Stopped");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
default:
|
||||
Log->print("ETH Event: ");
|
||||
Log->println(event);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_GOT_IP:
|
||||
Log->printf("ETH Got IP: '%s'\n", esp_netif_get_desc(info.got_ip.esp_netif));
|
||||
Log->println(ETH);
|
||||
|
||||
// For RMII devices, this check is handled in the update() method.
|
||||
if(_useSpi && !_ipConfiguration->dhcpEnabled() && _ipConfiguration->ipAddress() != ETH.localIP())
|
||||
{
|
||||
Log->printf("Static IP not used, retrying to set static IP");
|
||||
ETH.config(_ipConfiguration->ipAddress(), _ipConfiguration->defaultGateway(), _ipConfiguration->subnet(), _ipConfiguration->dnsServer());
|
||||
ETH.begin(_type, _phy_addr, _cs, _irq, _rst, SPI);
|
||||
}
|
||||
|
||||
_connected = true;
|
||||
if(_preferences->getBool(preference_ntw_reconfigure, false))
|
||||
{
|
||||
_preferences->putBool(preference_ntw_reconfigure, false);
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_LOST_IP:
|
||||
Log->println("ETH Lost IP");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_DISCONNECTED:
|
||||
Log->println("ETH Disconnected");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_STOP:
|
||||
Log->println("ETH Stopped");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
default:
|
||||
Log->print("ETH Event: ");
|
||||
Log->println(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +213,10 @@ bool EthernetDevice::isApOpen()
|
||||
|
||||
void EthernetDevice::onDisconnected()
|
||||
{
|
||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000))
|
||||
{
|
||||
restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
}
|
||||
}
|
||||
|
||||
int8_t EthernetDevice::signalStrength()
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "../Logger.h"
|
||||
|
||||
IPConfiguration::IPConfiguration(Preferences *preferences)
|
||||
: _preferences(preferences)
|
||||
: _preferences(preferences)
|
||||
{
|
||||
if(!dhcpEnabled() && _preferences->getString(preference_ip_address, "").length() <= 0)
|
||||
{
|
||||
@@ -23,10 +23,14 @@ IPConfiguration::IPConfiguration(Preferences *preferences)
|
||||
}
|
||||
else
|
||||
{
|
||||
Log->print(F("IP address: ")); Log->print(ipAddress());
|
||||
Log->print(F(", Subnet: ")); Log->print(subnet());
|
||||
Log->print(F(", Gateway: ")); Log->print(defaultGateway());
|
||||
Log->print(F(", DNS: ")); Log->println(dnsServer());
|
||||
Log->print(F("IP address: "));
|
||||
Log->print(ipAddress());
|
||||
Log->print(F(", Subnet: "));
|
||||
Log->print(subnet());
|
||||
Log->print(F(", Gateway: "));
|
||||
Log->print(defaultGateway());
|
||||
Log->print(F(", DNS: "));
|
||||
Log->println(dnsServer());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#include "../RestartReason.h"
|
||||
|
||||
WifiDevice::WifiDevice(const String& hostname, Preferences* preferences, const IPConfiguration* ipConfiguration)
|
||||
: NetworkDevice(hostname, ipConfiguration),
|
||||
_preferences(preferences)
|
||||
: NetworkDevice(hostname, ipConfiguration),
|
||||
_preferences(preferences)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -52,10 +52,10 @@ void WifiDevice::initialize()
|
||||
for (int i = 0; i < _foundNetworks; i++)
|
||||
{
|
||||
Log->println(String(F("SSID ")) + WiFi.SSID(i) + String(F(" found with RSSI: ")) +
|
||||
String(WiFi.RSSI(i)) + String(F("(")) +
|
||||
String(constrain((100.0 + WiFi.RSSI(i)) * 2, 0, 100)) +
|
||||
String(F(" %) and BSSID: ")) + WiFi.BSSIDstr(i) +
|
||||
String(F(" and channel: ")) + String(WiFi.channel(i)));
|
||||
String(WiFi.RSSI(i)) + String(F("(")) +
|
||||
String(constrain((100.0 + WiFi.RSSI(i)) * 2, 0, 100)) +
|
||||
String(F(" %) and BSSID: ")) + WiFi.BSSIDstr(i) +
|
||||
String(F(" and channel: ")) + String(WiFi.channel(i)));
|
||||
}
|
||||
|
||||
if (_connectOnScanDone && _foundNetworks > 0)
|
||||
@@ -78,11 +78,13 @@ void WifiDevice::initialize()
|
||||
_preferences->putBool(preference_wifi_converted, true);
|
||||
|
||||
wifi_config_t wifi_cfg;
|
||||
if(esp_wifi_get_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK) {
|
||||
if(esp_wifi_get_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK)
|
||||
{
|
||||
Log->println("Failed to get Wi-Fi configuration in RAM");
|
||||
}
|
||||
|
||||
if (esp_wifi_set_storage(WIFI_STORAGE_FLASH) != ESP_OK) {
|
||||
if (esp_wifi_set_storage(WIFI_STORAGE_FLASH) != ESP_OK)
|
||||
{
|
||||
Log->println("Failed to set storage Wi-Fi");
|
||||
}
|
||||
|
||||
@@ -107,7 +109,8 @@ void WifiDevice::initialize()
|
||||
memset(wifi_cfg.sta.ssid, 0, sizeof(wifi_cfg.sta.ssid));
|
||||
memset(wifi_cfg.sta.password, 0, sizeof(wifi_cfg.sta.password));
|
||||
|
||||
if (esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK) {
|
||||
if (esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK)
|
||||
{
|
||||
Log->println("Failed to clear NVS Wi-Fi configuration");
|
||||
}
|
||||
|
||||
@@ -159,7 +162,7 @@ void WifiDevice::initialize()
|
||||
|
||||
void WifiDevice::scan(bool passive, bool async)
|
||||
{
|
||||
if(!_connecting)
|
||||
if(!_connecting)
|
||||
{
|
||||
WiFi.scanDelete();
|
||||
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
|
||||
@@ -210,10 +213,10 @@ bool WifiDevice::connect()
|
||||
if (ssid == WiFi.SSID(i))
|
||||
{
|
||||
Log->println(String(F("Saved SSID ")) + ssid + String(F(" found with RSSI: ")) +
|
||||
String(WiFi.RSSI(i)) + String(F("(")) +
|
||||
String(constrain((100.0 + WiFi.RSSI(i)) * 2, 0, 100)) +
|
||||
String(F(" %) and BSSID: ")) + WiFi.BSSIDstr(i) +
|
||||
String(F(" and channel: ")) + String(WiFi.channel(i)));
|
||||
String(WiFi.RSSI(i)) + String(F("(")) +
|
||||
String(constrain((100.0 + WiFi.RSSI(i)) * 2, 0, 100)) +
|
||||
String(F(" %) and BSSID: ")) + WiFi.BSSIDstr(i) +
|
||||
String(F(" and channel: ")) + String(WiFi.channel(i)));
|
||||
if (bestConnection == -1)
|
||||
{
|
||||
bestConnection = i;
|
||||
@@ -232,7 +235,10 @@ bool WifiDevice::connect()
|
||||
{
|
||||
Log->print("No network found with SSID: ");
|
||||
Log->println(ssid);
|
||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000))
|
||||
{
|
||||
restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
}
|
||||
_connectOnScanDone = true;
|
||||
_openAP = false;
|
||||
scan(false, true);
|
||||
@@ -243,42 +249,42 @@ bool WifiDevice::connect()
|
||||
_connecting = true;
|
||||
esp_wifi_scan_stop();
|
||||
Log->println(String(F("Trying to connect to SSID ")) + ssid + String(F(" found with RSSI: ")) +
|
||||
String(WiFi.RSSI(bestConnection)) + String(F("(")) +
|
||||
String(constrain((100.0 + WiFi.RSSI(bestConnection)) * 2, 0, 100)) +
|
||||
String(F(" %) and BSSID: ")) + WiFi.BSSIDstr(bestConnection) +
|
||||
String(F(" and channel: ")) + String(WiFi.channel(bestConnection)));
|
||||
|
||||
|
||||
String(WiFi.RSSI(bestConnection)) + String(F("(")) +
|
||||
String(constrain((100.0 + WiFi.RSSI(bestConnection)) * 2, 0, 100)) +
|
||||
String(F(" %) and BSSID: ")) + WiFi.BSSIDstr(bestConnection) +
|
||||
String(F(" and channel: ")) + String(WiFi.channel(bestConnection)));
|
||||
|
||||
|
||||
if(!_ipConfiguration->dhcpEnabled())
|
||||
{
|
||||
WiFi.config(_ipConfiguration->ipAddress(), _ipConfiguration->dnsServer(), _ipConfiguration->defaultGateway(), _ipConfiguration->subnet());
|
||||
}
|
||||
|
||||
|
||||
WiFi.begin(ssid, pass);
|
||||
auto status = WiFi.waitForConnectResult(10000);
|
||||
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case WL_CONNECTED:
|
||||
case WL_CONNECTED:
|
||||
Log->println("WiFi connected");
|
||||
break;
|
||||
case WL_NO_SSID_AVAIL:
|
||||
case WL_NO_SSID_AVAIL:
|
||||
Log->println("WiFi SSID not available");
|
||||
break;
|
||||
case WL_CONNECT_FAILED:
|
||||
case WL_CONNECT_FAILED:
|
||||
Log->println("WiFi connection failed");
|
||||
break;
|
||||
case WL_IDLE_STATUS:
|
||||
case WL_IDLE_STATUS:
|
||||
Log->println("WiFi changing status");
|
||||
break;
|
||||
case WL_DISCONNECTED:
|
||||
case WL_DISCONNECTED:
|
||||
Log->println("WiFi disconnected");
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
Log->println("WiFi timeout");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (status != WL_CONNECTED)
|
||||
{
|
||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000))
|
||||
@@ -326,7 +332,7 @@ bool WifiDevice::isConnected()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -350,12 +356,12 @@ void WifiDevice::onDisconnected()
|
||||
_connecting = true;
|
||||
String ssid = _preferences->getString(preference_wifi_ssid, "");
|
||||
String pass = _preferences->getString(preference_wifi_pass, "");
|
||||
|
||||
|
||||
if(!_ipConfiguration->dhcpEnabled())
|
||||
{
|
||||
WiFi.config(_ipConfiguration->ipAddress(), _ipConfiguration->dnsServer(), _ipConfiguration->defaultGateway(), _ipConfiguration->subnet());
|
||||
}
|
||||
|
||||
|
||||
WiFi.begin(ssid, pass);
|
||||
|
||||
int loop = 0;
|
||||
@@ -371,26 +377,29 @@ void WifiDevice::onDisconnected()
|
||||
|
||||
if(!isConnected())
|
||||
{
|
||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000))
|
||||
{
|
||||
restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
}
|
||||
|
||||
WiFi.disconnect(true);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
delay(500);
|
||||
WiFi.disconnect(true);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
delay(500);
|
||||
|
||||
wifi_mode_t wifiMode;
|
||||
esp_wifi_get_mode(&wifiMode);
|
||||
wifi_mode_t wifiMode;
|
||||
esp_wifi_get_mode(&wifiMode);
|
||||
|
||||
while (wifiMode != WIFI_MODE_STA || WiFi.status() == WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
Log->println(F("Waiting for WiFi mode change or disconnection."));
|
||||
esp_wifi_get_mode(&wifiMode);
|
||||
}
|
||||
while (wifiMode != WIFI_MODE_STA || WiFi.status() == WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
Log->println(F("Waiting for WiFi mode change or disconnection."));
|
||||
esp_wifi_get_mode(&wifiMode);
|
||||
}
|
||||
|
||||
_connectOnScanDone = true;
|
||||
_openAP = false;
|
||||
scan(false, true);
|
||||
_connectOnScanDone = true;
|
||||
_openAP = false;
|
||||
scan(false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user