Compare commits

...
12 Commits
Author SHA1 Message Date
Yurii e712f1803a fix: fit BLE and Ethernet in classic ESP32 OTA slots 2026-12-04 16:12:42 +03:00
Yurii 54caf4fd7f feat: add LAN8720 support and extend ESP32 Ethernet profiles 2026-12-04 15:12:16 +03:00
Yurii cea8231015 revert: restore the default branch for Dependabot version updates
This reverts commit a7b2120740.
2026-12-03 09:44:07 +03:00
dependabot[bot] 998ac5221d chore: bump actions/setup-node from 5 to 6 (#306)
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 5 to 6.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-12-03 09:39:14 +03:00
dependabot[bot] 887d7ebb9a chore: bump actions/checkout from 6 to 7 (#305)
Bumps [actions/checkout](https://github.com/actions/checkout) from 6 to 7.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-12-03 09:38:57 +03:00
dependabot[bot] e42286dd70 chore: bump actions/download-artifact from 5 to 8 (#304)
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 5 to 8.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v5...v8)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: '8'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-12-03 09:38:39 +03:00
dependabot[bot] fd5a1d7be6 chore: bump actions/setup-python from 6 to 7 (#303)
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 6 to 7.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-12-03 09:38:22 +03:00
dependabot[bot] d03aae959e chore: bump actions/cache from 5 to 6 (#302)
Bumps [actions/cache](https://github.com/actions/cache) from 5 to 6.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](https://github.com/actions/cache/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-12-03 09:38:05 +03:00
Yurii a7b2120740 ci: target dev for Dependabot version updates 2026-12-03 09:37:09 +03:00
Yurii 230b223e7f build: split elvinhome THRM ONE into BLE and Ethernet environments 2026-12-03 09:32:19 +03:00
Yurii 6d8a28e82c feat: rework the network settings page 2026-12-03 09:25:37 +03:00
Yurii 29a5bc0f43 fix: make W5500 interrupt and reset pins optional 2026-12-03 09:25:27 +03:00
20 changed files with 902 additions and 559 deletions

No files matched your search

+7 -7
View File
@@ -40,13 +40,13 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v6 uses: actions/checkout@v7
with: with:
# A new tag needs branch history to determine whether its commit is on master. # A new tag needs branch history to determine whether its commit is on master.
fetch-depth: ${{ startsWith(github.ref, 'refs/tags/v') && github.event.created && '0' || '1' }} fetch-depth: ${{ startsWith(github.ref, 'refs/tags/v') && github.event.created && '0' || '1' }}
- name: Python - name: Python
uses: actions/setup-python@v6 uses: actions/setup-python@v7
with: with:
python-version: ${{ env.PYTHON_VERSION }} python-version: ${{ env.PYTHON_VERSION }}
@@ -98,15 +98,15 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v6 uses: actions/checkout@v7
- name: Python - name: Python
uses: actions/setup-python@v6 uses: actions/setup-python@v7
with: with:
python-version: ${{ env.PYTHON_VERSION }} python-version: ${{ env.PYTHON_VERSION }}
- name: Install Node.js - name: Install Node.js
uses: actions/setup-node@v5 uses: actions/setup-node@v6
with: with:
node-version: "22" node-version: "22"
@@ -178,7 +178,7 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v6 uses: actions/checkout@v7
with: with:
fetch-depth: 0 fetch-depth: 0
@@ -190,7 +190,7 @@ jobs:
git push origin refs/tags/unstable --force git push origin refs/tags/unstable --force
- name: Download artifacts - name: Download artifacts
uses: actions/download-artifact@v5 uses: actions/download-artifact@v8
with: with:
path: artifacts path: artifacts
merge-multiple: true merge-multiple: true
+4 -4
View File
@@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v6 uses: actions/checkout@v7
- name: Install jq - name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq run: sudo apt-get update && sudo apt-get install -y jq
@@ -67,16 +67,16 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v6 uses: actions/checkout@v7
- name: Cache - name: Cache
uses: actions/cache@v5 uses: actions/cache@v6
with: with:
key: ${{ runner.os }}-cpplint key: ${{ runner.os }}-cpplint
path: ~/.cache/pip path: ~/.cache/pip
- name: Python - name: Python
uses: actions/setup-python@v6 uses: actions/setup-python@v7
with: with:
python-version: "3.x" python-version: "3.x"
+9 -1
View File
@@ -32,7 +32,7 @@ struct NetworkSettings {
} wifi; } wifi;
struct { struct {
EthernetType type = EthernetType::W5500; EthernetType type = DEFAULT_ETHERNET_TYPE;
struct { struct {
uint8_t clk = DEFAULT_ETH_CLK_GPIO; uint8_t clk = DEFAULT_ETH_CLK_GPIO;
@@ -42,6 +42,14 @@ struct NetworkSettings {
uint8_t irq = DEFAULT_ETH_IRQ_GPIO; uint8_t irq = DEFAULT_ETH_IRQ_GPIO;
uint8_t rst = DEFAULT_ETH_RST_GPIO; uint8_t rst = DEFAULT_ETH_RST_GPIO;
} w5500; } w5500;
struct {
uint8_t mdc = DEFAULT_ETH_MDC_GPIO;
uint8_t mdio = DEFAULT_ETH_MDIO_GPIO;
uint8_t power = DEFAULT_ETH_POWER_GPIO;
uint8_t phyAddr = DEFAULT_ETH_PHY_ADDR;
uint8_t clockMode = 0; // External REF_CLK on GPIO0.
} lan8720;
} ethernet; } ethernet;
NetworkMode type = NetworkMode::STA; NetworkMode type = NetworkMode::STA;
+1 -1
View File
@@ -153,7 +153,7 @@ IPAddress getNetworkSubnet();
IPAddress getNetworkGateway(); IPAddress getNetworkGateway();
IPAddress getNetworkDns(); IPAddress getNetworkDns();
String getNetworkMac(); String getNetworkMac();
bool isEthernetConfigured(const NetworkSettings& config = networkSettings); bool isEthernetConfigValid(const NetworkSettings& config = networkSettings);
bool isNetworkInterfaceStarted(NetworkMode mode); bool isNetworkInterfaceStarted(NetworkMode mode);
// Last state published by the system worker, including during event callbacks. // Last state published by the system worker, including during event callbacks.
bool isNetworkConnected(); bool isNetworkConnected();
+20
View File
@@ -87,6 +87,10 @@
#define DEFAULT_STATUS_LED_GPIO GPIO_IS_NOT_CONFIGURED #define DEFAULT_STATUS_LED_GPIO GPIO_IS_NOT_CONFIGURED
#endif #endif
#ifndef DEFAULT_ETHERNET_TYPE
#define DEFAULT_ETHERNET_TYPE EthernetType::W5500
#endif
#ifndef DEFAULT_ETH_CLK_GPIO #ifndef DEFAULT_ETH_CLK_GPIO
#define DEFAULT_ETH_CLK_GPIO GPIO_IS_NOT_CONFIGURED #define DEFAULT_ETH_CLK_GPIO GPIO_IS_NOT_CONFIGURED
#endif #endif
@@ -111,6 +115,22 @@
#define DEFAULT_ETH_RST_GPIO GPIO_IS_NOT_CONFIGURED #define DEFAULT_ETH_RST_GPIO GPIO_IS_NOT_CONFIGURED
#endif #endif
#ifndef DEFAULT_ETH_MDC_GPIO
#define DEFAULT_ETH_MDC_GPIO GPIO_IS_NOT_CONFIGURED
#endif
#ifndef DEFAULT_ETH_MDIO_GPIO
#define DEFAULT_ETH_MDIO_GPIO GPIO_IS_NOT_CONFIGURED
#endif
#ifndef DEFAULT_ETH_POWER_GPIO
#define DEFAULT_ETH_POWER_GPIO GPIO_IS_NOT_CONFIGURED
#endif
#ifndef DEFAULT_ETH_PHY_ADDR
#define DEFAULT_ETH_PHY_ADDR 1
#endif
#ifndef DEFAULT_PORTAL_LOGIN #ifndef DEFAULT_PORTAL_LOGIN
#define DEFAULT_PORTAL_LOGIN "" #define DEFAULT_PORTAL_LOGIN ""
#endif #endif
+6 -1
View File
@@ -52,9 +52,9 @@ inline const char S_CH2_ALWAYS_ENABLED[] = "ch2_always_enabled
inline const char S_CH2_DISABLING_ACTION[] = "ch2_disabling_action"; inline const char S_CH2_DISABLING_ACTION[] = "ch2_disabling_action";
inline const char S_CHIP[] = "chip"; inline const char S_CHIP[] = "chip";
inline const char S_CLK[] = "clk"; inline const char S_CLK[] = "clk";
inline const char S_CLOCK_MODE[] = "clock_mode";
inline const char S_CODE[] = "code"; inline const char S_CODE[] = "code";
inline const char S_COMMIT[] = "commit"; inline const char S_COMMIT[] = "commit";
inline const char S_CONFIGURED[] = "configured";
inline const char S_CONNECTED[] = "connected"; inline const char S_CONNECTED[] = "connected";
inline const char S_CONNECTION_TYPE[] = "connection_type"; inline const char S_CONNECTION_TYPE[] = "connection_type";
inline const char S_COOLING[] = "cooling"; inline const char S_COOLING[] = "cooling";
@@ -125,6 +125,7 @@ inline const char S_IP[] = "ip";
inline const char S_IRQ[] = "irq"; inline const char S_IRQ[] = "irq";
inline const char S_I_FACTOR[] = "i_factor"; inline const char S_I_FACTOR[] = "i_factor";
inline const char S_I_MULTIPLIER[] = "i_multiplier"; inline const char S_I_MULTIPLIER[] = "i_multiplier";
inline const char S_LAN8720[] = "lan8720";
inline const char S_LOGIN[] = "login"; inline const char S_LOGIN[] = "login";
inline const char S_LOG_LEVEL[] = "loglevel"; inline const char S_LOG_LEVEL[] = "loglevel";
inline const char S_LOW_TEMP[] = "low_temp"; inline const char S_LOW_TEMP[] = "low_temp";
@@ -136,6 +137,8 @@ inline const char S_MAX_MODULATION[] = "max_modulation";
inline const char S_MAX_POWER[] = "max_power"; inline const char S_MAX_POWER[] = "max_power";
inline const char S_MAX_TEMP[] = "max_temp"; inline const char S_MAX_TEMP[] = "max_temp";
inline const char S_MAX_TEMP_SYNC_WITH_TARGET_TEMP[] = "max_temp_sync_with_target_temp"; inline const char S_MAX_TEMP_SYNC_WITH_TARGET_TEMP[] = "max_temp_sync_with_target_temp";
inline const char S_MDC[] = "mdc";
inline const char S_MDIO[] = "mdio";
inline const char S_MDNS[] = "mdns"; inline const char S_MDNS[] = "mdns";
inline const char S_MEMBER_ID[] = "member_id"; inline const char S_MEMBER_ID[] = "member_id";
inline const char S_MIN[] = "min"; inline const char S_MIN[] = "min";
@@ -166,6 +169,7 @@ inline const char S_OUTPUT[] = "output";
inline const char S_OVERHEAT[] = "overheat"; inline const char S_OVERHEAT[] = "overheat";
inline const char S_OVERHEAT_PROTECTION[] = "overheat_protection"; inline const char S_OVERHEAT_PROTECTION[] = "overheat_protection";
inline const char S_PASSWORD[] = "password"; inline const char S_PASSWORD[] = "password";
inline const char S_PHY_ADDR[] = "phy_addr";
inline const char S_PID[] = "pid"; inline const char S_PID[] = "pid";
inline const char S_PORT[] = "port"; inline const char S_PORT[] = "port";
inline const char S_PORTAL[] = "portal"; inline const char S_PORTAL[] = "portal";
@@ -228,5 +232,6 @@ inline const char S_USE_DHCP[] = "use_dhcp";
inline const char S_USER[] = "user"; inline const char S_USER[] = "user";
inline const char S_VALUE[] = "value"; inline const char S_VALUE[] = "value";
inline const char S_VERSION[] = "version"; inline const char S_VERSION[] = "version";
inline const char S_W5500[] = "w5500";
inline const char S_WEBSERIAL[] = "web_serial"; inline const char S_WEBSERIAL[] = "web_serial";
inline const char S_WIFI[] = "wifi"; inline const char S_WIFI[] = "wifi";
+5 -2
View File
@@ -21,10 +21,13 @@ enum class PumpStartReason {
}; };
enum class EthernetType : uint8_t { enum class EthernetType : uint8_t {
NONE = 0, NONE = 0,
W5500 = 1 W5500 = 1,
LAN8720 = 2
}; };
typedef std::function<bool(uint8_t)> GpioValidator;
struct SettingResult { struct SettingResult {
bool changed = false; bool changed = false;
bool accepted = false; bool accepted = false;
+47 -11
View File
@@ -173,6 +173,8 @@ board = lolin_s2_mini
extra_scripts = ${esp32_defaults.extra_scripts} extra_scripts = ${esp32_defaults.extra_scripts}
pre:tools/tinyusb_s2.py pre:tools/tinyusb_s2.py
custom_sdkconfig = ${esp32_defaults.custom_sdkconfig} custom_sdkconfig = ${esp32_defaults.custom_sdkconfig}
CONFIG_ETH_USE_SPI_ETHERNET=y
CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF=y
'# CONFIG_BT_ENABLED is not set' '# CONFIG_BT_ENABLED is not set'
CONFIG_TINYUSB_ENABLED=y CONFIG_TINYUSB_ENABLED=y
CONFIG_TINYUSB_CDC_ENABLED=y CONFIG_TINYUSB_CDC_ENABLED=y
@@ -188,6 +190,7 @@ custom_sdkconfig = ${esp32_defaults.custom_sdkconfig}
'# CONFIG_TINYUSB_VENDOR_ENABLED is not set' '# CONFIG_TINYUSB_VENDOR_ENABLED is not set'
'# CONFIG_TINYUSB_NCM_ENABLED is not set' '# CONFIG_TINYUSB_NCM_ENABLED is not set'
build_flags = ${esp32_defaults.build_flags} build_flags = ${esp32_defaults.build_flags}
-D USE_ETHERNET=1
${this.custom_board_flags} ${this.custom_board_flags}
custom_board_flags = -D DEFAULT_OT_IN_GPIO=33 custom_board_flags = -D DEFAULT_OT_IN_GPIO=33
-D DEFAULT_OT_OUT_GPIO=35 -D DEFAULT_OT_OUT_GPIO=35
@@ -251,15 +254,28 @@ custom_board_flags = -D DEFAULT_OT_IN_GPIO=8
custom_sdkconfig = ${esp32_defaults.custom_sdkconfig} custom_sdkconfig = ${esp32_defaults.custom_sdkconfig}
CONFIG_COMPILER_SAVE_RESTORE_LIBCALLS=y CONFIG_COMPILER_SAVE_RESTORE_LIBCALLS=y
[env:nodemcu_32] [esp32_classic]
custom_title = NodeMCU (ESP32)
extends = esp32_defaults extends = esp32_defaults
board = nodemcu-32s custom_board_flags =
lib_deps = ${esp32_defaults.lib_deps} lib_deps = ${esp32_defaults.lib_deps}
${esp32_defaults.nimble_lib} ${esp32_defaults.nimble_lib}
custom_sdkconfig = ${esp32_defaults.custom_sdkconfig}
CONFIG_ETH_USE_ESP32_EMAC=y
CONFIG_ETH_USE_SPI_ETHERNET=y
CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF=y
; Keep assertion checks and omit their messages to fit BLE and Ethernet in OTA.
'# CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE is not set'
'# CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE is not set'
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y
build_flags = ${esp32_defaults.build_flags} build_flags = ${esp32_defaults.build_flags}
-D USE_ETHERNET=1
-D USE_BLE=1 -D USE_BLE=1
${this.custom_board_flags} ${this.custom_board_flags}
[env:nodemcu_32]
custom_title = NodeMCU (ESP32)
extends = esp32_classic
board = nodemcu-32s
custom_board_flags = -D DEFAULT_OT_IN_GPIO=16 custom_board_flags = -D DEFAULT_OT_IN_GPIO=16
-D DEFAULT_OT_OUT_GPIO=4 -D DEFAULT_OT_OUT_GPIO=4
-D DEFAULT_SENSOR_OUTDOOR_GPIO=15 -D DEFAULT_SENSOR_OUTDOOR_GPIO=15
@@ -272,15 +288,23 @@ custom_title = NodeMCU (ESP32, 160 mhz)
extends = env:nodemcu_32 extends = env:nodemcu_32
board_build.f_cpu = 160000000L ; set frequency to 160MHz board_build.f_cpu = 160000000L ; set frequency to 160MHz
[env:wt32_eth01]
custom_title = WT32-ETH01 (ESP32)
extends = esp32_classic
board = wt32-eth01
custom_board_flags = -D DEFAULT_OT_IN_GPIO=32
-D DEFAULT_OT_OUT_GPIO=33
-D DEFAULT_STATUS_LED_GPIO=15
-D DEFAULT_ETHERNET_TYPE=EthernetType::LAN8720
-D DEFAULT_ETH_MDC_GPIO=ETH_PHY_MDC
-D DEFAULT_ETH_MDIO_GPIO=ETH_PHY_MDIO
-D DEFAULT_ETH_POWER_GPIO=ETH_PHY_POWER
-D DEFAULT_ETH_PHY_ADDR=ETH_PHY_ADDR
[env:d1_mini32] [env:d1_mini32]
custom_title = Wemos D1 mini32 (ESP32) custom_title = Wemos D1 mini32 (ESP32)
extends = esp32_defaults extends = esp32_classic
board = wemos_d1_mini32 board = wemos_d1_mini32
lib_deps = ${esp32_defaults.lib_deps}
${esp32_defaults.nimble_lib}
build_flags = ${esp32_defaults.build_flags}
-D USE_BLE=1
${this.custom_board_flags}
custom_board_flags = -D DEFAULT_OT_IN_GPIO=21 custom_board_flags = -D DEFAULT_OT_IN_GPIO=21
-D DEFAULT_OT_OUT_GPIO=22 -D DEFAULT_OT_OUT_GPIO=22
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12 -D DEFAULT_SENSOR_OUTDOOR_GPIO=12
@@ -345,8 +369,20 @@ custom_sdkconfig = ${env:esp32_c6.custom_sdkconfig}
CONFIG_ETH_USE_SPI_ETHERNET=y CONFIG_ETH_USE_SPI_ETHERNET=y
CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF=y CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF=y
[env:elvinhome_thrm_one] [env:elvinhome_thrm_one_ble]
custom_title = Elvinhome THRM ONE (ESP32 C6, NO BLE) custom_title = elvinhome THRM ONE (ESP32 C6, BLE)
extends = env:esp32_c6
custom_board_flags = -D DEFAULT_OT_IN_GPIO=6
-D DEFAULT_OT_OUT_GPIO=7
-D DEFAULT_STATUS_LED_GPIO=1
-D DEFAULT_SENSOR_INDOOR_GPIO=4
-D DEFAULT_SENSOR_INDOOR_TYPE=Sensors::Type::NTC_10K_TEMP
-D DEFAULT_OT_RX_LED_GPIO=GPIO_IS_NOT_CONFIGURED
-D DEFAULT_SENSOR_OUTDOOR_GPIO=GPIO_IS_NOT_CONFIGURED
-D DEFAULT_NTC_VREF=3200.0f
[env:elvinhome_thrm_one_ethernet]
custom_title = elvinhome THRM ONE (ESP32 C6, ETHERNET)
extends = env:esp32_c6_ethernet extends = env:esp32_c6_ethernet
custom_board_flags = -D DEFAULT_ETH_CLK_GPIO=22 custom_board_flags = -D DEFAULT_ETH_CLK_GPIO=22
-D DEFAULT_ETH_MOSI_GPIO=20 -D DEFAULT_ETH_MOSI_GPIO=20
+117 -37
View File
@@ -2,6 +2,9 @@
#include <app.h> #include <app.h>
#if USE_ETHERNET
#include <ETH.h>
#endif
#include <FileData.h> #include <FileData.h>
#include <LittleFS.h> #include <LittleFS.h>
#include <cmath> #include <cmath>
@@ -292,6 +295,37 @@ static bool isSettingInteger(float value, float minValue, float maxValue) {
return std::isfinite(value) && value >= minValue && value <= maxValue && std::trunc(value) == value; return std::isfinite(value) && value >= minValue && value <= maxValue && std::trunc(value) == value;
} }
static const GpioValidator isValidOutputGpio = [](uint8_t gpio) {
return GPIO_IS_VALID_OUTPUT(gpio);
};
static const GpioValidator isValidInputGpio = [](uint8_t gpio) {
return GPIO_IS_VALID_INPUT(gpio);
};
static void parseJsonGpio(JsonVariantConst gpio, uint8_t& target, SettingResult& result,
const GpioValidator& isValid = nullptr) {
if (gpio.is<JsonString>() && gpio.as<JsonString>().size() == 0) {
result.accepted = true;
if (target != GPIO_IS_NOT_CONFIGURED) {
target = GPIO_IS_NOT_CONFIGURED;
result.changed = true;
}
} else if (gpio.is<uint8_t>()) {
const auto value = gpio.as<uint8_t>();
if (value == GPIO_IS_NOT_CONFIGURED || (GPIO_IS_VALID(value) && (!isValid || isValid(value)))) {
result.accepted = true;
if (value != target) {
target = value;
result.changed = true;
}
}
}
}
// Network settings // Network settings
static bool isHostnameValid(const char* value) { static bool isHostnameValid(const char* value) {
@@ -353,13 +387,27 @@ JsonVariant toJson(const NetworkSettings& src, JsonVariant dst) {
wifi[S_STA][S_CHANNEL] = src.wifi.sta.channel; wifi[S_STA][S_CHANNEL] = src.wifi.sta.channel;
#if USE_ETHERNET #if USE_ETHERNET
auto gpio = dst[S_ETHERNET][S_GPIO].to<JsonObject>(); auto ethernet = dst[S_ETHERNET].to<JsonObject>();
gpio[S_CLK] = src.ethernet.w5500.clk; ethernet[S_TYPE] = static_cast<uint8_t>(src.ethernet.type);
gpio[S_MOSI] = src.ethernet.w5500.mosi;
gpio[S_MISO] = src.ethernet.w5500.miso; #if CONFIG_ETH_USE_SPI_ETHERNET && CONFIG_ETH_SPI_ETHERNET_W5500
gpio[S_CS] = src.ethernet.w5500.cs; auto w5500 = ethernet[S_W5500].to<JsonObject>();
gpio[S_IRQ] = src.ethernet.w5500.irq; w5500[S_CLK] = src.ethernet.w5500.clk;
gpio[S_RST] = src.ethernet.w5500.rst; w5500[S_MOSI] = src.ethernet.w5500.mosi;
w5500[S_MISO] = src.ethernet.w5500.miso;
w5500[S_CS] = src.ethernet.w5500.cs;
w5500[S_IRQ] = src.ethernet.w5500.irq;
w5500[S_RST] = src.ethernet.w5500.rst;
#endif
#if CONFIG_ETH_USE_ESP32_EMAC && CONFIG_IDF_TARGET_ESP32
auto lan8720 = ethernet[S_LAN8720].to<JsonObject>();
lan8720[S_MDC] = src.ethernet.lan8720.mdc;
lan8720[S_MDIO] = src.ethernet.lan8720.mdio;
lan8720[S_POWER] = src.ethernet.lan8720.power;
lan8720[S_PHY_ADDR] = src.ethernet.lan8720.phyAddr;
lan8720[S_CLOCK_MODE] = src.ethernet.lan8720.clockMode;
#endif
#endif #endif
dst[S_TYPE] = static_cast<uint8_t>(src.type); dst[S_TYPE] = static_cast<uint8_t>(src.type);
@@ -545,47 +593,79 @@ SettingResult fromJson(JsonVariantConst src, NetworkSettings& dst) {
} }
#if USE_ETHERNET #if USE_ETHERNET
// Ethernet GPIOs use the same strict numeric contract as the other GPIO settings.
const auto ethernet = src[S_ETHERNET]; const auto ethernet = src[S_ETHERNET];
const auto parseGpio = [&result](JsonVariantConst gpio, uint8_t& target, bool output) { if (ethernet[S_TYPE].is<uint8_t>()) {
uint8_t value; const auto value = static_cast<EthernetType>(ethernet[S_TYPE].as<uint8_t>());
if (gpio.is<JsonString>() && gpio.as<JsonString>().size() == 0) {
value = GPIO_IS_NOT_CONFIGURED;
} else if (gpio.is<uint8_t>()) { bool valid = value == EthernetType::NONE;
value = gpio.as<uint8_t>(); #if CONFIG_ETH_USE_SPI_ETHERNET && CONFIG_ETH_SPI_ETHERNET_W5500
valid |= value == EthernetType::W5500;
#endif
} else { #if CONFIG_ETH_USE_ESP32_EMAC && CONFIG_IDF_TARGET_ESP32
return; valid |= value == EthernetType::LAN8720;
#endif
if (valid) {
result.accepted = true;
if (value != dst.ethernet.type) {
dst.ethernet.type = value;
result.changed = true;
}
}
}
#if CONFIG_ETH_USE_SPI_ETHERNET && CONFIG_ETH_SPI_ETHERNET_W5500
const auto w5500 = ethernet[S_W5500];
parseJsonGpio(w5500[S_CLK], dst.ethernet.w5500.clk, result, isValidOutputGpio);
parseJsonGpio(w5500[S_MOSI], dst.ethernet.w5500.mosi, result, isValidOutputGpio);
parseJsonGpio(w5500[S_MISO], dst.ethernet.w5500.miso, result);
parseJsonGpio(w5500[S_CS], dst.ethernet.w5500.cs, result, isValidOutputGpio);
parseJsonGpio(w5500[S_IRQ], dst.ethernet.w5500.irq, result);
parseJsonGpio(w5500[S_RST], dst.ethernet.w5500.rst, result, isValidOutputGpio);
#endif
#if CONFIG_ETH_USE_ESP32_EMAC && CONFIG_IDF_TARGET_ESP32
const auto lan8720 = ethernet[S_LAN8720];
parseJsonGpio(lan8720[S_MDC], dst.ethernet.lan8720.mdc, result, isValidOutputGpio);
parseJsonGpio(lan8720[S_MDIO], dst.ethernet.lan8720.mdio, result, isValidOutputGpio);
parseJsonGpio(lan8720[S_POWER], dst.ethernet.lan8720.power, result, isValidOutputGpio);
if (lan8720[S_PHY_ADDR].is<uint8_t>()) {
const auto value = lan8720[S_PHY_ADDR].as<uint8_t>();
if (value <= 31) {
result.accepted = true;
if (value != dst.ethernet.lan8720.phyAddr) {
dst.ethernet.lan8720.phyAddr = value;
result.changed = true;
}
}
} }
if (value != GPIO_IS_NOT_CONFIGURED && !(output ? GPIO_IS_VALID_OUTPUT(value) : GPIO_IS_VALID_INPUT(value))) { if (lan8720[S_CLOCK_MODE].is<uint8_t>()) {
return; const auto value = lan8720[S_CLOCK_MODE].as<uint8_t>();
}
result.accepted = true; if (value <= 3) {
if (value != target) { result.accepted = true;
target = value; if (value != dst.ethernet.lan8720.clockMode) {
result.changed = true; dst.ethernet.lan8720.clockMode = value;
result.changed = true;
}
}
} }
}; #endif
const auto gpio = ethernet[S_GPIO];
parseGpio(gpio[S_CLK], dst.ethernet.w5500.clk, true);
parseGpio(gpio[S_MOSI], dst.ethernet.w5500.mosi, true);
parseGpio(gpio[S_MISO], dst.ethernet.w5500.miso, false);
parseGpio(gpio[S_CS], dst.ethernet.w5500.cs, true);
parseGpio(gpio[S_IRQ], dst.ethernet.w5500.irq, false);
parseGpio(gpio[S_RST], dst.ethernet.w5500.rst, true);
#endif #endif
if (src[S_TYPE].is<uint8_t>()) { if (src[S_TYPE].is<uint8_t>()) {
const auto value = static_cast<NetworkMode>(src[S_TYPE].as<uint8_t>()); const auto value = static_cast<NetworkMode>(src[S_TYPE].as<uint8_t>());
if (value == NetworkMode::STA
#if USE_ETHERNET bool valid = value == NetworkMode::STA;
|| value == NetworkMode::ETH #if USE_ETHERNET
#endif valid |= value == NetworkMode::ETH;
) { #endif
if (valid) {
result.accepted = true; result.accepted = true;
if (value != dst.type) { if (value != dst.type) {
dst.type = value; dst.type = value;
+89 -26
View File
@@ -26,6 +26,7 @@ static std::atomic<NetworkState> staState{NetworkState::NETWORK_DISABLED};
static std::atomic<NetworkState> apState{NetworkState::NETWORK_DISABLED}; static std::atomic<NetworkState> apState{NetworkState::NETWORK_DISABLED};
#if USE_ETHERNET #if USE_ETHERNET
static std::atomic<bool> ethStarted{false}; static std::atomic<bool> ethStarted{false};
static eth_phy_type_t ethType = ETH_PHY_MAX;
static std::atomic<NetworkState> ethState{NetworkState::NETWORK_DISABLED}; static std::atomic<NetworkState> ethState{NetworkState::NETWORK_DISABLED};
#endif #endif
@@ -183,21 +184,48 @@ String getNetworkMac() {
return getNetworkInterface().macAddress(); return getNetworkInterface().macAddress();
} }
bool isEthernetConfigured(const NetworkSettings& config) { bool isEthernetConfigValid(const NetworkSettings& src) {
#if USE_ETHERNET #if USE_ETHERNET
const auto& gpios = config.ethernet.w5500; #if CONFIG_ETH_USE_SPI_ETHERNET && CONFIG_ETH_SPI_ETHERNET_W5500
if (src.ethernet.type == EthernetType::W5500) {
const auto& config = src.ethernet.w5500;
return config.ethernet.type == EthernetType::W5500 && return GPIO_IS_VALID_OUTPUT(config.clk) &&
GPIO_IS_VALID_OUTPUT(gpios.clk) && GPIO_IS_VALID_OUTPUT(config.mosi) &&
GPIO_IS_VALID_OUTPUT(gpios.mosi) && GPIO_IS_VALID_INPUT(config.miso) &&
GPIO_IS_VALID_INPUT(gpios.miso) && GPIO_IS_VALID_OUTPUT(config.cs) &&
GPIO_IS_VALID_OUTPUT(gpios.cs) && (config.irq == GPIO_IS_NOT_CONFIGURED || GPIO_IS_VALID_INPUT(config.irq)) &&
GPIO_IS_VALID_INPUT(gpios.irq) && (config.rst == GPIO_IS_NOT_CONFIGURED || GPIO_IS_VALID_OUTPUT(config.rst));
GPIO_IS_VALID_OUTPUT(gpios.rst); }
#endif
#if CONFIG_ETH_USE_ESP32_EMAC && CONFIG_IDF_TARGET_ESP32
if (src.ethernet.type == EthernetType::LAN8720) {
const auto& config = src.ethernet.lan8720;
static const uint8_t clockGpios[] = {0, 0, 16, 17}; // eth_clock_mode_t order
if (config.phyAddr > 31 || config.clockMode >= sizeof(clockGpios)) {
return false;
}
const auto clockGpio = clockGpios[config.clockMode];
const auto isControlGpio = [clockGpio](uint8_t gpio) {
// The ESP32 reserves the RMII data lines and the selected reference clock.
return GPIO_IS_VALID_OUTPUT(gpio) && gpio != clockGpio &&
gpio != ETH_RMII_TX_EN && gpio != ETH_RMII_TX0 && gpio != ETH_RMII_TX1 &&
gpio != ETH_RMII_CRS_DV && gpio != ETH_RMII_RX0 && gpio != ETH_RMII_RX1_EN;
};
return isControlGpio(config.mdc) && isControlGpio(config.mdio) &&
(config.power == GPIO_IS_NOT_CONFIGURED || isControlGpio(config.power)) &&
config.mdc != config.mdio && config.power != config.mdc && config.power != config.mdio;
}
#endif
#else #else
(void)config; (void)src;
return false;
#endif #endif
return false;
} }
bool isNetworkInterfaceStarted(NetworkMode mode) { bool isNetworkInterfaceStarted(NetworkMode mode) {
@@ -557,13 +585,18 @@ static bool stopEthernet() {
return false; return false;
} }
// end() removes the device, but leaves the SPI bus with its previous GPIOs. #if CONFIG_ETH_USE_SPI_ETHERNET && CONFIG_ETH_SPI_ETHERNET_W5500
const esp_err_t result = spi_bus_free(SPI2_HOST); // SPI bus free
if (result != ESP_OK && result != ESP_ERR_INVALID_STATE) { if (ethType == ETH_PHY_W5500) {
ESP_LOGE(L_NETWORK, "Failed release Ethernet SPI bus: %s", esp_err_to_name(result)); const esp_err_t result = spi_bus_free(SPI2_HOST);
return false; if (result != ESP_OK && result != ESP_ERR_INVALID_STATE) {
ESP_LOGE(L_NETWORK, "Failed release Ethernet SPI bus: %s", esp_err_to_name(result));
return false;
}
} }
#endif
ethType = ETH_PHY_MAX;
postInterfaceStopped(ARDUINO_EVENT_ETH_STOP); postInterfaceStopped(ARDUINO_EVENT_ETH_STOP);
return true; return true;
} }
@@ -583,17 +616,47 @@ static bool configureEthernet() {
} }
static bool startEthernet() { static bool startEthernet() {
if ((ETH.handle() != nullptr || ETH.netif() != nullptr) && !stopEthernet()) { // A previous begin() can leave driver resources allocated.
return false; if (ethType != ETH_PHY_MAX || ETH.handle() != nullptr || ETH.netif() != nullptr) {
// Release them before starting the next driver.
if (!stopEthernet()) {
return false;
}
} }
const auto& gpios = networkSettings.ethernet.w5500; bool initialized = false;
ESP_LOGI(L_NETWORK, "Initialize W5500 Ethernet"); const auto type = networkSettings.ethernet.type;
if (!ETH.begin( #if CONFIG_ETH_USE_SPI_ETHERNET && CONFIG_ETH_SPI_ETHERNET_W5500
ETH_PHY_W5500, 1, gpios.cs, gpios.irq, gpios.rst, if (type == EthernetType::W5500) {
SPI2_HOST, gpios.clk, gpios.miso, gpios.mosi, 12 const auto& config = networkSettings.ethernet.w5500;
)) { ESP_LOGI(L_NETWORK, "Initializing W5500 driver...");
ESP_LOGE(L_NETWORK, "W5500 initialization failed, check GPIOs and wiring");
ethType = ETH_PHY_W5500;
initialized = ETH.begin(
ETH_PHY_W5500, 1, config.cs,
config.irq == GPIO_IS_NOT_CONFIGURED ? -1 : config.irq,
config.rst == GPIO_IS_NOT_CONFIGURED ? -1 : config.rst,
SPI2_HOST, config.clk, config.miso, config.mosi, 12
);
}
#endif
#if CONFIG_ETH_USE_ESP32_EMAC && CONFIG_IDF_TARGET_ESP32
if (type == EthernetType::LAN8720) {
const auto& config = networkSettings.ethernet.lan8720;
ESP_LOGI(L_NETWORK, "Initializing LAN8720 driver...");
ethType = ETH_PHY_LAN8720;
initialized = ETH.begin(
ETH_PHY_LAN8720, config.phyAddr, config.mdc, config.mdio,
config.power == GPIO_IS_NOT_CONFIGURED ? -1 : config.power,
static_cast<eth_clock_mode_t>(config.clockMode)
);
}
#endif
if (!initialized) {
ESP_LOGE(L_NETWORK, "Ethernet initialization failed!");
stopEthernet(); stopEthernet();
return false; return false;
} }
@@ -1110,7 +1173,7 @@ static Task networkTask("Network", [](void*) {
return; return;
} }
if (networkSettings.type == NetworkMode::ETH && !isEthernetConfigured()) { if (networkSettings.type == NetworkMode::ETH && !isEthernetConfigValid()) {
#if USE_ETHERNET #if USE_ETHERNET
if (ethStarted.load()) { if (ethStarted.load()) {
stopEthernet(); stopEthernet();
+2 -10
View File
@@ -400,11 +400,7 @@ static void restApi() {
webServer->on("/api/network/settings", HTTP_GET, [](AsyncWebServerRequest *request) { webServer->on("/api/network/settings", HTTP_GET, [](AsyncWebServerRequest *request) {
// Prepare response // Prepare response
auto *response = new AsyncJsonResponse(); auto *response = new AsyncJsonResponse();
auto& doc = response->getRoot(); toJson(networkSettings, response->getRoot());
toJson(networkSettings, doc);
#if USE_ETHERNET
doc[S_ETHERNET][S_CONFIGURED] = isEthernetConfigured();
#endif
// Send response // Send response
response->setLength(); response->setLength();
@@ -437,13 +433,9 @@ static void restApi() {
} else { } else {
// Prepare response // Prepare response
auto *response = new AsyncJsonResponse(); auto *response = new AsyncJsonResponse();
auto& responseDoc = response->getRoot();
toJson(networkSettings, responseDoc);
#if USE_ETHERNET
responseDoc[S_ETHERNET][S_CONFIGURED] = isEthernetConfigured();
#endif
// Send response // Send response
toJson(networkSettings, response->getRoot());
response->setLength(); response->setLength();
response->setCode(result.changed ? 201 : 200); response->setCode(result.changed ? 201 : 200);
request->send(response); request->send(response);
+17 -7
View File
@@ -29,6 +29,8 @@
"save": "保存", "save": "保存",
"saved": "已保存", "saved": "已保存",
"refresh": "刷新", "refresh": "刷新",
"search": "搜索",
"close": "关闭",
"restore": "恢复", "restore": "恢复",
"restored": "已恢复", "restored": "已恢复",
"backup": "备份", "backup": "备份",
@@ -154,24 +156,32 @@
"ethernet": "以太网", "ethernet": "以太网",
"wifi": "Wi-Fi", "wifi": "Wi-Fi",
"availableNetworks": "可用网络", "availableNetworks": "可用网络",
"staSettings": "WiFi 设置", "staSettings": "连接到 Wi-Fi",
"apSettings": "AP 设置" "apSettings": "备用接入点"
}, },
"scan": { "scan": {
"pos": "#", "pos": "#",
"info": "Info", "info": "Info",
"hiddenSsid": "请输入隐藏网络的名称",
"empty": "未找到网络",
"failed": "无法获取网络列表。",
"unavailable": "仅在 Wi-Fi 模式下可扫描网络。" "unavailable": "仅在 Wi-Fi 模式下可扫描网络。"
}, },
"ethernet": { "ethernet": {
"notConfigured": "配置全部六个 GPIO 引脚以使用以太网。", "unavailable": "此固件版本不支持以太网。",
"clk": "SPI 时钟 GPIO", "controller": "以太网控制器",
"clk": "SPI clock GPIO",
"mosi": "SPI MOSI GPIO", "mosi": "SPI MOSI GPIO",
"miso": "SPI MISO GPIO", "miso": "SPI MISO GPIO",
"cs": "SPI CS GPIO", "cs": "SPI CS GPIO",
"irq": "中断 GPIO", "irq": "Interrupt GPIO",
"rst": "复位 GPIO", "rst": "Reset GPIO",
"note": "W5500 SPI 接线" "phyAddr": "PHY 地址",
"clockMode": "RMII 时钟",
"mdc": "MDC GPIO",
"mdio": "MDIO GPIO",
"power": "电源/复位 GPIO(可选)"
}, },
"wifi": { "wifi": {
"ssid": "SSID", "ssid": "SSID",
+17 -7
View File
@@ -29,6 +29,8 @@
"save": "Save", "save": "Save",
"saved": "Saved", "saved": "Saved",
"refresh": "Refresh", "refresh": "Refresh",
"search": "Search",
"close": "Close",
"restore": "Restore", "restore": "Restore",
"restored": "Restored", "restored": "Restored",
"backup": "Backup", "backup": "Backup",
@@ -154,24 +156,32 @@
"ethernet": "Ethernet", "ethernet": "Ethernet",
"wifi": "Wi-Fi", "wifi": "Wi-Fi",
"availableNetworks": "Available networks", "availableNetworks": "Available networks",
"staSettings": "WiFi settings", "staSettings": "Connect to Wi-Fi",
"apSettings": "AP settings" "apSettings": "Fallback access point"
}, },
"scan": { "scan": {
"pos": "#", "pos": "#",
"info": "Info", "info": "Info",
"hiddenSsid": "Enter the hidden network name",
"empty": "No networks found",
"failed": "Could not retrieve the list of networks.",
"unavailable": "Network scanning is available only in Wi-Fi mode." "unavailable": "Network scanning is available only in Wi-Fi mode."
}, },
"ethernet": { "ethernet": {
"notConfigured": "Configure all six GPIOs to use Ethernet.", "unavailable": "This firmware build does not support Ethernet.",
"clk": "SPI clock GPIO", "controller": "Ethernet controller",
"clk": "SPI CLK GPIO",
"mosi": "SPI MOSI GPIO", "mosi": "SPI MOSI GPIO",
"miso": "SPI MISO GPIO", "miso": "SPI MISO GPIO",
"cs": "SPI CS GPIO", "cs": "SPI CS GPIO",
"irq": "Interrupt GPIO", "irq": "IRQ GPIO",
"rst": "Reset GPIO", "rst": "RST GPIO",
"note": "W5500 SPI wiring" "phyAddr": "PHY address",
"clockMode": "RMII clock",
"mdc": "MDC GPIO",
"mdio": "MDIO GPIO",
"power": "Power/reset GPIO (optional)"
}, },
"wifi": { "wifi": {
"ssid": "SSID", "ssid": "SSID",
+20 -10
View File
@@ -29,6 +29,8 @@
"save": "Salva", "save": "Salva",
"saved": "Salvato", "saved": "Salvato",
"refresh": "Ricarica", "refresh": "Ricarica",
"search": "Cerca",
"close": "Chiudi",
"restore": "Recupera", "restore": "Recupera",
"restored": "Recuperato", "restored": "Recuperato",
"backup": "Backup", "backup": "Backup",
@@ -154,24 +156,32 @@
"ethernet": "Ethernet", "ethernet": "Ethernet",
"wifi": "Wi-Fi", "wifi": "Wi-Fi",
"availableNetworks": "Reti disponibili", "availableNetworks": "Reti disponibili",
"staSettings": "Impostazioni WiFi", "staSettings": "Connessione al Wi-Fi",
"apSettings": "Impostazioni AP" "apSettings": "Punto di accesso di riserva"
}, },
"scan": { "scan": {
"pos": "#", "pos": "#",
"info": "Info", "info": "Info",
"hiddenSsid": "Inserisci il nome della rete nascosta",
"empty": "Nessuna rete trovata",
"failed": "Impossibile recuperare la lista delle reti.",
"unavailable": "La ricerca delle reti è disponibile solo in modalità Wi-Fi." "unavailable": "La ricerca delle reti è disponibile solo in modalità Wi-Fi."
}, },
"ethernet": { "ethernet": {
"notConfigured": "Configura tutti e sei i GPIO per utilizzare Ethernet.", "unavailable": "Questa versione del firmware non supporta Ethernet.",
"clk": "GPIO clock SPI", "controller": "Controller Ethernet",
"mosi": "GPIO MOSI SPI", "clk": "SPI clock GPIO",
"miso": "GPIO MISO SPI", "mosi": "SPI MOSI GPIO",
"cs": "GPIO CS SPI", "miso": "SPI MISO GPIO",
"irq": "GPIO interrupt", "cs": "SPI CS GPIO",
"rst": "GPIO reset", "irq": "Interrupt GPIO",
"note": "Cablaggio SPI del W5500" "rst": "Reset GPIO",
"phyAddr": "Indirizzo PHY",
"clockMode": "Clock RMII",
"mdc": "MDC GPIO",
"mdio": "MDIO GPIO",
"power": "GPIO alimentazione/reset (opzionale)"
}, },
"wifi": { "wifi": {
"ssid": "SSID", "ssid": "SSID",
+15 -5
View File
@@ -29,6 +29,8 @@
"save": "Opslaan", "save": "Opslaan",
"saved": "Opgeslagen", "saved": "Opgeslagen",
"refresh": "Vernieuwen", "refresh": "Vernieuwen",
"search": "Zoeken",
"close": "Sluiten",
"restore": "Herstellen", "restore": "Herstellen",
"restored": "Hersteld", "restored": "Hersteld",
"backup": "Back-up", "backup": "Back-up",
@@ -154,24 +156,32 @@
"ethernet": "Ethernet", "ethernet": "Ethernet",
"wifi": "Wi-Fi", "wifi": "Wi-Fi",
"availableNetworks": "Beschikbare netwerken", "availableNetworks": "Beschikbare netwerken",
"staSettings": "WiFi-instellingen", "staSettings": "Verbinden met wifi",
"apSettings": "AP-instellingen" "apSettings": "Reservetoegangspunt"
}, },
"scan": { "scan": {
"pos": "#", "pos": "#",
"info": "Info", "info": "Info",
"hiddenSsid": "Voer de naam van het verborgen netwerk in",
"empty": "Geen netwerken gevonden",
"failed": "De lijst met netwerken kon niet worden opgehaald.",
"unavailable": "Netwerken zoeken is alleen beschikbaar in de Wi-Fi-modus." "unavailable": "Netwerken zoeken is alleen beschikbaar in de Wi-Fi-modus."
}, },
"ethernet": { "ethernet": {
"notConfigured": "Configureer alle zes GPIO's om Ethernet te gebruiken.", "unavailable": "Deze firmwarebuild ondersteunt geen Ethernet.",
"clk": "SPI-klok GPIO", "controller": "Ethernetcontroller",
"clk": "SPI clock GPIO",
"mosi": "SPI MOSI GPIO", "mosi": "SPI MOSI GPIO",
"miso": "SPI MISO GPIO", "miso": "SPI MISO GPIO",
"cs": "SPI CS GPIO", "cs": "SPI CS GPIO",
"irq": "Interrupt GPIO", "irq": "Interrupt GPIO",
"rst": "Reset GPIO", "rst": "Reset GPIO",
"note": "W5500 SPI-bedrading" "phyAddr": "PHY-adres",
"clockMode": "RMII-klok",
"mdc": "MDC GPIO",
"mdio": "MDIO GPIO",
"power": "Voedings-/reset-GPIO (optioneel)"
}, },
"wifi": { "wifi": {
"ssid": "SSID", "ssid": "SSID",
+20 -10
View File
@@ -29,6 +29,8 @@
"save": "Сохранить", "save": "Сохранить",
"saved": "Сохранено", "saved": "Сохранено",
"refresh": "Обновить", "refresh": "Обновить",
"search": "Поиск",
"close": "Закрыть",
"restore": "Восстановить настройки", "restore": "Восстановить настройки",
"restored": "Восстановлено", "restored": "Восстановлено",
"backup": "Сохранить настройки", "backup": "Сохранить настройки",
@@ -154,24 +156,32 @@
"ethernet": "Ethernet", "ethernet": "Ethernet",
"wifi": "Wi-Fi", "wifi": "Wi-Fi",
"availableNetworks": "Доступные сети", "availableNetworks": "Доступные сети",
"staSettings": "Настройки подключения", "staSettings": "Подключение к Wi-Fi",
"apSettings": "Настройки точки доступа" "apSettings": "Резервная точка доступа"
}, },
"scan": { "scan": {
"pos": "#", "pos": "#",
"info": "Инфо", "info": "Инфо",
"hiddenSsid": "Введите имя скрытой сети",
"empty": "Сети не найдены",
"failed": "Не удалось получить список сетей.",
"unavailable": "Поиск сетей доступен только в режиме Wi-Fi." "unavailable": "Поиск сетей доступен только в режиме Wi-Fi."
}, },
"ethernet": { "ethernet": {
"notConfigured": "Для подключения через Ethernet настройте все шесть GPIO.", "unavailable": "Эта сборка прошивки не поддерживает Ethernet.",
"clk": "GPIO тактирования SPI", "controller": "Контроллер Ethernet",
"mosi": "GPIO MOSI SPI", "clk": "SPI clock GPIO",
"miso": "GPIO MISO SPI", "mosi": "SPI MOSI GPIO",
"cs": "GPIO CS SPI", "miso": "SPI MISO GPIO",
"irq": "GPIO прерывания", "cs": "SPI CS GPIO",
"rst": "GPIO сброса", "irq": "Interrupt GPIO",
"note": "Подключение W5500 по SPI" "rst": "Reset GPIO",
"phyAddr": "Адрес PHY",
"clockMode": "Тактирование RMII",
"mdc": "MDC GPIO",
"mdio": "MDIO GPIO",
"power": "GPIO питания/сброса (необязательно)"
}, },
"wifi": { "wifi": {
"ssid": "Имя сети", "ssid": "Имя сети",
+451 -233
View File
@@ -41,47 +41,175 @@
<div id="network-settings-busy" aria-busy="true"></div> <div id="network-settings-busy" aria-busy="true"></div>
<form action="/api/network/settings" id="network-settings" class="hidden"> <form action="/api/network/settings" id="network-settings" class="hidden">
<label> <div class="grid">
<span data-i18n>network.params.hostname</span> <label>
<input type="text" name="hostname" maxlength="24" pattern="[A-Za-z0-9]+[A-Za-z0-9\-]+[A-Za-z0-9]+" required> <span data-i18n>network.params.hostname</span>
</label> <input type="text" name="hostname" maxlength="24" pattern="[A-Za-z0-9]+[A-Za-z0-9\-]+[A-Za-z0-9]+" required>
</label>
<label> <label>
<span data-i18n>network.type.title</span> <span data-i18n>network.type.title</span>
<select name="type"> <select name="type">
<option value="2" data-i18n>network.type.wifi</option> <option value="2" data-i18n>network.type.wifi</option>
<option value="3" hidden disabled data-i18n>network.type.ethernet</option> <option value="3" data-i18n>network.type.ethernet</option>
</select> </select>
</label> </label>
</div>
<label>
<input type="checkbox" name="use_dhcp" value="true">
<span data-i18n>network.params.dhcp</span>
</label>
<br />
<hr /> <hr />
<h4 data-i18n>network.section.static</h4>
<label> <details>
<span data-i18n>network.params.ip</span> <summary><b data-i18n>network.section.static</b></summary>
<input type="text" name="static_config[ip]" maxlength="16" pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" required> <div>
</label> <fieldset>
<label>
<input type="checkbox" name="use_dhcp" value="true">
<span data-i18n>network.params.dhcp</span>
</label>
</fieldset>
<label> <div class="grid">
<span data-i18n>network.params.gateway</span> <label>
<input type="text" name="static_config[gateway]" maxlength="16" pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" required> <span data-i18n>network.params.ip</span>
</label> <input type="text" name="static_config[ip]" maxlength="16" pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" required>
</label>
<label> <label>
<span data-i18n>network.params.subnet</span> <span data-i18n>network.params.subnet</span>
<input type="text" name="static_config[subnet]" maxlength="16" pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" required> <input type="text" name="static_config[subnet]" maxlength="16" pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" required>
</label> </label>
</div>
<label> <div class="grid">
<span data-i18n>network.params.dns</span> <label>
<input type="text" name="static_config[dns]" maxlength="16" pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" required> <span data-i18n>network.params.gateway</span>
</label> <input type="text" name="static_config[gateway]" maxlength="16" pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" required>
</label>
<label>
<span data-i18n>network.params.dns</span>
<input type="text" name="static_config[dns]" maxlength="16" pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" required>
</label>
</div>
</div>
</details>
<hr />
<details class="ethernet">
<summary><b data-i18n>network.section.ethernet</b></summary>
<div>
<p class="unsupported hidden" data-i18n>network.ethernet.unavailable</p>
<fieldset class="supported">
<label>
<span data-i18n>network.ethernet.controller</span>
<select name="ethernet[type]">
<option value="0">NONE</option>
</select>
</label>
</fieldset>
<fieldset id="ethernet-w5500">
<legend><b>W5500</b></legend>
<div class="grid">
<label>
<span data-i18n>network.ethernet.clk</span>
<input type="number" inputmode="numeric" name="ethernet[w5500][clk]" min="0" max="254" step="1">
</label>
<label>
<span data-i18n>network.ethernet.mosi</span>
<input type="number" inputmode="numeric" name="ethernet[w5500][mosi]" min="0" max="254" step="1">
</label>
<label>
<span data-i18n>network.ethernet.miso</span>
<input type="number" inputmode="numeric" name="ethernet[w5500][miso]" min="0" max="254" step="1">
</label>
</div>
<div class="grid">
<label>
<span data-i18n>network.ethernet.cs</span>
<input type="number" inputmode="numeric" name="ethernet[w5500][cs]" min="0" max="254" step="1">
</label>
<label>
<span data-i18n>network.ethernet.irq</span>
<input type="number" inputmode="numeric" name="ethernet[w5500][irq]" min="0" max="254" step="1">
</label>
<label>
<span data-i18n>network.ethernet.rst</span>
<input type="number" inputmode="numeric" name="ethernet[w5500][rst]" min="0" max="254" step="1">
</label>
</div>
</fieldset>
<fieldset id="ethernet-lan8720">
<legend><b>LAN8720</b></legend>
<div class="grid">
<label>
<span data-i18n>network.ethernet.phyAddr</span>
<input type="number" inputmode="numeric" name="ethernet[lan8720][phy_addr]" min="0" max="31" step="1" required>
</label>
<label>
<span data-i18n>network.ethernet.clockMode</span>
<select name="ethernet[lan8720][clock_mode]">
<option value="0">GPIO0 IN</option>
<option value="1">GPIO0 OUT</option>
<option value="2">GPIO16 OUT</option>
<option value="3">GPIO17 OUT</option>
</select>
</label>
</div>
<div class="grid">
<label>
<span data-i18n>network.ethernet.mdc</span>
<input type="number" inputmode="numeric" name="ethernet[lan8720][mdc]" min="0" max="254" step="1">
</label>
<label>
<span data-i18n>network.ethernet.mdio</span>
<input type="number" inputmode="numeric" name="ethernet[lan8720][mdio]" min="0" max="254" step="1">
</label>
<label>
<span data-i18n>network.ethernet.power</span>
<input type="number" inputmode="numeric" name="ethernet[lan8720][power]" min="0" max="254" step="1">
</label>
</div>
</fieldset>
</div>
</details>
<hr />
<details>
<summary><b data-i18n>network.section.apSettings</b></summary>
<div>
<div class="grid">
<label>
<span data-i18n>network.wifi.ssid</span>
<input type="text" name="wifi[ap][ssid]" maxlength="32" required>
</label>
<label>
<span data-i18n>network.wifi.password</span>
<input type="text" name="wifi[ap][password]" maxlength="64" required>
</label>
</div>
<label>
<span data-i18n>network.wifi.channel</span>
<input type="number" inputmode="numeric" name="wifi[ap][channel]" min="1" max="12" step="1" required>
</label>
</div>
</details>
<br />
<button type="submit" data-i18n>button.save</button> <button type="submit" data-i18n>button.save</button>
</form> </form>
</div> </div>
@@ -91,147 +219,65 @@
<article id="wifi-section"> <article id="wifi-section">
<div> <div>
<hgroup> <hgroup>
<h2 data-i18n>network.section.wifi</h2> <h2 data-i18n>network.section.staSettings</h2>
<p></p> <p></p>
</hgroup> </hgroup>
<hgroup> <div>
<h3 data-i18n>network.section.availableNetworks</h3> <form action="/api/network/settings" id="sta-settings" class="hidden">
<p></p> <label for="sta-ssid" data-i18n>network.wifi.ssid</label>
</hgroup> <div role="group">
<input type="text" id="sta-ssid" name="wifi[sta][ssid]" maxlength="32" required>
<form action="/api/network/scan" id="network-scan"> <button type="button" class="scan" aria-haspopup="dialog" aria-controls="scan-dialog" data-i18n>button.search</button>
<fieldset id="wifi-scan-controls" disabled>
<div style="max-height: 25rem;" class="overflow-auto">
<table id="networks" role="grid">
<thead>
<tr>
<th scope="col" data-i18n>network.scan.pos</th>
<th scope="col" data-i18n>network.wifi.ssid</th>
<th scope="col" data-i18n>network.scan.info</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div> </div>
<p id="scan-unavailable" class="hidden" data-i18n>network.scan.unavailable</p> <div class="grid">
<button type="submit" data-i18n>button.refresh</button> <label>
</fieldset> <span data-i18n>network.wifi.password</span>
</form> <input type="password" name="wifi[sta][password]" maxlength="64">
</label>
<hr /> <label>
<div> <span data-i18n>network.wifi.channel</span>
<hgroup> <input type="number" inputmode="numeric" name="wifi[sta][channel]" min="0" max="12" step="1" required>
<h3 data-i18n>network.section.staSettings</h3> <small data-i18n>network.sta.channel.note</small>
<p></p> </label>
</hgroup> </div>
<div id="sta-settings-busy" aria-busy="true"></div>
<form action="/api/network/settings" id="sta-settings" class="hidden">
<label>
<span data-i18n>network.wifi.ssid</span>
<input type="text" name="wifi[sta][ssid]" maxlength="32" required>
</label>
<label>
<span data-i18n>network.wifi.password</span>
<input type="password" name="wifi[sta][password]" maxlength="64" required>
</label>
<label>
<span data-i18n>network.wifi.channel</span>
<input type="number" inputmode="numeric" name="wifi[sta][channel]" min="0" max="12" step="1" required>
<small data-i18n>network.sta.channel.note</small>
</label>
<br />
<button type="submit" data-i18n>button.save</button> <button type="submit" data-i18n>button.save</button>
</form> </form>
</div> </div>
<hr />
<div>
<hgroup>
<h3 data-i18n>network.section.apSettings</h3>
<p></p>
</hgroup>
<div id="ap-settings-busy" aria-busy="true"></div>
<form action="/api/network/settings" id="ap-settings" class="hidden">
<label>
<span data-i18n>network.wifi.ssid</span>
<input type="text" name="wifi[ap][ssid]" maxlength="32" required>
</label>
<label>
<span data-i18n>network.wifi.password</span>
<input type="text" name="wifi[ap][password]" maxlength="64" required>
</label>
<label>
<span data-i18n>network.wifi.channel</span>
<input type="number" inputmode="numeric" name="wifi[ap][channel]" min="1" max="12" step="1" required>
</label>
<button type="submit" data-i18n>button.save</button>
</form>
</div>
</div>
</article>
<article id="ethernet-section" class="hidden">
<div>
<hgroup>
<h3 data-i18n>network.section.ethernet</h3>
<p></p>
</hgroup>
<div id="ethernet-settings-busy" aria-busy="true"></div>
<form action="/api/network/settings" id="ethernet-settings" class="hidden">
<small id="ethernet-not-configured" class="hidden" data-i18n>network.ethernet.notConfigured</small>
<div class="grid">
<label>
<span data-i18n>network.ethernet.clk</span>
<input type="number" inputmode="numeric" name="ethernet[gpio][clk]" min="0" max="254" step="1">
</label>
<label>
<span data-i18n>network.ethernet.mosi</span>
<input type="number" inputmode="numeric" name="ethernet[gpio][mosi]" min="0" max="254" step="1">
</label>
<label>
<span data-i18n>network.ethernet.miso</span>
<input type="number" inputmode="numeric" name="ethernet[gpio][miso]" min="0" max="254" step="1">
</label>
</div>
<div class="grid">
<label>
<span data-i18n>network.ethernet.cs</span>
<input type="number" inputmode="numeric" name="ethernet[gpio][cs]" min="0" max="254" step="1">
</label>
<label>
<span data-i18n>network.ethernet.irq</span>
<input type="number" inputmode="numeric" name="ethernet[gpio][irq]" min="0" max="254" step="1">
</label>
<label>
<span data-i18n>network.ethernet.rst</span>
<input type="number" inputmode="numeric" name="ethernet[gpio][rst]" min="0" max="254" step="1">
</label>
</div>
<small data-i18n>network.ethernet.note</small>
<button type="submit" data-i18n>button.save</button>
</form>
</div> </div>
</article> </article>
</main> </main>
<dialog id="scan-dialog">
<article>
<header>
<button type="button" aria-label="Close" rel="prev"></button>
<p><b data-i18n>network.section.availableNetworks</b></p>
</header>
<form action="/api/network/scan" id="network-scan">
<table>
<thead>
<tr>
<th scope="col" data-i18n>network.scan.pos</th>
<th scope="col" data-i18n>network.wifi.ssid</th>
<th scope="col" data-i18n>network.scan.info</th>
</tr>
</thead>
<tbody></tbody>
</table>
<div role="status"></div>
</form>
<footer>
<button type="submit" class="refresh" form="network-scan" data-i18n>button.refresh</button>
</footer>
</article>
</dialog>
<footer class="container"> <footer class="container">
<small> <small>
<b>Made by Laxilef</b> <b>Made by Laxilef</b>
@@ -245,100 +291,272 @@
<script src="/static/app.js?{BUILD_TIME}"></script> <script src="/static/app.js?{BUILD_TIME}"></script>
<script> <script>
const setupNetworkScan = () => {
const staForm = document.getElementById('sta-settings');
const ssidInput = staForm.querySelector("[name='wifi[sta][ssid]']");
const dialog = document.getElementById('scan-dialog');
const form = dialog.querySelector('form');
const closeButton = dialog.querySelector('[rel="prev"]');
const refreshButton = dialog.querySelector('.refresh');
const status = form.querySelector('[role="status"]');
const tbody = form.querySelector('tbody');
const authNames = [
'Open', 'WEP', 'WPA', 'WPA2', 'WPA/WPA2', 'WPA/WPA2 Enterprise',
'WPA3', 'WPA2/WPA3', 'WAPI', 'OWE', 'WPA3 Enterprise'
];
let scanController;
let retryTimer;
const selectNetwork = (network) => {
if (network.hidden) {
ssidInput.value = '';
ssidInput.placeholder = i18n('network.scan.hiddenSsid');
ssidInput.removeAttribute('aria-invalid');
} else {
ssidInput.value = network.ssid;
ssidInput.removeAttribute('placeholder');
ssidInput.dispatchEvent(new Event('change', { bubbles: true }));
}
dialog.close();
ssidInput.focus();
};
const addIcon = (cell, iconClass, label) => {
const icon = document.createElement('i');
icon.className = iconClass;
const tooltip = document.createElement('span');
tooltip.dataset.tooltip = label;
tooltip.setAttribute('role', 'img');
tooltip.setAttribute('aria-label', label);
tooltip.appendChild(icon);
cell.appendChild(tooltip);
};
const addNetworkRow = (network, index) => {
const row = tbody.insertRow();
row.className = 'network';
row.insertCell().textContent = '#' + (index + 1);
const nameButton = document.createElement('button');
nameButton.type = 'button';
nameButton.textContent = network.hidden ? network.bssid : network.ssid;
nameButton.classList.toggle('bssid', network.hidden);
row.insertCell().appendChild(nameButton);
const infoCell = row.insertCell();
const strength = Math.max(0, Math.ceil(network.signal_quality / 20) - 1);
addIcon(infoCell, 'icons-wifi-strength-' + strength, network.signal_quality + '%');
const authIcon = network.auth === 0 ? 'icons-unlocked' : 'icons-locked';
addIcon(infoCell, authIcon, authNames[network.auth] || 'unknown');
row.addEventListener('click', () => selectNetwork(network));
};
const scan = async (signal, attempt = 1) => {
if (signal.aborted || !dialog.open) {
return;
}
const maxAttempts = 6;
let retryDelay = 0;
let unavailable = false;
let message = 'network.scan.failed';
try {
const response = await fetch(form.action, {
cache: "no-cache",
credentials: "include",
signal
});
const networks = response.status === 200
? await response.json()
: null;
// A previous scan can finish after the dialog is closed and opened again.
if (signal.aborted || !dialog.open) {
return;
}
if (networks !== null) {
networks.forEach(addNetworkRow);
message = networks.length ? '' : 'network.scan.empty';
} else if (response.status === 409) {
unavailable = true;
message = 'network.scan.unavailable';
} else if ((response.status === 404 || response.status === 202) && attempt < maxAttempts) {
// The ESP returns 404 when it starts a scan and 202 while it is running.
retryDelay = 5000;
}
} catch {
if (signal.aborted || !dialog.open) {
return;
}
tbody.replaceChildren();
if (attempt < maxAttempts) {
retryDelay = 10000;
}
} finally {
if (!signal.aborted && dialog.open) {
if (retryDelay) {
retryTimer = setTimeout(() => scan(signal, attempt + 1), retryDelay);
} else {
status.textContent = message ? i18n(message) : '';
refreshButton.disabled = unavailable;
refreshButton.removeAttribute('aria-busy');
}
}
}
};
const stopScan = () => {
clearTimeout(retryTimer);
scanController?.abort();
};
const startScan = () => {
stopScan();
scanController = new AbortController();
tbody.replaceChildren();
status.textContent = '';
refreshButton.disabled = true;
refreshButton.setAttribute('aria-busy', 'true');
scan(scanController.signal);
};
staForm.querySelector('.scan').addEventListener('click', () => {
closeButton.setAttribute('aria-label', i18n('button.close'));
dialog.showModal();
document.documentElement.classList.add('modal-is-open');
startScan();
});
form.addEventListener('submit', (event) => {
event.preventDefault();
if (dialog.open && !refreshButton.disabled) {
startScan();
}
});
closeButton.addEventListener('click', () => dialog.close());
dialog.addEventListener('click', (event) => {
if (event.target === dialog) {
dialog.close();
}
});
dialog.addEventListener('close', () => {
if (!dialog.open) {
stopScan();
document.documentElement.classList.remove('modal-is-open');
}
});
};
document.addEventListener('DOMContentLoaded', async () => { document.addEventListener('DOMContentLoaded', async () => {
const lang = new Lang(document.getElementById('lang')); const lang = new Lang(document.getElementById('lang'));
await lang.build(); await lang.build();
let networkType = 2; const ethernetType = document.querySelector("[name='ethernet[type]']");
const fillData = (data) => { const fillNetworkSettings = (settings) => {
networkType = data.type; setSelectValue("[name='type']", ethernetType.disabled ? 2 : settings.type);
setSelectValue("[name='type']", networkType); setInputValue("[name='hostname']", settings.hostname);
setCheckboxValue("[name='use_dhcp']", settings.use_dhcp);
for (const field of ['ip', 'gateway', 'subnet', 'dns']) {
setInputValue(`[name='static_config[${field}]']`, settings.static_config[field]);
}
const canScan = networkType === 2; const ethernet = settings.ethernet;
document.getElementById('wifi-scan-controls').disabled = !canScan; if (ethernet) {
document.querySelector('#scan-unavailable').classList.toggle('hidden', canScan); ethernetType.value = ethernet.type;
setInputValue("[name='hostname']", data.hostname); if (ethernet.w5500) {
setCheckboxValue("[name='use_dhcp']", data.use_dhcp); for (const gpio of ['clk', 'mosi', 'miso', 'cs', 'irq', 'rst']) {
setInputValue("[name='static_config[ip]']", data.static_config.ip); const value = ethernet.w5500[gpio];
setInputValue("[name='static_config[gateway]']", data.static_config.gateway); setInputValue(`[name='ethernet[w5500][${gpio}]']`, value < 255 ? value : '');
setInputValue("[name='static_config[subnet]']", data.static_config.subnet); }
setInputValue("[name='static_config[dns]']", data.static_config.dns); }
setBusy('#network-settings-busy', '#network-settings', false);
const ethernet = data.ethernet || {}; if (ethernet.lan8720) {
const ethernetConfigured = !!ethernet.configured; for (const gpio of ['mdc', 'mdio', 'power']) {
const ethernetGpio = ethernet.gpio || {}; const value = ethernet.lan8720[gpio];
const gpioValue = (value) => (value ?? 255) < 255 ? value : ''; setInputValue(`[name='ethernet[lan8720][${gpio}]']`, value < 255 ? value : '');
}
setInputValue("[name='ethernet[gpio][clk]']", gpioValue(ethernetGpio.clk)); setInputValue("[name='ethernet[lan8720][phy_addr]']", ethernet.lan8720.phy_addr);
setInputValue("[name='ethernet[gpio][mosi]']", gpioValue(ethernetGpio.mosi)); setSelectValue("[name='ethernet[lan8720][clock_mode]']", ethernet.lan8720.clock_mode);
setInputValue("[name='ethernet[gpio][miso]']", gpioValue(ethernetGpio.miso)); }
setInputValue("[name='ethernet[gpio][cs]']", gpioValue(ethernetGpio.cs)); }
setInputValue("[name='ethernet[gpio][irq]']", gpioValue(ethernetGpio.irq));
setInputValue("[name='ethernet[gpio][rst]']", gpioValue(ethernetGpio.rst));
document.getElementById('ethernet-not-configured')?.classList.toggle('hidden', ethernetConfigured); setInputValue("[name='wifi[ap][ssid]']", settings.wifi.ap.ssid);
setInputValue("[name='wifi[ap][password]']", settings.wifi.ap.password);
setBusy('#ethernet-settings-busy', '#ethernet-settings', false); setInputValue("[name='wifi[ap][channel]']", settings.wifi.ap.channel);
setInputValue("[name='wifi[sta][ssid]']", data.wifi.sta.ssid);
setInputValue("[name='wifi[sta][password]']", data.wifi.sta.password);
setInputValue("[name='wifi[sta][channel]']", data.wifi.sta.channel);
setBusy('#sta-settings-busy', '#sta-settings', false);
setInputValue("[name='wifi[ap][ssid]']", data.wifi.ap.ssid);
setInputValue("[name='wifi[ap][password]']", data.wifi.ap.password);
setInputValue("[name='wifi[ap][channel]']", data.wifi.ap.channel);
setBusy('#ap-settings-busy', '#ap-settings', false);
}; };
const applyCapabilities = (info) => { const fillStaSettings = (settings) => {
// pages and firmware ship together: the section stays hidden unless the build says it can do ethernet setInputValue("[name='wifi[sta][ssid]']", settings.wifi.sta.ssid);
const supported = info?.features?.ethernet === true; setInputValue("[name='wifi[sta][password]']", settings.wifi.sta.password);
setInputValue("[name='wifi[sta][channel]']", settings.wifi.sta.channel);
document.getElementById('ethernet-section')?.classList.toggle('hidden', !supported);
const ethernetOption = document.querySelector("[name='type'] option[value='3']");
ethernetOption.hidden = !supported;
ethernetOption.disabled = !supported;
return supported;
}; };
try { try {
const [response, infoResponse] = await Promise.all([ const response = await fetch("/api/network/settings", {
fetch("/api/network/settings", { cache: "no-cache",
cache: "no-cache", credentials: "include"
credentials: "include" });
}),
fetch("/api/info", {
cache: "no-cache",
credentials: "include"
})
]);
if (!response.ok) { if (!response.ok) {
throw new Error('Response not valid'); throw new Error('Response not valid');
} }
const info = infoResponse.ok ? await infoResponse.json() : null; const settings = await response.json();
const ethernetSupported = applyCapabilities(info); const ethernet = settings.ethernet;
if (ethernet?.w5500) {
ethernetType.add(new Option('W5500', '1'));
const result = await response.json(); } else {
fillData(result); document.getElementById('ethernet-w5500').remove();
setupForm('#network-settings', fillData, ['hostname', 'static_config.ip', 'static_config.gateway', 'static_config.subnet', 'static_config.dns']);
// Keep scans disabled if an earlier request finishes after the connection method changes.
setupNetworkScanForm('#network-scan', '#networks', networkType === 2);
if (ethernetSupported) {
setupForm('#ethernet-settings', fillData);
} }
setupForm('#sta-settings', fillData, ['wifi.sta.ssid', 'wifi.sta.password']); if (ethernet?.lan8720) {
setupForm('#ap-settings', fillData, ['wifi.ap.ssid', 'wifi.ap.password']); ethernetType.add(new Option('LAN8720', '2'));
} else {
document.getElementById('ethernet-lan8720').remove();
}
// The API includes settings only for Ethernet drivers built into this firmware.
if (!ethernet?.w5500 && !ethernet?.lan8720) {
show('.ethernet .unsupported');
hide('.ethernet .supported');
ethernetType.disabled = true;
// Value 3 in the network mode selector is Ethernet (NetworkMode::ETH).
document.querySelector("[name='type'] [value='3']").disabled = true;
}
fillNetworkSettings(settings);
fillStaSettings(settings);
setupForm('#network-settings', fillNetworkSettings, [
'hostname',
'static_config.ip', 'static_config.gateway', 'static_config.subnet', 'static_config.dns',
'wifi.ap.ssid', 'wifi.ap.password'
]);
setupForm('#sta-settings', fillStaSettings, [
'wifi.sta.ssid', 'wifi.sta.password'
]);
setupNetworkScan();
setBusy('#network-settings-busy', '#network-settings, #sta-settings', false);
} catch (error) { } catch (error) {
console.log(error); console.log(error);
@@ -346,4 +564,4 @@
}); });
</script> </script>
</body> </body>
</html> </html>
+34 -12
View File
@@ -1,4 +1,5 @@
const convertLegacyBackup = (data) => { const convertLegacyBackup = (data) => {
// 1.x to 2.0.0: rename legacy settings keys throughout the backup.
const aliases = { const aliases = {
alwaysSendIndoorTemp: 'always_send_indoor_temp', alwaysSendIndoorTemp: 'always_send_indoor_temp',
antiStuckInterval: 'antistuck_interval', antiStuckInterval: 'antistuck_interval',
@@ -61,8 +62,8 @@ const convertLegacyBackup = (data) => {
useDhcp: 'use_dhcp', useDhcp: 'use_dhcp',
webSerial: 'web_serial' webSerial: 'web_serial'
}; };
const logLevels = [0, 1, 1, 2, 3, 3, 4, 5];
// 1.x to 2.0.0: apply the key aliases recursively, including objects inside arrays.
const convert = (value) => { const convert = (value) => {
if (Array.isArray(value)) { if (Array.isArray(value)) {
return value.map(convert); return value.map(convert);
@@ -79,6 +80,8 @@ const convertLegacyBackup = (data) => {
return result; return result;
}; };
// 1.x to 2.0.0: map TinyLogger levels to ESP-IDF levels before renaming logLevel.
const logLevels = [0, 1, 1, 2, 3, 3, 4, 5];
const legacySystem = data?.settings?.system; const legacySystem = data?.settings?.system;
if (legacySystem !== null && typeof legacySystem === 'object' if (legacySystem !== null && typeof legacySystem === 'object'
&& Object.prototype.hasOwnProperty.call(legacySystem, 'logLevel')) { && Object.prototype.hasOwnProperty.call(legacySystem, 'logLevel')) {
@@ -98,8 +101,15 @@ const convertLegacyBackup = (data) => {
const result = convert(data); const result = convert(data);
// 1.x to 2.0.0: settings.system.unit_system became the sole unit setting.
const opentherm = result?.settings?.opentherm;
if (opentherm !== null && typeof opentherm === 'object') {
delete opentherm.unit_system;
}
const network = result?.network; const network = result?.network;
if (network !== null && typeof network === 'object' && !Array.isArray(network)) { if (network !== null && typeof network === 'object' && !Array.isArray(network)) {
// 1.x to 2.0.0: move network.ap and network.sta under network.wifi.
const hasLegacyAp = Object.prototype.hasOwnProperty.call(network, 'ap'); const hasLegacyAp = Object.prototype.hasOwnProperty.call(network, 'ap');
const hasLegacySta = Object.prototype.hasOwnProperty.call(network, 'sta'); const hasLegacySta = Object.prototype.hasOwnProperty.call(network, 'sta');
if (hasLegacyAp || hasLegacySta) { if (hasLegacyAp || hasLegacySta) {
@@ -117,28 +127,40 @@ const convertLegacyBackup = (data) => {
delete network.sta; delete network.sta;
} }
// 1.x to 2.0.0: derive network.type from the settings present in the backup.
if (!Object.prototype.hasOwnProperty.call(network, 'type')) { if (!Object.prototype.hasOwnProperty.call(network, 'type')) {
if (typeof network.ethernet?.enabled === 'boolean') { if (typeof network.ethernet?.enabled === 'boolean') {
// Legacy builds with W5500 after the 1.6.0 tag (#286) stored ethernet.enabled.
network.type = network.ethernet.enabled ? 3 : 2; network.type = network.ethernet.enabled ? 3 : 2;
} else if (hasLegacyAp || hasLegacySta) { } else if (hasLegacyAp || hasLegacySta) {
// Tagged 1.x releases only supported Wi-Fi.
network.type = 2; network.type = 2;
} }
} }
if (network.ethernet !== null && typeof network.ethernet === 'object' && !Array.isArray(network.ethernet)) { const ethernet = network.ethernet;
if (Object.prototype.hasOwnProperty.call(network.ethernet, 'pins') if (ethernet !== null && typeof ethernet === 'object' && !Array.isArray(ethernet)) {
&& !Object.prototype.hasOwnProperty.call(network.ethernet, 'gpio')) { // Post-1.6.0 legacy (#286) to 2.0.0: rename ethernet.pins to ethernet.gpio.
network.ethernet.gpio = network.ethernet.pins; if (Object.prototype.hasOwnProperty.call(ethernet, 'pins')
&& !Object.prototype.hasOwnProperty.call(ethernet, 'gpio')) {
ethernet.gpio = ethernet.pins;
} }
delete network.ethernet.pins; delete ethernet.pins;
delete network.ethernet.enabled; delete ethernet.enabled;
}
}
const opentherm = result?.settings?.opentherm; // 2.0.0 and 2.0.1 to the per-controller format: ethernet.gpio belonged to W5500.
if (opentherm !== null && typeof opentherm === 'object') { const gpio = ethernet.gpio;
delete opentherm.unit_system; if (gpio !== null && typeof gpio === 'object' && !Array.isArray(gpio)) {
if (!Object.prototype.hasOwnProperty.call(ethernet, 'w5500')) {
ethernet.w5500 = gpio;
}
if (!Object.prototype.hasOwnProperty.call(ethernet, 'type')) {
ethernet.type = 1; // W5500
}
}
delete ethernet.gpio;
}
} }
return result; return result;
-174
View File
@@ -92,180 +92,6 @@ const setupForm = (formSelector, onResultCallback = null, noCastItems = []) => {
}); });
} }
const setupNetworkScanForm = (formSelector, tableSelector, autorun = true) => {
const form = document.querySelector(formSelector);
if (!form) {
console.error("form not found");
return;
}
const url = form.action;
let button = form.querySelector('button[type="submit"]');
let defaultText;
const onSubmitFn = async (event) => {
if (event) {
event.preventDefault();
}
if (button) {
defaultText = button.innerHTML;
button.innerHTML = i18n('button.wait');
button.setAttribute('disabled', true);
button.setAttribute('aria-busy', true);
}
let table = document.querySelector(tableSelector);
if (!table) {
console.error("table not found");
return;
}
const onSuccess = async (response) => {
let result = await response.json();
console.log('networks: ', result);
let tbody = table.querySelector('tbody');
if (!tbody) {
tbody = table.createTBody();
}
while (tbody.rows.length > 0) {
tbody.rows[0].remove();
}
for (let i = 0; i < result.length; i++) {
let row = tbody.insertRow(-1);
row.classList.add("network");
row.dataset.ssid = result[i].hidden ? '' : result[i].ssid;
row.insertCell().textContent = `#${i + 1}`;
const nameCell = row.insertCell();
if (result[i].hidden) {
const hiddenName = document.createElement('i');
hiddenName.textContent = result[i].bssid;
nameCell.appendChild(hiddenName);
} else {
nameCell.textContent = result[i].ssid;
}
nameCell.onclick = (event) => {
const input = document.querySelector("[name='wifi[sta][ssid]']");
const ssid = row.dataset.ssid;
if (!input || !ssid) {
return;
}
input.value = ssid;
input.focus();
};
// info cell
let infoCell = row.insertCell();
// signal quality
let signalQualityIcon = document.createElement("i");
if (result[i].signal_quality > 80) {
signalQualityIcon.classList.add('icons-wifi-strength-4');
} else if (result[i].signal_quality > 60) {
signalQualityIcon.classList.add('icons-wifi-strength-3');
} else if (result[i].signal_quality > 40) {
signalQualityIcon.classList.add('icons-wifi-strength-2');
} else if (result[i].signal_quality > 20) {
signalQualityIcon.classList.add('icons-wifi-strength-1');
} else {
signalQualityIcon.classList.add('icons-wifi-strength-0');
}
let signalQualityContainer = document.createElement("span");
signalQualityContainer.dataset.tooltip = `${result[i].signal_quality}%`;
signalQualityContainer.appendChild(signalQualityIcon);
infoCell.appendChild(signalQualityContainer);
// auth
const authList = {
0: "Open",
1: "WEP",
2: "WPA",
3: "WPA2",
4: "WPA/WPA2",
5: "WPA/WPA2 Enterprise",
6: "WPA3",
7: "WPA2/WPA3",
8: "WAPI",
9: "OWE",
10: "WPA3 Enterprise"
};
let authIcon = document.createElement("i");
if (result[i].auth == 0) {
authIcon.classList.add('icons-unlocked');
} else {
authIcon.classList.add('icons-locked');
}
let authContainer = document.createElement("span");
authContainer.dataset.tooltip = (result[i].auth in authList) ? authList[result[i].auth] : "unknown";
authContainer.appendChild(authIcon);
infoCell.appendChild(authContainer);
}
if (button) {
button.innerHTML = defaultText;
button.removeAttribute('disabled');
button.removeAttribute('aria-busy');
}
};
const onFailed = async (response) => {
table.classList.remove('hidden');
if (button) {
button.innerHTML = defaultText;
button.removeAttribute('disabled');
button.removeAttribute('aria-busy');
}
};
let attempts = 6;
let attemptFn = async () => {
attempts--;
try {
let response = await fetch(url, {
cache: "no-cache",
credentials: "include"
});
if (response.status == 200) {
await onSuccess(response);
} else if (attempts <= 0) {
await onFailed(response);
} else {
setTimeout(attemptFn, 5000);
}
} catch (err) {
if (attempts <= 0) {
onFailed(err);
} else {
setTimeout(attemptFn, 10000);
}
}
};
attemptFn();
};
form.addEventListener('submit', onSubmitFn);
if (autorun) {
onSubmitFn();
}
}
const setBusy = (busySelector, contentSelector, value, parent = undefined) => { const setBusy = (busySelector, contentSelector, value, parent = undefined) => {
if (!value) { if (!value) {
hide(busySelector, parent); hide(busySelector, parent);
+21 -1
View File
@@ -111,11 +111,31 @@ button.failed {
border-color: var(--pico-form-element-invalid-border-color); border-color: var(--pico-form-element-invalid-border-color);
} }
#scan-dialog header {
margin-bottom: 0.25rem;
}
#scan-dialog thead {
position: sticky;
top: calc(-1 * var(--pico-block-spacing-vertical));
z-index: 1;
}
tr.network:hover { tr.network:hover {
--pico-background-color: var(--pico-primary-focus); --pico-background-color: var(--pico-primary-focus);
cursor: pointer; cursor: pointer;
} }
tr.network button {
all: unset;
outline: revert;
overflow-wrap: anywhere;
}
tr.network .bssid {
font-style: italic;
}
.primary { .primary {
border: 0.25rem solid var(--pico-form-element-invalid-border-color); border: 0.25rem solid var(--pico-form-element-invalid-border-color);
padding: 1rem; padding: 1rem;
@@ -332,4 +352,4 @@ tr.network:hover {
.icons-color-red { .icons-color-red {
color: var(--pico-form-element-invalid-active-border-color); color: var(--pico-form-element-invalid-active-border-color);
} }