From 4090098a97599bb250209fb2969d5416f4cb699d Mon Sep 17 00:00:00 2001 From: Ewoud Date: Mon, 23 Sep 2024 22:14:08 +0200 Subject: [PATCH] Refactor Network module pio.ini - add STARBASE_ETHERNET - show optional features SysModNetwork - use STARBASE_ETHERNET - reorder ui - on off for each connection type - status for each connection - auto init and stop AP - align naming --- misc/testOutput.txt | 1 - platformio.ini | 11 +- src/Sys/SysModNetwork.cpp | 451 +++++++++++++++++++++++--------------- src/Sys/SysModNetwork.h | 25 ++- src/Sys/SysModWeb.h | 2 +- 5 files changed, 296 insertions(+), 194 deletions(-) diff --git a/misc/testOutput.txt b/misc/testOutput.txt index 53f22b40..10a14109 100644 --- a/misc/testOutput.txt +++ b/misc/testOutput.txt @@ -80,7 +80,6 @@ callVarChangeFun fixSize unknown type for {"x":32,"y":32,"z":1} setValue changed fixCount ->1024 StarJson destructing FastLED.addLeds new 16: 0-1024 -lastReconnectAttempt == 0 Access point disabled (init). Connecting to WiFi ewtr / ********* setValue var vlLoopps[0] value null not array, creating diff --git a/platformio.ini b/platformio.ini index a9cee12c..319aaf7a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -75,20 +75,23 @@ lib_deps = build_flags = -D APP=StarBase -D PIOENV=$PIOENV - -D VERSION=24092014 ; Date and time (GMT!), update at every commit!! + -D VERSION=24092320 ; Date and time (GMT!), update at every commit!! -D LFS_THREADSAFE ; enables use of semaphores in LittleFS driver -D STARBASE_DEVMODE -mtext-section-literals ;otherwise [UserModLive::setup()]+0xa17): dangerous relocation: l32r: literal target out of range (try using text-section-literals) ;for StarLight, first only for s2, now for all due to something in UserModLive.Setup... ${ESPAsyncWebServer.build_flags} ;alternatively PsychicHttp - ${STARBASE_USERMOD_E131.build_flags} - ${STARBASE_USERMOD_MPU6050.build_flags} + ;optional: + -D STARBASE_ETHERNET ; +41.876 bytes (2.2%) + ${STARBASE_USERMOD_E131.build_flags} ;+11.416 bytes 0.6% + ${STARBASE_USERMOD_MPU6050.build_flags} ;+35.308 bytes 1.8% ; ${STARBASE_USERMOD_HA.build_flags} - ${STARBASE_USERMOD_LIVE.build_flags} + ${STARBASE_USERMOD_LIVE.build_flags} ;+222.204 bytes 11.7% lib_deps = ${ESPAsyncWebServer.lib_deps} ;alternatively PsychicHttp https://github.com/bblanchon/ArduinoJson.git # 7.1.0 ; https://github.com/Jason2866/ESP32_Show_Info.git + ;optional: ${STARBASE_USERMOD_E131.lib_deps} ${STARBASE_USERMOD_MPU6050.lib_deps} ; ${STARBASE_USERMOD_HA.lib_deps} diff --git a/src/Sys/SysModNetwork.cpp b/src/Sys/SysModNetwork.cpp index d85b819f..f87dc045 100644 --- a/src/Sys/SysModNetwork.cpp +++ b/src/Sys/SysModNetwork.cpp @@ -18,8 +18,9 @@ #include "User/UserModMDNS.h" #include "SysModPins.h" -#include - +#ifdef STARBASE_ETHERNET + #include +#endif SysModNetwork::SysModNetwork() :SysModule("Network") {}; @@ -35,132 +36,185 @@ void SysModNetwork::setup() { // ui->setComment(var, "List of defined and available Wifi APs"); // }); - ui->initText(parentVar, "ssid", "", 31, false); + JsonObject currentVar; + + #ifdef STARBASE_ETHERNET - ui->initPassword(parentVar, "pw", "", 63, false, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + currentVar = ui->initCheckBox(parentVar, "ethOn", true, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun case onUI: - ui->setLabel(var, "Password"); + ui->setLabel(var, "Ethernet"); return true; + //initEthernet not done in onChange as initEthernet needs a bit of a delay default: return false; - }}); + }}); + + ui->initSelect(currentVar, "ethConfig", 0, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun + case onUI: { + ui->setLabel(var, "Config"); + JsonArray options = ui->setOptions(var); + options.add("Manual"); + options.add("Olimex ESP32 Gateway"); + return true; + } + case onChange: + Variable(var).preDetails(); + mdl->setValueRowNr = rowNr; + + if (var["value"] == 0) {//manual + ui->initNumber(var, "ethaddr", (uint16_t)0, 0, 255, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun + case onUI: + ui->setLabel(var, "Address"); + return true; + case onChange: + ethActive = false; + return true; + default: return false; + }}); + ui->initPin(var, "ethpower", 14, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun + case onUI: + ui->setLabel(var, "Power"); + return true; + case onChange: + ethActive = false; + return true; + default: return false; + }}); + ui->initPin(var, "ethmdc", 23, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun + case onUI: + ui->setLabel(var, "mdc"); + return true; + case onChange: + ethActive = false; + return true; + default: return false; + }}); + ui->initPin(var, "ethmdio", 18, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun + case onUI: + ui->setLabel(var, "mdio"); + return true; + case onChange: + ethActive = false; + return true; + default: return false; + }}); + ui->initSelect(var, "ethtype", ETH_PHY_LAN8720, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun + case onUI: { + ui->setLabel(var, "Type"); + JsonArray options = ui->setOptions(var); + options.add("LAN8720"); + options.add("TLK110"); + options.add("RTL8201"); + options.add("DP83848"); + options.add("DM9051"); + options.add("KSZ8041"); + options.add("KSZ8081"); + options.add("MAX"); + return true; + } + case onChange: + ethActive = false; + return true; + default: return false; + }}); + ui->initSelect(var, "ethclkmode", ETH_CLOCK_GPIO17_OUT, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun + case onUI: { + ui->setLabel(var, "Clock mode"); + JsonArray options = ui->setOptions(var); + options.add("GPIO0_IN"); + options.add("GPIO0_OUT"); + options.add("GPIO16_OUT"); + options.add("GPIO17_OUT"); + return true; + } + case onChange: + ethActive = false; + return true; + default: return false; + }}); + } + + Variable(var).postDetails(rowNr); + mdl->setValueRowNr = UINT8_MAX; + + ethActive = false; + // initEthernet(); //try to connect + + return true; + default: return false; + }}); + + ui->initText(currentVar, "etStatus", nullptr, 32, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + case onUI: + ui->setLabel(var, "Status"); + return true; + default: return false; + }}); - ui->initButton(parentVar, "connect", false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun - // case onUI: - // ui->setComment(var, "Force reconnect (loose current connection)"); - // return true; + #endif + + currentVar = ui->initCheckBox(parentVar, "wifiOn", true, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + case onUI: + ui->setLabel(var, "WiFi"); + return true; case onChange: - // mdl->doWriteModel = true; //saves the model - initConnection(); //try to connect + if (var["value"].as()) + initWiFiConnection(); + else + stopWiFiConnection(); return true; default: return false; }}); - ui->initText(parentVar, "rssi", nullptr, 32, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun - case onUI: - ui->setLabel(var, "Wifi signal"); + ui->initText(currentVar, "ssid", "", 31, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + case onChange: + if (mdl->getValue("wifiOn").as()) { + stopWiFiConnection(); + initWiFiConnection(); + } return true; default: return false; }}); - ui->initSelect(parentVar, "ethernet", 0, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun - case onUI: { - JsonArray options = ui->setOptions(var); - options.add("None"); - options.add("Manual"); - options.add("Olimex ESP32 Gateway"); - options.add("Other"); - options.add("Another"); - options.add("tbd"); + ui->initPassword(currentVar, "pw", "", 63, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + case onUI: + ui->setLabel(var, "Password"); return true; - } case onChange: - Variable(var).preDetails(); - mdl->setValueRowNr = rowNr; - - if (var["value"] == 1) {//manual - ui->initNumber(var, "ethaddr", (uint16_t)0, 0, 255, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun - case onUI: - ui->setLabel(var, "Address"); - return true; - case onChange: - successfullyConfiguredEthernet = false; - return true; - default: return false; - }}); - ui->initPin(var, "ethpower", 14, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun - case onUI: - ui->setLabel(var, "Power"); - return true; - case onChange: - successfullyConfiguredEthernet = false; - return true; - default: return false; - }}); - ui->initPin(var, "ethmdc", 23, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun - case onUI: - ui->setLabel(var, "mdc"); - return true; - case onChange: - successfullyConfiguredEthernet = false; - return true; - default: return false; - }}); - ui->initPin(var, "ethmdio", 18, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun - case onUI: - ui->setLabel(var, "mdio"); - return true; - case onChange: - successfullyConfiguredEthernet = false; - return true; - default: return false; - }}); - ui->initSelect(var, "ethtype", ETH_PHY_LAN8720, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun - case onUI: { - ui->setLabel(var, "Type"); - JsonArray options = ui->setOptions(var); - options.add("LAN8720"); - options.add("TLK110"); - options.add("RTL8201"); - options.add("DP83848"); - options.add("DM9051"); - options.add("KSZ8041"); - options.add("KSZ8081"); - options.add("MAX"); - return true; - } - case onChange: - successfullyConfiguredEthernet = false; - return true; - default: return false; - }}); - ui->initSelect(var, "ethclkmode", ETH_CLOCK_GPIO17_OUT, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun - case onUI: { - ui->setLabel(var, "Clock mode"); - JsonArray options = ui->setOptions(var); - options.add("GPIO0_IN"); - options.add("GPIO0_OUT"); - options.add("GPIO16_OUT"); - options.add("GPIO17_OUT"); - return true; - } - case onChange: - successfullyConfiguredEthernet = false; - return true; - default: return false; - }}); + if (mdl->getValue("wifiOn").as()) { + stopWiFiConnection(); + initWiFiConnection(); } + return true; + default: return false; + }}); - Variable(var).postDetails(rowNr); - mdl->setValueRowNr = UINT8_MAX; - - successfullyConfiguredEthernet = false; - // initEthernet(); //try to connect + ui->initText(currentVar, "rssi", nullptr, 32, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + case onUI: + ui->setLabel(var, "Signal"); + return true; + default: return false; + }}); + ui->initText(currentVar, "wfStatus", nullptr, 32, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + case onUI: + ui->setLabel(var, "Status"); return true; default: return false; }}); - ui->initText(parentVar, "nwstatus", nullptr, 32, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + currentVar = ui->initCheckBox(parentVar, "apOn", false, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + case onUI: + ui->setLabel(var, "AP"); + return true; + case onChange: + if (var["value"].as()) + initAP(); + else + stopAP(); + return true; + default: return false; + }}); + ui->initText(currentVar, "apStatus", nullptr, 32, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun case onUI: ui->setLabel(var, "Status"); return true; @@ -170,112 +224,132 @@ void SysModNetwork::setup() { } void SysModNetwork::loop1s() { - handleConnection(); //once per second is enough + + #ifdef STARBASE_ETHERNET + mdl->setUIValueV("etStatus", "%s %s", ethActive?ETH.localIP()[0]?"🟢":"🟠":"🛑", ethActive?ETH.localIP().toString().c_str():"inactive"); + #endif + mdl->setUIValueV("wfStatus", "%s %s (s:%d)", wfActive?WiFi.localIP()[0]?"🟢":"🟠":"🛑", wfActive?WiFi.localIP().toString().c_str():"inactive", WiFi.status()); + mdl->setUIValueV("apStatus", "%s %s", apActive?WiFi.softAPIP()[0]?"🟢":"🟠":"🛑", apActive?WiFi.softAPIP().toString().c_str():"inactive"); mdl->setUIValueV("rssi", "%d dBm", WiFi.RSSI()); - mdl->setUIValueV("nwstatus", "Connected %s (e:%s s:%s)", WiFi.localIP().toString().c_str(), ETH.localIP().toString().c_str(), WiFi.softAPIP().toString().c_str()); - initEthernet(); -} -void SysModNetwork::loop10s() { - if (millis() < 60000) - ppf("%s %s %s\n", WiFi.localIP().toString().c_str(), ETH.localIP().toString().c_str(), WiFi.softAPIP().toString().c_str()); // show IP the first minute -} + #ifdef STARBASE_ETHERNET + //not done in onChange as initEthernet needs a bit of a delay + if (!ethActive && mdl->getValue("ethOn").as()) + initEthernet(); + #endif -void SysModNetwork::handleConnection() { - if (lastReconnectAttempt == 0) { // do this only once - ppf("lastReconnectAttempt == 0\n"); - initConnection(); //WiFi connection - return; - } + // if (!apActive && mdl->getValue("apOn").as()) { + // stopAP(); + // initAP(); + // } - if (apActive) { + if (apActive) handleAP(); - } +} - //if not connected // || ETH.localIP()[0] != 0 - if (!((WiFi.localIP()[0] != 0 && WiFi.status() == WL_CONNECTED))) { //!Network.isConfirmedConnection() - if (isConfirmedConnection) { //should not be confirmed as not connected -> lost connection -> retry - ppf("Disconnected!\n"); - initConnection(); //WiFi connection - } +void SysModNetwork::loop10s() { + if (millis() < 60000) {// show IP the first minute + #ifdef STARBASE_ETHERNET + ppf("e:%s ", ETH.localIP().toString().c_str()); + #endif + ppf("w:%s a:%s\n", WiFi.localIP().toString().c_str(), WiFi.softAPIP().toString().c_str()); // show IP the first minute + } - //if no connection for more then 6 seconds (was 12) - if (!apActive && millis() - lastReconnectAttempt > 6000 ) { //&& (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN) - ppf("Not connected AP.\n"); + //initAP if no IP's, stopAP if IP's and apOn is false + #ifdef STARBASE_ETHERNET + //if no ip's found, init AP + if (ETH.localIP()[0] == 0 && WiFi.localIP()[0] == 0) { + #else + if (WiFi.localIP()[0] == 0) { + #endif + if (!apActive && WiFi.softAPIP()[0] == 0) { + ppf("no IP's found -> initAP\n"); initAP(); } - } else if (!isConfirmedConnection) { //newly connected - mdl->setUIValueV("nwstatus", "Connected %s (e:%s s:%s)", WiFi.localIP().toString().c_str(), ETH.localIP().toString().c_str(), WiFi.softAPIP().toString().c_str()); - ppf("Connected %s %s %s\n", WiFi.localIP().toString().c_str(), ETH.localIP().toString().c_str(), WiFi.softAPIP().toString().c_str()); - - isConfirmedConnection = true; - - mdls->newConnection = true; // send all modules connect notification - - // shut down AP - if (apActive) { //apBehavior != AP_BEHAVIOR_ALWAYS + } else { + if (apActive && !mdl->getValue("apOn").as()) { + ppf("IP's found -> stopAP (%s %s)\n", ETH.localIP().toString().c_str(), WiFi.localIP().toString().c_str()); stopAP(); } } } -void SysModNetwork::initConnection() { +void SysModNetwork::initWiFiConnection() { - WiFi.disconnect(true); // close old connections + if (wfActive ) //allready success && WiFi.localIP()[0] != 0 + return; - lastReconnectAttempt = millis(); + WiFi.disconnect(true); // close old connections //close ap if not ap - if (!apActive) { - stopAP(); - WiFi.mode(WIFI_STA); - } + // if (!apActive) { + // stopAP(); + // WiFi.mode(WIFI_STA); + // } const char * ssid = mdl->getValue("ssid"); const char * password = mdl->getValue("pw"); if (ssid && strlen(ssid)>0 && password) { char passXXX [64] = ""; for (int i = 0; i < strlen(password); i++) strncat(passXXX, "*", sizeof(passXXX)-1); - ppf("Connecting to WiFi %s / %s\n", ssid, passXXX); WiFi.begin(ssid, password); + ppf("initWiFiConnection success %s / %s s:%d\n", ssid, passXXX, WiFi.status()); //6 is disconnected #if defined(STARBASE_LOLIN_WIFI_FIX ) WiFi.setTxPower(WIFI_POWER_8_5dBm ); #endif WiFi.setSleep(false); WiFi.setHostname(mdns->cmDNS); //use the mdns name (instance name or star-mac) + + wfActive = true; + if (!connected) { + connected = true; + mdls->newConnection = true; + } + // } + // else ppf("initWiFiConnection failed: status not connected\n"); } else - ppf("initConnection error ssid:%s pw:%s\n", ssid?ssid:"No SSID", password?password:"No Password"); + ppf("initWiFiConnection not succesful ssid:%s pw:%s s:%d\n", ssid?ssid:"No SSID", password?password:"No Password", WiFi.status()); +} + +void SysModNetwork::stopWiFiConnection() { + if (!wfActive) return; - isConfirmedConnection = false; //need to test if really connected in handleConnection + WiFi.disconnect(true); + wfActive = false; + ppf("stopWiFiConnection s:%d\n", WiFi.status()); } void SysModNetwork::initAP() { - const char * apSSID = mdl->getValue("name"); - ppf("Opening access point %s\n", apSSID); - WiFi.softAPConfig(IPAddress(4, 3, 2, 1), IPAddress(4, 3, 2, 1), IPAddress(255, 255, 255, 0)); - WiFi.softAP(apSSID, NULL, apChannel, false); //no password!!! - #if defined(STARBASE_LOLIN_WIFI_FIX ) - WiFi.setTxPower(WIFI_POWER_8_5dBm ); - #endif - if (!apActive) // start captive portal if AP active - { - mdl->setUIValueV("nwstatus", "AP %s / %s @ %s", apSSID, "NULL", WiFi.softAPIP().toString().c_str()); + if (apActive) // && WiFi.softAPIP()[0] != 0 + return; + const char * apSSID = mdl->getValue("name"); + if (WiFi.softAPConfig(IPAddress(4, 3, 2, 1), IPAddress(4, 3, 2, 1), IPAddress(255, 255, 255, 0)) + && WiFi.softAP(apSSID, NULL, apChannel, false)) { //no password!!! + ppf("AP success %s %s s:%d\n", apSSID, WiFi.softAPIP().toString().c_str(), WiFi.status()); //6 is disconnected + #if defined(STARBASE_LOLIN_WIFI_FIX ) + WiFi.setTxPower(WIFI_POWER_8_5dBm ); + #endif //for captive portal dnsServer.setErrorReplyCode(DNSReplyCode::NoError); dnsServer.start(53, "*", WiFi.softAPIP()); apActive = true; - mdls->newConnection = true; // send all modules connect notification + if (!connected) { + connected = true; + mdls->newConnection = true; + } } + else ppf("initAP not successful\n"); } void SysModNetwork::stopAP() { + if (!apActive) return; //allready stopped dnsServer.stop(); WiFi.softAPdisconnect(true); apActive = false; - ppf("Access point disabled (handle).\n"); + ppf("stopAP s:%d\n", WiFi.status()); } void SysModNetwork::handleAP() { @@ -283,19 +357,20 @@ void SysModNetwork::handleAP() { wifi_sta_list_t stationList; esp_wifi_ap_get_sta_list(&stationList); stac = stationList.num; - if (stac != stacO) { - stacO = stac; + if (stac != stationCount) { //stationCount changed + stationCount = stac; if (WiFi.status() != WL_CONNECTED) { - ppf("Connected AP clients: %d %d\n", stac, WiFi.status()); //6 is disconnected + ppf("handleAP changed: #:%d s:%d\n", stac, WiFi.status()); //6 is disconnected if (stac) WiFi.disconnect(); // disable search so that AP can work else - initConnection(); // restart search + initWiFiConnection(); // restart search } } dnsServer.processNextRequest(); //for captiveportal } +#ifdef STARBASE_ETHERNET typedef struct EthernetSettings { uint8_t eth_address; int eth_power; @@ -309,23 +384,20 @@ typedef struct EthernetSettings { bool SysModNetwork::initEthernet() { - if (successfullyConfiguredEthernet) { - // DEBUG_PRINTLN(F("initE: ETH already successfully configured, ignoring")); + if (ethActive) { // && ETH.localIP()[0] != 0 return false; } pinsM->deallocatePin(UINT8_MAX, "Eth"); - uint8_t ethernet = mdl->getValue("ethernet"); + uint8_t ethernet = mdl->getValue("ethConfig"); ethernet_settings es; bool result; switch (ethernet) { - case 0: //none - return false; - case 1: //manual + case 0: //manual { es = { mdl->getValue("ethaddr"), // eth_address, @@ -338,7 +410,7 @@ bool SysModNetwork::initEthernet() { } break; - case 2: //Olimex + case 1: //Olimex { //WLEDMM: Olimex-ESP32-Gateway (like QuinLed-ESP32-Ethernet es = { @@ -389,7 +461,7 @@ bool SysModNetwork::initEthernet() { return false; } - if (!ETH.begin( + if (ETH.begin( (uint8_t) es.eth_address, (int) es.eth_power, (int) es.eth_mdc, @@ -397,16 +469,37 @@ bool SysModNetwork::initEthernet() { (eth_phy_type_t) es.eth_type, (eth_clock_mode_t) es.eth_clk_mode )) { - ppf("initC: ETH.begin() failed\n"); + + ETH.setHostname(mdns->cmDNS); + + ethActive = true; + + //tbd: make eth vars readonly as once connected cannot be changed anymore + // mdl->findVar("ethOn")["ro"] = true; //not possible to change anymore if connected + + if (!connected) { + connected = true; + mdls->newConnection = true; + } + + ppf("initEthernet success %s s:%d\n", ETH.localIP().toString().c_str(), WiFi.status()); // WLEDMM + return true; + } + else { + ppf("initEthernet not successful s:%d\n", WiFi.status()); // de-allocate the allocated pins // for (managed_pin_type mpt : pinsToAllocate) { // pinManager.deallocatePin(mpt.pin, PinOwner::Ethernet); // } return false; } +} - successfullyConfiguredEthernet = true; - ppf("initC: *** Ethernet successfully configured! %s ***\n", ETH.localIP().toString().c_str()); // WLEDMM - return true; +void SysModNetwork::stopEthernet() { + if (!ethActive) return; + //not possible to stop ... + // esp_eth_stop(ETH.eth_handle); + // ethActive = false; +} -} \ No newline at end of file +#endif \ No newline at end of file diff --git a/src/Sys/SysModNetwork.h b/src/Sys/SysModNetwork.h index e32b9ebb..8af2623f 100644 --- a/src/Sys/SysModNetwork.h +++ b/src/Sys/SysModNetwork.h @@ -25,24 +25,31 @@ class SysModNetwork:public SysModule { void loop1s(); void loop10s(); - void handleConnection(); - void initConnection(); + // void handleConnections(); + + #ifdef STARBASE_ETHERNET + bool initEthernet(); + void stopEthernet(); + #endif + + void initWiFiConnection(); + void stopWiFiConnection(); - void handleAP(); void initAP(); + void handleAP(); void stopAP(); - bool initEthernet(); private: + #ifdef STARBASE_ETHERNET + bool ethActive = false; //currently only one call to ETH.begin is possible, wether successful or not: reboot needed for other attempt + #endif bool apActive = false; - unsigned32 lastReconnectAttempt = 0; + bool wfActive = false; byte apChannel = 1; // 2.4GHz WiFi AP channel (1-13) - bool isConfirmedConnection = false; DNSServer dnsServer; - byte stacO = 0; //stationCount - - bool successfullyConfiguredEthernet = false; //currently only one call to ETH.begin is possible, wether successful or not: reboot needed for other attempt + byte stationCount = 0; + bool connected = false; }; extern SysModNetwork *net; \ No newline at end of file diff --git a/src/Sys/SysModWeb.h b/src/Sys/SysModWeb.h index e5959801..6998c070 100644 --- a/src/Sys/SysModWeb.h +++ b/src/Sys/SysModWeb.h @@ -158,7 +158,7 @@ class SysModWeb:public SysModule { void sendResponseObject(WebClient * client = nullptr); void printClient(const char * text, WebClient * client) { - ppf("%s client: %d ...%d q:%d l:%d s:%d (#:%d)\n", text, client?client->id():-1, client?client->remoteIP()[3]:-1, client->queueIsFull(), client->queueLength(), client->status(), client->server()->count()); + ppf("%s client: %d ip:%s q:%d l:%d s:%d (#:%d)\n", text, client?client->id():-1, client?client->remoteIP().toString().c_str():"", client->queueIsFull(), client->queueLength(), client->status(), client->server()->count()); //status: { WS_DISCONNECTED, WS_CONNECTED, WS_DISCONNECTING } }