diff --git a/src/app.h b/src/app.h index 05b11469..cb546267 100644 --- a/src/app.h +++ b/src/app.h @@ -184,7 +184,11 @@ class app : public IApp, public ah::Scheduler { }*/ bool getWasInCh12to14(void) const override { - return false; // @todo mWifi.getWasInCh12to14(); + #if defined(ESP8266) + return mNetwork->getWasInCh12to14(); + #else + return false; + #endif } #endif /* !defined(ETHERNET) */ diff --git a/src/config/config.h b/src/config/config.h index 23e27a8c..a4b84934 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -78,7 +78,7 @@ #define DEF_ETH_CS_PIN 15 #endif #ifndef DEF_ETH_RST_PIN - #define DEF_ETH_RST_PIN 2 + #define DEF_ETH_RST_PIN DEF_PIN_OFF #endif #else /* defined(ETHERNET) */ // time in seconds how long the station info (ssid + pwd) will be tried diff --git a/src/config/settings.h b/src/config/settings.h index fb8689b9..8f20ba8f 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -405,13 +405,17 @@ class settings { else { snprintf(mCfg.sys.stationSsid, SSID_LEN, FB_WIFI_SSID); snprintf(mCfg.sys.stationPwd, PWD_LEN, FB_WIFI_PWD); - snprintf(mCfg.sys.apPwd, PWD_LEN, WIFI_AP_PWD); mCfg.sys.isHidden = false; } #endif + snprintf(mCfg.sys.apPwd, PWD_LEN, WIFI_AP_PWD); #if defined(ETHERNET) - mCfg.sys.eth.enabled = false; + #if defined(DEF_ETH_ENABLED) + mCfg.sys.eth.enabled = true; + #else + mCfg.sys.eth.enabled = false; + #endif mCfg.sys.eth.pinCs = DEF_ETH_CS_PIN; mCfg.sys.eth.pinSclk = DEF_ETH_SCK_PIN; mCfg.sys.eth.pinMiso = DEF_ETH_MISO_PIN; @@ -431,7 +435,11 @@ class settings { mCfg.nrf.pinMosi = DEF_NRF_MOSI_PIN; mCfg.nrf.pinSclk = DEF_NRF_SCLK_PIN; + #if defined(ETHERNET) + mCfg.nrf.enabled = false; + #else mCfg.nrf.enabled = true; + #endif #if defined(ESP32) mCfg.cmt.pinSclk = DEF_CMT_SCLK; diff --git a/src/network/AhoyEthernet.h b/src/network/AhoyEthernet.h index ce176ec3..db624a41 100644 --- a/src/network/AhoyEthernet.h +++ b/src/network/AhoyEthernet.h @@ -18,12 +18,16 @@ class AhoyEthernet : public AhoyNetwork { void begin() override { mAp.enable(); + if(!mConfig->sys.eth.enabled) + return; + + mEthSpi.begin(mConfig->sys.eth.pinMiso, mConfig->sys.eth.pinMosi, mConfig->sys.eth.pinSclk, mConfig->sys.eth.pinCs, mConfig->sys.eth.pinIrq, mConfig->sys.eth.pinRst); + ETH.setHostname(mConfig->sys.deviceName); + // static IP setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool { return ETH.config(ip, gateway, mask, dns1, dns2); }); - - ETH.setHostname(mConfig->sys.deviceName); } void tickNetworkLoop() override { @@ -43,9 +47,8 @@ class AhoyEthernet : public AhoyNetwork { break; case NetworkState::GOT_IP: - mAp.disable(); - if(!mConnected) { + mAp.disable(); mConnected = true; ah::welcome(ETH.localIP().toString(), F("Station")); MDNS.begin(mConfig->sys.deviceName); @@ -59,10 +62,8 @@ class AhoyEthernet : public AhoyNetwork { return ETH.localIP().toString(); } - void scanAvailNetworks(void) override {}; - bool getAvailNetworks(JsonObject obj) override { - return false; - } + private: + AhoyEthernetSpi mEthSpi; }; #endif /*ETHERNET*/ diff --git a/src/network/AhoyEthernetSpi.h b/src/network/AhoyEthernetSpi.h index 12e58e4d..b41431b4 100644 --- a/src/network/AhoyEthernetSpi.h +++ b/src/network/AhoyEthernetSpi.h @@ -26,9 +26,11 @@ class AhoyEthernetSpi { eth_netif(nullptr) {} void begin(int8_t pin_miso, int8_t pin_mosi, int8_t pin_sclk, int8_t pin_cs, int8_t pin_int, int8_t pin_rst) { - gpio_reset_pin(static_cast(pin_rst)); - gpio_set_direction(static_cast(pin_rst), GPIO_MODE_OUTPUT); - gpio_set_level(static_cast(pin_rst), 0); + if(-1 != pin_rst) { + gpio_reset_pin(static_cast(pin_rst)); + gpio_set_direction(static_cast(pin_rst), GPIO_MODE_OUTPUT); + gpio_set_level(static_cast(pin_rst), 0); + } gpio_reset_pin(static_cast(pin_sclk)); gpio_reset_pin(static_cast(pin_mosi)); @@ -42,6 +44,7 @@ class AhoyEthernetSpi { gpio_reset_pin(static_cast(pin_int)); gpio_set_pull_mode(static_cast(pin_int), GPIO_PULLUP_ONLY); + spi_bus_config_t buscfg = { .mosi_io_num = pin_mosi, .miso_io_num = pin_miso, @@ -80,9 +83,11 @@ class AhoyEthernetSpi { ESP_ERROR_CHECK(spi_bus_add_device(SPI3_HOST, &devcfg, &spi)); // Reset sequence - delayMicroseconds(500); - gpio_set_level(static_cast(pin_rst), 1); - delayMicroseconds(1000); + if(-1 != pin_rst) { + delayMicroseconds(500); + gpio_set_level(static_cast(pin_rst), 1); + delayMicroseconds(1000); + } // Arduino function to start networking stack if not already started tcpipInit(); diff --git a/src/network/AhoyNetwork.h b/src/network/AhoyNetwork.h index 59e000bd..5ce668df 100644 --- a/src/network/AhoyNetwork.h +++ b/src/network/AhoyNetwork.h @@ -80,8 +80,39 @@ class AhoyNetwork { virtual void begin() = 0; virtual void tickNetworkLoop() = 0; virtual String getIp(void) = 0; - virtual void scanAvailNetworks(void) = 0; - virtual bool getAvailNetworks(JsonObject obj) = 0; + + virtual bool getWasInCh12to14() { + return false; + } + + #if !defined(ETHERNET) + void scanAvailNetworks(void) { + if(!mScanActive) { + mScanActive = true; + WiFi.scanNetworks(true); + } + } + + bool getAvailNetworks(JsonObject obj) { + JsonArray nets = obj.createNestedArray(F("networks")); + + int n = WiFi.scanComplete(); + if (n < 0) + return false; + if(n > 0) { + int sort[n]; + sortRSSI(&sort[0], n); + for (int i = 0; i < n; ++i) { + nets[i][F("ssid")] = WiFi.SSID(sort[i]); + nets[i][F("rssi")] = WiFi.RSSI(sort[i]); + } + } + mScanActive = false; + WiFi.scanDelete(); + + return true; + } + #endif protected: void setupIp(std::function cb) { @@ -169,6 +200,17 @@ class AhoyNetwork { mUdp.close(); } + #if !defined(ETHERNET) + void sortRSSI(int *sort, int n) { + for (int i = 0; i < n; i++) + sort[i] = i; + for (int i = 0; i < n; i++) + for (int j = i + 1; j < n; j++) + if (WiFi.RSSI(sort[j]) > WiFi.RSSI(sort[i])) + std::swap(sort[i], sort[j]); + } + #endif + protected: enum class NetworkState : uint8_t { DISCONNECTED, @@ -182,6 +224,7 @@ class AhoyNetwork { settings_t *mConfig = nullptr; uint32_t *mUtcTimestamp = nullptr; bool mConnected = false; + bool mScanActive = false; OnNetworkCB mOnNetworkCB; OnTimeCB mOnTimeCB; diff --git a/src/network/AhoyNetworkHelper.h b/src/network/AhoyNetworkHelper.h index 33f71029..378ba033 100644 --- a/src/network/AhoyNetworkHelper.h +++ b/src/network/AhoyNetworkHelper.h @@ -9,7 +9,7 @@ #include "../utils/dbg.h" #include #if defined(ESP32) - #include + #include "ESPAsyncWebServer.h" #include #include #else diff --git a/src/network/AhoyWifiEsp32.h b/src/network/AhoyWifiEsp32.h index 99733ad2..255f2b03 100644 --- a/src/network/AhoyWifiEsp32.h +++ b/src/network/AhoyWifiEsp32.h @@ -9,8 +9,8 @@ #if defined(ESP32) && !defined(ETHERNET) #include #include -#include #include "AhoyNetwork.h" +#include "ESPAsyncWebServer.h" class AhoyWifi : public AhoyNetwork { public: @@ -69,33 +69,6 @@ class AhoyWifi : public AhoyNetwork { return WiFi.localIP().toString(); } - void scanAvailNetworks(void) override { - if(!mScanActive) { - mScanActive = true; - WiFi.scanNetworks(true); - } - } - - bool getAvailNetworks(JsonObject obj) override { - JsonArray nets = obj.createNestedArray(F("networks")); - - int n = WiFi.scanComplete(); - if (n < 0) - return false; - if(n > 0) { - int sort[n]; - sortRSSI(&sort[0], n); - for (int i = 0; i < n; ++i) { - nets[i][F("ssid")] = WiFi.SSID(sort[i]); - nets[i][F("rssi")] = WiFi.RSSI(sort[i]); - } - } - mScanActive = false; - WiFi.scanDelete(); - - return true; - } - private: void sortRSSI(int *sort, int n) { for (int i = 0; i < n; i++) @@ -105,9 +78,6 @@ class AhoyWifi : public AhoyNetwork { if (WiFi.RSSI(sort[j]) > WiFi.RSSI(sort[i])) std::swap(sort[i], sort[j]); } - - private: - bool mScanActive = false; }; #endif /*ESP32 & !ETHERNET*/ diff --git a/src/network/AhoyWifiEsp8266.h b/src/network/AhoyWifiEsp8266.h index 2db24c21..b9417556 100644 --- a/src/network/AhoyWifiEsp8266.h +++ b/src/network/AhoyWifiEsp8266.h @@ -74,7 +74,6 @@ class AhoyWifi : public AhoyNetwork { DBGPRINT(" " + String(bssid[j], HEX)); } DBGPRINTLN(""); - mGotDisconnect = false; WiFi.begin(mConfig->sys.stationSsid, mConfig->sys.stationPwd, 0, &bssid[0]); break; @@ -96,6 +95,9 @@ class AhoyWifi : public AhoyNetwork { MDNS.begin(mConfig->sys.deviceName); mOnNetworkCB(true); } + + if(WiFi.channel() > 11) + mWasInCh12to14 = true; break; } } @@ -104,43 +106,11 @@ class AhoyWifi : public AhoyNetwork { return WiFi.localIP().toString(); } - void scanAvailNetworks(void) override { - if(!mScanActive) { - mScanActive = true; - WiFi.scanNetworks(true); - } - } - - bool getAvailNetworks(JsonObject obj) override { - JsonArray nets = obj.createNestedArray(F("networks")); - - int n = WiFi.scanComplete(); - if (n < 0) - return false; - if(n > 0) { - int sort[n]; - sortRSSI(&sort[0], n); - for (int i = 0; i < n; ++i) { - nets[i][F("ssid")] = WiFi.SSID(sort[i]); - nets[i][F("rssi")] = WiFi.RSSI(sort[i]); - } - } - mScanActive = false; - WiFi.scanDelete(); - - return true; + bool getWasInCh12to14() override { + return mWasInCh12to14; } private: - void sortRSSI(int *sort, int n) { - for (int i = 0; i < n; i++) - sort[i] = i; - for (int i = 0; i < n; i++) - for (int j = i + 1; j < n; j++) - if (WiFi.RSSI(sort[j]) > WiFi.RSSI(sort[i])) - std::swap(sort[i], sort[j]); - } - bool getBSSIDs() { bool result = false; int n = WiFi.scanComplete(); @@ -175,9 +145,8 @@ class AhoyWifi : public AhoyNetwork { private: uint8_t mCnt = 0; uint8_t mScanCnt = 0; - bool mScanActive = false; - bool mGotDisconnect = false; std::list mBSSIDList; + bool mWasInCh12to14 = false; static constexpr uint8_t TIMEOUT = 20; static constexpr uint8_t SCAN_TIMEOUT = 10; }; diff --git a/src/platformio.ini b/src/platformio.ini index de9028d0..4d0d528d 100644 --- a/src/platformio.ini +++ b/src/platformio.ini @@ -41,6 +41,16 @@ build_unflags = -std=gnu++11 +[env:esp8266-minimal] +platform = espressif8266 +board = esp12e +board_build.f_cpu = 80000000L +build_flags = ${env.build_flags} + -DEMC_MIN_FREE_MEMORY=4096 + ;-Wl,-Map,output.map +monitor_filters = + esp8266_exception_decoder + [env:esp8266] platform = espressif8266 board = esp12e @@ -48,10 +58,8 @@ board_build.f_cpu = 80000000L lib_deps = ${env.lib_deps} https://github.com/me-no-dev/ESPAsyncUDP -build_flags = ${env.build_flags} - -DEMC_MIN_FREE_MEMORY=4096 +build_flags = ${env:esp8266-minimal.build_flags} -DENABLE_MQTT - ;-Wl,-Map,output.map monitor_filters = esp8266_exception_decoder @@ -59,11 +67,8 @@ monitor_filters = platform = espressif8266 board = esp12e board_build.f_cpu = 80000000L -build_flags = ${env.build_flags} - -DEMC_MIN_FREE_MEMORY=4096 +build_flags = ${env:esp8266.build_flags} -DLANG_DE - -DENABLE_MQTT - ;-Wl,-Map,output.map monitor_filters = esp8266_exception_decoder @@ -71,12 +76,9 @@ monitor_filters = platform = espressif8266 board = esp12e board_build.f_cpu = 80000000L -build_flags = ${env.build_flags} - -DEMC_MIN_FREE_MEMORY=4096 - -DENABLE_MQTT +build_flags = ${env:esp8266.build_flags} -DPLUGIN_DISPLAY -DENABLE_HISTORY - ;-Wl,-Map,output.map monitor_filters = esp8266_exception_decoder @@ -84,13 +86,8 @@ monitor_filters = platform = espressif8266 board = esp12e board_build.f_cpu = 80000000L -build_flags = ${env.build_flags} - -DEMC_MIN_FREE_MEMORY=4096 +build_flags = ${env:esp8266-all.build_flags} -DLANG_DE - -DENABLE_MQTT - -DPLUGIN_DISPLAY - -DENABLE_HISTORY - ;-Wl,-Map,output.map monitor_filters = esp8266_exception_decoder @@ -98,12 +95,8 @@ monitor_filters = platform = espressif8266 board = esp12e board_build.f_cpu = 80000000L -build_flags = ${env.build_flags} - -DEMC_MIN_FREE_MEMORY=4096 +build_flags = ${env:esp8266-all.build_flags} -DENABLE_PROMETHEUS_EP - -DENABLE_MQTT - -DPLUGIN_DISPLAY - -DENABLE_HISTORY monitor_filters = esp8266_exception_decoder @@ -111,23 +104,8 @@ monitor_filters = platform = espressif8266 board = esp12e board_build.f_cpu = 80000000L -build_flags = ${env.build_flags} - -DEMC_MIN_FREE_MEMORY=4096 - -DENABLE_PROMETHEUS_EP +build_flags = ${env:esp8266-prometheus.build_flags} -DLANG_DE - -DENABLE_MQTT - -DPLUGIN_DISPLAY - -DENABLE_HISTORY -monitor_filters = - esp8266_exception_decoder - -[env:esp8266-minimal] -platform = espressif8266 -board = esp12e -board_build.f_cpu = 80000000L -build_flags = ${env.build_flags} - -DEMC_MIN_FREE_MEMORY=4096 - ;-Wl,-Map,output.map monitor_filters = esp8266_exception_decoder @@ -350,6 +328,7 @@ build_flags = ${env:opendtufusion-minimal.build_flags} -DDEF_ETH_MOSI_PIN=40 -DDEF_ETH_IRQ_PIN=44 -DDEF_ETH_RST_PIN=43 + -DDEF_ETH_ENABLED monitor_filters = esp32_exception_decoder, colorize diff --git a/src/web/RestApi.h b/src/web/RestApi.h index f4c655b5..8087883e 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -375,14 +375,12 @@ class RestApi { } void getSysInfo(AsyncWebServerRequest *request, JsonObject obj) { + obj[F("ap_pwd")] = mConfig->sys.apPwd; #if !defined(ETHERNET) obj[F("ssid")] = mConfig->sys.stationSsid; - obj[F("ap_pwd")] = mConfig->sys.apPwd; obj[F("hidd")] = mConfig->sys.isHidden; obj[F("mac")] = WiFi.macAddress(); obj[F("wifi_channel")] = WiFi.channel(); - #else - getEthernet(obj.createNestedObject(F("eth"))); #endif /* !defined(ETHERNET) */ obj[F("device_name")] = mConfig->sys.deviceName; obj[F("dark_mode")] = (bool)mConfig->sys.darkMode; @@ -882,6 +880,9 @@ class RestApi { #if defined(ESP32) getRadioCmt(obj.createNestedObject(F("radioCmt"))); #endif + #if defined(ETHERNET) + getEthernet(obj.createNestedObject(F("eth"))); + #endif getRadioNrf(obj.createNestedObject(F("radioNrf"))); getSerial(obj.createNestedObject(F("serial"))); getStaticIp(obj.createNestedObject(F("static_ip"))); @@ -1051,6 +1052,17 @@ class RestApi { //mApp->setStopApAllowedMode(false); mApp->setupStation(); } + #else + else if(F("save_eth") == jsonIn[F("cmd")]) { + mConfig->sys.eth.enabled = jsonIn[F("en")].as(); + mConfig->sys.eth.pinCs = jsonIn[F("cs")].as(); + mConfig->sys.eth.pinSclk = jsonIn[F("sclk")].as(); + mConfig->sys.eth.pinMiso = jsonIn[F("miso")].as(); + mConfig->sys.eth.pinMosi = jsonIn[F("mosi")].as(); + mConfig->sys.eth.pinIrq = jsonIn[F("irq")].as(); + mConfig->sys.eth.pinRst = jsonIn[F("reset")].as(); + mApp->saveSettings(true); + } #endif /* !defined(ETHERNET */ else if(F("save_iv") == jsonIn[F("cmd")]) { Inverter<> *iv = mSys->getInverterByPos(jsonIn[F("id")], false); diff --git a/src/web/html/setup.html b/src/web/html/setup.html index 9af66314..fb1eff97 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -949,7 +949,7 @@ } } - function parsePinout(obj, type, system) { + function parsePinout(obj) { var e = document.getElementById("pinout"); /*IF_ESP32*/ var pinList = esp32pins; @@ -1291,13 +1291,13 @@ parseMqtt(root["mqtt"]); parseNtp(root["ntp"]); parseSun(root["sun"]); - parsePinout(root["pinout"], root["system"]["esp_type"], root["system"]); + parsePinout(root.pinout); parseNrfRadio(root["radioNrf"], root["pinout"]); /*IF_ESP32*/ - parseCmtRadio(root["radioCmt"]); + parseCmtRadio(root.radioCmt); /*ENDIF_ESP32*/ /*IF_ETHERNET*/ - parseEth(root.system.eth) + parseEth(root.eth) /*ENDIF_ETHERNET*/ parseSerial(root["serial"]); /*IF_PLUGIN_DISPLAY*/ diff --git a/src/web/html/wizard.html b/src/web/html/wizard.html index 3df44dc4..179adb5a 100644 --- a/src/web/html/wizard.html +++ b/src/web/html/wizard.html @@ -15,6 +15,165 @@ var found = false; var c = document.getElementById("con"); + /*IF_ESP32*/ + var pinList = [ + [255, "{#PIN_OFF}"], + [0, "GPIO0"], + [1, "TX (GPIO1)"], + [2, "GPIO2 (LED)"], + [3, "RX (GPIO3)"], + [4, "GPIO4"], + [5, "GPIO5"], + [12, "GPIO12 (HSPI MISO)"], + [13, "GPIO13 (HSPI MOSI)"], + [14, "GPIO14 (HSPI SCLK)"], + [15, "GPIO15"], + [16, "GPIO16"], + [17, "GPIO17"], + [18, "GPIO18 (VSPI SCLK)"], + [19, "GPIO19 (VSPI MISO)"], + [21, "GPIO21 (SDA)"], + [22, "GPIO22 (SCL)"], + [23, "GPIO23 (VSPI MOSI)"], + [25, "GPIO25"], + [26, "GPIO26"], + [27, "GPIO27"], + [32, "GPIO32"], + [33, "GPIO33"], + [34, "GPIO34 ({#PIN_INPUT_ONLY})"], + [35, "GPIO35 ({#PIN_INPUT_ONLY})"], + [36, "VP (GPIO36, {#PIN_INPUT_ONLY})"], + [39, "VN (GPIO39, {#PIN_INPUT_ONLY})"] + ]; + /*IF_ESP32-S2*/ + pinList = [ + [255, "off / default"], + [0, "GPIO0 ({#PIN_DONT_USE} - BOOT)"], + [1, "GPIO1"], + [2, "GPIO2"], + [3, "GPIO3"], + [4, "GPIO4"], + [5, "GPIO5"], + [6, "GPIO6"], + [7, "GPIO7"], + [8, "GPIO8"], + [9, "GPIO9"], + [10, "GPIO10"], + [11, "GPIO11"], + [12, "GPIO12"], + [13, "GPIO13"], + [14, "GPIO14"], + [15, "GPIO15"], + [16, "GPIO16"], + [17, "GPIO17"], + [18, "GPIO18"], + [19, "GPIO19 ({#PIN_DONT_USE} - USB-)"], + [20, "GPIO20 ({#PIN_DONT_USE} - USB+)"], + [21, "GPIO21"], + [26, "GPIO26 (PSRAM - {#PIN_NOT_AVAIL})"], + [27, "GPIO27 (FLASH - {#PIN_NOT_AVAIL})"], + [28, "GPIO28 (FLASH - {#PIN_NOT_AVAIL})"], + [29, "GPIO29 (FLASH - {#PIN_NOT_AVAIL})"], + [30, "GPIO30 (FLASH - {#PIN_NOT_AVAIL})"], + [31, "GPIO31 (FLASH - {#PIN_NOT_AVAIL})"], + [32, "GPIO32 (FLASH - {#PIN_NOT_AVAIL})"], + [33, "GPIO33 (not exposed on S3-WROOM modules)"], + [34, "GPIO34 (not exposed on S3-WROOM modules)"], + [35, "GPIO35"], + [36, "GPIO36"], + [37, "GPIO37"], + [38, "GPIO38"], + [39, "GPIO39"], + [40, "GPIO40"], + [41, "GPIO41"], + [42, "GPIO42"], + [43, "GPIO43"], + [44, "GPIO44"], + [45, "GPIO45 ({#PIN_DONT_USE} - STRAPPING PIN)"], + [46, "GPIO46 ({#PIN_DONT_USE} - STRAPPING PIN)"], + [47, "GPIO47"], + [48, "GPIO48"], + ]; + /*ENDIF_ESP32-S2*/ + /*IF_ESP32-S3*/ + pinList = [ + [255, "off / default"], + [0, "GPIO0 ({#PIN_DONT_USE} - BOOT)"], + [1, "GPIO1"], + [2, "GPIO2"], + [3, "GPIO3"], + [4, "GPIO4"], + [5, "GPIO5"], + [6, "GPIO6"], + [7, "GPIO7"], + [8, "GPIO8"], + [9, "GPIO9"], + [10, "GPIO10"], + [11, "GPIO11"], + [12, "GPIO12"], + [13, "GPIO13"], + [14, "GPIO14"], + [15, "GPIO15"], + [16, "GPIO16"], + [17, "GPIO17"], + [18, "GPIO18"], + [19, "GPIO19 ({#PIN_DONT_USE} - USB-)"], + [20, "GPIO20 ({#PIN_DONT_USE} - USB+)"], + [21, "GPIO21"], + [26, "GPIO26 (PSRAM - {#PIN_NOT_AVAIL})"], + [27, "GPIO27 (FLASH - {#PIN_NOT_AVAIL})"], + [28, "GPIO28 (FLASH - {#PIN_NOT_AVAIL})"], + [29, "GPIO29 (FLASH - {#PIN_NOT_AVAIL})"], + [30, "GPIO30 (FLASH - {#PIN_NOT_AVAIL})"], + [31, "GPIO31 (FLASH - {#PIN_NOT_AVAIL})"], + [32, "GPIO32 (FLASH - {#PIN_NOT_AVAIL})"], + [33, "GPIO33 (not exposed on S3-WROOM modules)"], + [34, "GPIO34 (not exposed on S3-WROOM modules)"], + [35, "GPIO35"], + [36, "GPIO36"], + [37, "GPIO37"], + [38, "GPIO38"], + [39, "GPIO39"], + [40, "GPIO40"], + [41, "GPIO41"], + [42, "GPIO42"], + [43, "GPIO43"], + [44, "GPIO44"], + [45, "GPIO45 ({#PIN_DONT_USE} - STRAPPING PIN)"], + [46, "GPIO46 ({#PIN_DONT_USE} - STRAPPING PIN)"], + [47, "GPIO47"], + [48, "GPIO48"], + ]; + /*ENDIF_ESP32-S3*/ + /*IF_ESP32-C3*/ + pinList = [ + [255, "off / default"], + [0, "GPIO0"], + [1, "GPIO1"], + [2, "GPIO2"], + [3, "GPIO3"], + [4, "GPIO4"], + [5, "GPIO5"], + [6, "GPIO6"], + [7, "GPIO7"], + [8, "GPIO8"], + [9, "GPIO9"], + [10, "GPIO10"], + [11, "GPIO11"], + [12, "GPIO12 (PSRAM/FLASH)"], + [13, "GPIO13 (PSRAM/FLASH)"], + [14, "GPIO14 (PSRAM/FLASH)"], + [15, "GPIO15 (PSRAM/FLASH)"], + [16, "GPIO16 (PSRAM/FLASH)"], + [17, "GPIO17 (PSRAM/FLASH)"], + [18, "GPIO18 ({#PIN_DONT_USE} - USB-)"], + [19, "GPIO19 ({#PIN_DONT_USE} - USB+)"], + [20, "GPIO20 (RX)"], + [21, "GPIO21 (TX)"], + ]; + /*ENDIF_ESP32-C3*/ + /*ENDIF_ESP32*/ + function sect(e1, e2) { return ml("div", {class: "row"}, [ ml("div", {class: "col-12"}, ml("p", {}, e1)), @@ -22,7 +181,36 @@ ]) } - function wifi() { + /*IF_ETHERNET*/ + var pins = ['cs', 'sclk', 'miso', 'mosi', 'irq', 'reset'] + function step1(obj) { + console.log(obj) + lst = [] + for(p of pins) { + lst.push( + ml("div", {class: "row mb-3"}, [ + ml("div", {class: "col-12 col-sm-3 my-2"}, p.toUpperCase()), + ml("div", {class: "col-12 col-sm-9"}, + sel(p, pinList, obj[p]) + ) + ]) + ) + } + let en = inp("en", null, null, ["cb"], "en", "checkbox"); + en.checked = obj["en"]; + + return sect("{#NETWORK_SETUP}", [ + ml("div", {class: "row mb-3"}, [ + ml("div", {class: "col-8"}, "{#ETH_ENABLE}"), + ml("div", {class: "col-4"}, en) + ]), + ...lst, + ml("div", {class: "row my-4"}, ml("div", {class: "col a-r"}, ml("input", {type: "button", class:"btn", value: "{#BTN_REBOOT}", onclick: () => {saveEth()}}, null))), + ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {href: "http://192.168.4.1/"}, "{#STOP_WIZARD}"))) + ]) + } + /*ELSE*/ + function step1() { return ml("div", {}, [ ml("div", {class: "row my-5"}, ml("div", {class: "col"}, ml("span", {class: "fs-1"}, "{#WELCOME}"))), ml("div", {class: "row"}, ml("div", {class: "col"}, ml("span", {class: "fs-5"}, "{#NETWORK_SETUP}"))), @@ -33,6 +221,7 @@ ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {href: "http://192.168.4.1/"}, "{#STOP_WIZARD}"))) ]) } + /*ENDIF_ETHERNET*/ function checkWifi() { c.replaceChildren( @@ -57,13 +246,29 @@ } } + /*IF_ETHERNET*/ + function saveEth() { + let o = { + cmd: "save_eth", + en: document.getElementsByName("en")[0].checked + } + for(p of pins) { + o[p] = document.getElementsByName(p)[0].value + } + getAjax("/api/setup", ((o) => {}), "POST", JSON.stringify(o)); + } + /*ELSE*/ function saveWifi() { var ssid = document.getElementById("net").value; if(-1 == ssid) ssid = document.getElementById("man").value; getAjax("/api/setup", ((o) => {if(!o.error) checkWifi()}), "POST", JSON.stringify({cmd: "save_wifi", ssid: ssid, pwd: document.getElementById("pwd").value})); } + /*ENDIF_ETHERNET*/ + /*IF_ETHERNET*/ + getAjax("/api/setup", ((o) => c.append(step1(o.eth)))); + /*ELSE*/ function nets(obj) { var e = document.getElementById("net"); if(obj.networks.length > 0) { @@ -79,9 +284,10 @@ } getAjax("/api/setup", ((o) => {}), "POST", JSON.stringify({cmd: "scan_wifi"})); - c.append(wifi()) - + c.append(step1()) v = setInterval(() => {getAjax('/api/setup/networks', nets)}, 2500); + /*ENDIF_ETHERNET*/ + diff --git a/src/web/lang.json b/src/web/lang.json index 22449f30..f2274b69 100644 --- a/src/web/lang.json +++ b/src/web/lang.json @@ -83,6 +83,11 @@ "en": "next >>", "de": "prüfen >>" }, + { + "token": "BTN_REBOOT", + "en": "reboot >>", + "de": "Ahoy neustarten >>" + }, { "token": "TEST_CONNECTION", "en": "Test Connection", @@ -112,6 +117,36 @@ "token": "NUM_NETWORKS_FOUND", "en": "Network(s) found", "de": "Netzwerk(e) gefunden" + }, + { + "token": "PIN_OFF", + "en": "off / default", + "de": "aus / Standard" + }, + { + "token": "PIN_NO_IRQ", + "en": "no IRQ!", + "de": "kein Interrupt!" + }, + { + "token": "PIN_INPUT_ONLY", + "en": "in only", + "de": "nur Eingang" + }, + { + "token": "PIN_DONT_USE", + "en": "DONT USE", + "de": "nicht benutzen" + }, + { + "token": "PIN_NOT_AVAIL", + "en": "not available", + "de": "nicht verfügbar" + }, + { + "token": "ETH_ENABLE", + "en": "Ethernet enable", + "de": "Ethernet aktivieren" } ] }, diff --git a/src/web/web.h b/src/web/web.h index f4389163..419d6826 100644 --- a/src/web/web.h +++ b/src/web/web.h @@ -447,10 +447,10 @@ class Web { request->arg("ssid").toCharArray(mConfig->sys.stationSsid, SSID_LEN); if (request->arg("pwd") != "{PWD}") request->arg("pwd").toCharArray(mConfig->sys.stationPwd, PWD_LEN); - if (request->arg("ap_pwd") != "") - request->arg("ap_pwd").toCharArray(mConfig->sys.apPwd, PWD_LEN); mConfig->sys.isHidden = (request->arg("hidd") == "on"); #endif /* !defined(ETHERNET) */ + if (request->arg("ap_pwd") != "") + request->arg("ap_pwd").toCharArray(mConfig->sys.apPwd, PWD_LEN); if (request->arg("device") != "") request->arg("device").toCharArray(mConfig->sys.deviceName, DEVNAME_LEN); mConfig->sys.darkMode = (request->arg("darkMode") == "on");