Compare commits

..
12 Commits
Author SHA1 Message Date
Elvin Luff f9a814ca11 feat: Implement W5500 SPI ethernet support (#286)
* feat: implement feature gate & w5500 SPI ethernet

* feat: eth conn restart handling, wifi-ap connection type, BLE sensor
gate

* fix: bring eth down when disabled

* fix: disable WiFi scan when ethernet is active

* feat: refactor uplink types into separate classes

* fix: compare enum, not string

* chore: remove dead code

* fix: remove out of scope persistNow(), move w5500 to networksettings,
add base for future ethernet implementations

* fix: keep wifi armed while reconnecting, reset IP when moving from
static to DHCP, refactor wifi loop to use return

* fix: clear out connectionType string for enum
2026-11-11 08:31:36 +03:00
dependabot[bot] dfbd297f90 chore: bump cssnano-preset-advanced from 9.7.0 to 10.0.0 (#283)
Bumps [cssnano-preset-advanced](https://github.com/cssnano/cssnano) from 9.7.0 to 10.0.0.
- [Release notes](https://github.com/cssnano/cssnano/releases)
- [Commits](https://github.com/cssnano/cssnano/compare/cssnano@9.7.0...cssnano-preset-advanced@10.0.0)

---
updated-dependencies:
- dependency-name: cssnano-preset-advanced
  dependency-version: 10.0.0
  dependency-type: direct:development
  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-10-19 18:58:31 +03:00
dependabot[bot]andYurii 2623ac17dc chore: bump cssnano from 8.0.10 to 9.3.2 (#280)
Bumps [cssnano](https://github.com/cssnano/cssnano) from 8.0.10 to 9.3.2.
- [Release notes](https://github.com/cssnano/cssnano/releases)
- [Commits](https://github.com/cssnano/cssnano/compare/cssnano@8.0.10...cssnano@9.3.2)

---
updated-dependencies:
- dependency-name: cssnano
  dependency-version: 9.3.2
  dependency-type: direct:development
  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>
Co-authored-by: Yurii <34578544+Laxilef@users.noreply.github.com>
2026-10-12 03:47:54 +03:00
dependabot[bot] 29321d5c53 chore: bump cssnano-preset-advanced from 8.0.10 to 9.2.2 (#279)
Bumps [cssnano-preset-advanced](https://github.com/cssnano/cssnano) from 8.0.10 to 9.2.2.
- [Release notes](https://github.com/cssnano/cssnano/releases)
- [Commits](https://github.com/cssnano/cssnano/compare/cssnano@8.0.10...cssnano@9.2.2)

---
updated-dependencies:
- dependency-name: cssnano-preset-advanced
  dependency-version: 9.2.2
  dependency-type: direct:development
  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-10-12 03:46:15 +03:00
dependabot[bot] 1290e1d33c chore: bump actions/stale from 10 to 11 (#255)
Bumps [actions/stale](https://github.com/actions/stale) from 10 to 11.
- [Release notes](https://github.com/actions/stale/releases)
- [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/stale/compare/v10...v11)

---
updated-dependencies:
- dependency-name: actions/stale
  dependency-version: '11'
  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-10-12 03:45:59 +03:00
Yurii cbc32fd378 refactor: reworking the freeze protection algorithm (#242)
* refactor: impoved freeze protection

* refactor: reworked freeze protection
2026-05-11 14:26:14 +03:00
dependabot[bot] 9a3a171370 chore: bump cssnano-preset-advanced from 7.0.16 to 8.0.0 (#241)
Bumps [cssnano-preset-advanced](https://github.com/cssnano/cssnano) from 7.0.16 to 8.0.0.
- [Release notes](https://github.com/cssnano/cssnano/releases)
- [Commits](https://github.com/cssnano/cssnano/compare/cssnano-preset-advanced@7.0.16...cssnano-preset-advanced@8.0.0)

---
updated-dependencies:
- dependency-name: cssnano-preset-advanced
  dependency-version: 8.0.0
  dependency-type: direct:development
  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-05-08 07:26:41 +03:00
dependabot[bot] 7c40984298 chore: bump cssnano from 7.1.9 to 8.0.0 (#240)
Bumps [cssnano](https://github.com/cssnano/cssnano) from 7.1.9 to 8.0.0.
- [Release notes](https://github.com/cssnano/cssnano/releases)
- [Commits](https://github.com/cssnano/cssnano/compare/cssnano@7.1.9...cssnano@8.0.0)

---
updated-dependencies:
- dependency-name: cssnano
  dependency-version: 8.0.0
  dependency-type: direct:development
  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-05-08 07:24:24 +03:00
dependabot[bot] 4775d36f1b chore: bump gulp-html-minifier-terser from 7.1.0 to 8.0.0 (#224)
Bumps [gulp-html-minifier-terser](https://github.com/pioug/gulp-html-minifier-terser) from 7.1.0 to 8.0.0.
- [Release notes](https://github.com/pioug/gulp-html-minifier-terser/releases)
- [Commits](https://github.com/pioug/gulp-html-minifier-terser/compare/v7.1.0...v8.0.0)

---
updated-dependencies:
- dependency-name: gulp-html-minifier-terser
  dependency-version: 8.0.0
  dependency-type: direct:development
  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-02-16 23:36:56 +03:00
Yurii 1f895690db chore: bump milesburton/DallasTemperature from 4.0.5 to 4.0.6 #213
https://github.com/milesburton/Arduino-Temperature-Control-Library/pull/289
2026-02-13 14:10:08 +03:00
Yurii 13e8bedf3f fix: added await for lang.build() 2026-02-13 11:21:17 +03:00
Yurii 3a6bb03456 chore: fix build 2026-02-12 23:32:39 +03:00
40 changed files with 3732 additions and 1890 deletions

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v10
- uses: actions/stale@v11
with:
stale-issue-message: >
This issue is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 5 days.
+1 -1
View File
@@ -1,5 +1,4 @@
.pio
.dummy
.vscode
.PVS-Studio
build/*
@@ -11,4 +10,5 @@ package-lock.json
*.lock
sdkconfig.*
CMakeLists.txt
!sdkconfig.defaults
!.gitkeep
+113
View File
@@ -0,0 +1,113 @@
#pragma once
#include <NetworkUplink.h>
#include <NetworkWifi.h>
namespace NetworkUtils {
/**
* @brief Fallback AP: the setup network, raised when the station cannot carry the uplink
*/
class ApUplink : public NetworkUplink {
public:
ApUplink(UplinkContext* context, WifiUplink* wifi) : NetworkUplink(context), wifi(wifi) {}
void loop() override {
// the association carries the traffic again: retire the AP once it is stable and idle
if (this->wifi->isActive()) {
if (
this->isEnabled() && !this->hasClients()
&& millis() - this->wifi->getConnectedTime() >= this->retireDelay
) {
Log.sinfoln(FPSTR(L_NETWORK), F("Stop AP because STA connected"));
this->stop();
}
return;
}
if (this->isEnabled()) {
this->attempt.disarm();
return;
}
// a failed softAP() retries once the window runs out
if (this->attempt.isPending()) {
return;
}
this->start();
}
/**
* @brief The AP interface is up, whether or not anyone is on it
*
* A parked radio means the AP is not carrying anything, whatever the mode still says.
*/
bool isActive() override {
return this->isEnabled() && !this->wifi->isSuspended();
}
bool isEnabled() {
return (WiFi.getMode() & WIFI_AP) != 0;
}
bool hasClients() {
if (!this->isEnabled()) {
return false;
}
return WiFi.softAPgetStationNum() > 0;
}
void start() {
Log.sinfoln(
FPSTR(L_NETWORK),
this->wifi->hasCredentials()
? F("Disconnected for a long time, start AP")
: F("No STA credentials, start AP")
);
WiFi.mode(WIFI_AP_STA);
this->context->delayCallback(250);
if (!WiFi.softAP(this->context->apName, this->context->apPassword, this->context->apChannel)) {
this->attempt.arm(this->startTimeout);
}
}
void stop() {
WiFi.mode(WIFI_STA);
this->attempt.disarm();
}
IPAddress localIP() override {
return WiFi.softAPIP();
}
IPAddress subnetMask() override {
#ifdef ARDUINO_ARCH_ESP32
return WiFi.softAPSubnetMask();
#else
return IPAddress(255, 255, 255, 0);
#endif
}
IPAddress gatewayIP() override {
return WiFi.softAPIP();
}
IPAddress dnsIP() override {
return WiFi.softAPIP();
}
String macAddress() override {
return WiFi.softAPmacAddress();
}
protected:
const unsigned long retireDelay = 15000;
const unsigned long startTimeout = 5000;
WifiUplink* wifi;
};
}
+1
View File
@@ -1,3 +1,4 @@
#pragma once
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include "lwip/etharp.h"
+269
View File
@@ -0,0 +1,269 @@
#pragma once
#include <NetworkUplink.h>
#ifdef NETWORK_HAS_ETHERNET
#include <ETH.h>
#endif
namespace NetworkUtils {
/**
* @brief Ethernet uplink: the W5500 driver, its cable and its DHCP lease
*/
class EthernetUplink : public NetworkUplink {
public:
explicit EthernetUplink(UplinkContext* context) : NetworkUplink(context) {}
void loop() override {
#ifdef NETWORK_HAS_ETHERNET
if (this->restartFlag) {
this->restartFlag = false;
// The W5500 driver cannot be re-initialized in place: Arduino's ETH.end() leaves
// the SPI bus allocated, so a wiring change only takes effect after a restart.
if (this->started) {
Log.swarningln(FPSTR(L_NETWORK), F("Ethernet: settings changed, restart required to apply them"));
}
}
if (!this->enabled || !this->hasPins()) {
if (this->active || this->linkUp) {
this->active = false;
this->linkUp = false;
Log.sinfoln(FPSTR(L_NETWORK), F("Ethernet: disabled, handing the uplink back to WiFi"));
}
this->attempt.disarm();
return;
}
if (!this->started) {
if (this->startUnavailable) {
return;
}
Log.sinfoln(
FPSTR(L_NETWORK),
F("Ethernet: init W5500 (CS: %u, IRQ: %u, RST: %u, CLK: %u, MISO: %u, MOSI: %u)"),
this->cs,
this->irq,
this->rst,
this->clk,
this->miso,
this->mosi
);
if (!ETH.begin(ETH_PHY_W5500, 1, this->cs, this->irq, this->rst, SPI2_HOST, this->clk, this->miso, this->mosi, 12)) {
// A failed init leaves the SPI bus allocated, so retrying cannot succeed;
// wait for a restart instead of flapping.
this->startUnavailable = true;
this->attempt.disarm();
Log.serrorln(FPSTR(L_NETWORK), F("Ethernet: W5500 init failed, check the wiring and restart"));
return;
}
this->started = true;
this->running = true;
this->prevLinkCheck = 0;
this->attempt.arm(this->linkGrace);
if (!this->context->useDhcp) {
ETH.config(this->context->staticIp, this->context->staticGateway, this->context->staticSubnet, this->context->staticDns);
}
if (strlen(this->context->hostname) && UplinkContext::isHostnameValid(this->context->hostname)) {
ETH.setHostname(this->context->hostname);
}
return;
}
if (millis() - this->prevLinkCheck < this->linkCheckInterval) {
return;
}
this->prevLinkCheck = millis();
if (!ETH.linkUp()) {
if (this->linkUp) {
this->linkUp = false;
Log.sinfoln(FPSTR(L_NETWORK), F("Ethernet: cable disconnected"));
}
this->attempt.disarm();
if (this->active) {
this->active = false;
Log.sinfoln(FPSTR(L_NETWORK), F("Ethernet: link lost, falling back to WiFi"));
this->context->delayCallback(250);
}
return;
}
if (!this->linkUp) {
this->linkUp = true;
this->attempt.arm(this->leaseGrace);
Log.sinfoln(FPSTR(L_NETWORK), F("Ethernet: cable connected"));
}
if (!ETH.connected() || this->active) {
return;
}
this->active = true;
this->attempt.disarm();
Log.sinfoln(
FPSTR(L_NETWORK),
F("Ethernet: using ethernet instead of WiFi, IP: %s, link: %u Mbps, duplex: %u"),
ETH.localIP().toString().c_str(),
ETH.linkSpeed(),
ETH.fullDuplex() ? 1 : 0
);
#endif
}
/**
* @brief Ethernet carries the uplink: cable plugged in and DHCP lease obtained
*/
bool isActive() override {
#ifdef NETWORK_HAS_ETHERNET
if (!this->enabled || !this->started) {
return false;
}
return ETH.linkUp() && ETH.connected();
#else
return false;
#endif
}
/**
* @brief Enable/disable the interface, taking the driver in and out of the FSM
*/
void setEnabled(bool value) {
this->enabled = value;
#ifdef NETWORK_HAS_ETHERNET
// The driver stays installed: stop() only takes the link and the netif down, while the
// SPI bus, the MAC and the netif itself stay allocated, so start() resumes without a restart
if (this->started && ETH.handle() != nullptr && value != this->running) {
esp_err_t ret = value ? esp_eth_start(ETH.handle()) : esp_eth_stop(ETH.handle());
if (ret == ESP_OK) {
this->running = value;
} else {
Log.serrorln(FPSTR(L_NETWORK), F("Ethernet: driver %s failed"), value ? "start" : "stop");
}
}
#endif
}
/**
* @brief Configure the W5500 wiring. Use GPIO_IS_NOT_CONFIGURED to disable
*/
void setPins(uint8_t clk, uint8_t mosi, uint8_t miso, uint8_t cs, uint8_t irq, uint8_t rst) {
if (
clk != this->clk || mosi != this->mosi || miso != this->miso
|| cs != this->cs || irq != this->irq || rst != this->rst
) {
this->markSettingsChanged();
}
this->clk = clk;
this->mosi = mosi;
this->miso = miso;
this->cs = cs;
this->irq = irq;
this->rst = rst;
}
/**
* @brief A setting the driver reads changed: applying it needs a restart
*/
void markSettingsChanged() {
if (this->started) {
this->restartFlag = true;
}
}
bool hasPins() {
return this->clk != GPIO_IS_NOT_CONFIGURED
&& this->mosi != GPIO_IS_NOT_CONFIGURED
&& this->miso != GPIO_IS_NOT_CONFIGURED
&& this->cs != GPIO_IS_NOT_CONFIGURED
&& this->irq != GPIO_IS_NOT_CONFIGURED
&& this->rst != GPIO_IS_NOT_CONFIGURED;
}
IPAddress localIP() override {
#ifdef NETWORK_HAS_ETHERNET
return ETH.localIP();
#else
return IPAddress();
#endif
}
IPAddress subnetMask() override {
#ifdef NETWORK_HAS_ETHERNET
return ETH.subnetMask();
#else
return IPAddress();
#endif
}
IPAddress gatewayIP() override {
#ifdef NETWORK_HAS_ETHERNET
return ETH.gatewayIP();
#else
return IPAddress();
#endif
}
IPAddress dnsIP() override {
#ifdef NETWORK_HAS_ETHERNET
return ETH.dnsIP();
#else
return IPAddress();
#endif
}
String macAddress() override {
#ifdef NETWORK_HAS_ETHERNET
return ETH.macAddress();
#else
return String();
#endif
}
protected:
const unsigned long linkCheckInterval = 1000;
const unsigned long linkGrace = 5000;
const unsigned long leaseGrace = 20000;
bool enabled = false;
bool started = false;
bool running = false;
bool active = false;
bool linkUp = false;
bool restartFlag = false;
bool startUnavailable = false;
uint8_t clk = GPIO_IS_NOT_CONFIGURED;
uint8_t mosi = GPIO_IS_NOT_CONFIGURED;
uint8_t miso = GPIO_IS_NOT_CONFIGURED;
uint8_t cs = GPIO_IS_NOT_CONFIGURED;
uint8_t irq = GPIO_IS_NOT_CONFIGURED;
uint8_t rst = GPIO_IS_NOT_CONFIGURED;
unsigned long prevLinkCheck = 0;
};
}
+201 -363
View File
@@ -1,380 +1,258 @@
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include "lwip/etharp.h"
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <esp_wifi.h>
#endif
#pragma once
#include <NetworkAp.h>
#include <NetworkConnection.h>
#include <NetworkEthernet.h>
#include <NetworkUplink.h>
#include <NetworkWifi.h>
namespace NetworkUtils {
/**
* @brief Picks the uplink that carries the traffic and drives it
*
* The hierarchy is ethernet > WiFi > fallback AP: the first interface able to do it owns the
* pass, and every status getter reads that decision instead of re-testing the interfaces.
*/
class NetworkMgr {
public:
typedef std::function<void()> YieldCallback;
typedef std::function<void(unsigned int)> DelayCallback;
NetworkMgr() {
NetworkConnection::setup(this->useDhcp);
this->resetWifi();
NetworkMgr() : wifi(&this->context), ap(&this->context, &this->wifi), ethernet(&this->context) {
NetworkConnection::setup(this->context.useDhcp);
this->wifi.resetWifi();
}
NetworkMgr* setYieldCallback(YieldCallback callback = nullptr) {
this->yieldCallback = callback;
this->context.yieldCallback = callback;
return this;
}
NetworkMgr* setDelayCallback(DelayCallback callback = nullptr) {
this->delayCallback = callback;
this->context.delayCallback = callback;
return this;
}
NetworkMgr* setHostname(const char* value) {
this->hostname = value;
this->context.hostname = value;
return this;
}
NetworkMgr* setApCredentials(const char* ssid, const char* password = nullptr, uint8_t channel = 0) {
this->apName = ssid;
this->apPassword = password;
this->apChannel = channel;
this->context.apName = ssid;
this->context.apPassword = password;
this->context.apChannel = channel;
return this;
}
NetworkMgr* setStaCredentials(const char* ssid = nullptr, const char* password = nullptr, uint8_t channel = 0) {
this->staSsid = ssid;
this->staPassword = password;
this->staChannel = channel;
this->context.staSsid = ssid;
this->context.staPassword = password;
this->context.staChannel = channel;
return this;
}
NetworkMgr* setUseDhcp(bool value) {
this->useDhcp = value;
NetworkConnection::setup(this->useDhcp);
if (value != this->context.useDhcp) {
this->ethernet.markSettingsChanged();
}
this->context.useDhcp = value;
NetworkConnection::setup(this->context.useDhcp);
return this;
}
NetworkMgr* setStaticConfig(const char* ip, const char* gateway, const char* subnet, const char* dns) {
this->staticIp.fromString(ip);
this->staticGateway.fromString(gateway);
this->staticSubnet.fromString(subnet);
this->staticDns.fromString(dns);
IPAddress valueIp, valueGateway, valueSubnet, valueDns;
valueIp.fromString(ip);
valueGateway.fromString(gateway);
valueSubnet.fromString(subnet);
valueDns.fromString(dns);
if (
valueIp != this->context.staticIp || valueGateway != this->context.staticGateway
|| valueSubnet != this->context.staticSubnet || valueDns != this->context.staticDns
) {
this->ethernet.markSettingsChanged();
}
this->context.staticIp = valueIp;
this->context.staticGateway = valueGateway;
this->context.staticSubnet = valueSubnet;
this->context.staticDns = valueDns;
return this;
}
NetworkMgr* setStaticConfig(IPAddress& ip, IPAddress& gateway, IPAddress& subnet, IPAddress& dns) {
this->staticIp = ip;
this->staticGateway = gateway;
this->staticSubnet = subnet;
this->staticDns = dns;
if (
ip != this->context.staticIp || gateway != this->context.staticGateway
|| subnet != this->context.staticSubnet || dns != this->context.staticDns
) {
this->ethernet.markSettingsChanged();
}
this->context.staticIp = ip;
this->context.staticGateway = gateway;
this->context.staticSubnet = subnet;
this->context.staticDns = dns;
return this;
}
bool hasStaCredentials() {
return this->staSsid != nullptr;
/**
* @brief Enable/disable the ethernet interface (W5500 over SPI)
*/
NetworkMgr* setEthernet(bool enabled) {
this->ethernet.setEnabled(enabled);
return this;
}
/**
* @brief Configure W5500 wiring. Use GPIO_IS_NOT_CONFIGURED to disable
*/
NetworkMgr* setEthernetPins(uint8_t clk, uint8_t mosi, uint8_t miso, uint8_t cs, uint8_t irq, uint8_t rst) {
this->ethernet.setPins(clk, mosi, miso, cs, irq, rst);
return this;
}
/**
* @brief Uplinks in the order they are tried: ethernet, WiFi, fallback AP
*/
enum class Uplink : uint8_t { None = 0, Ap, Wifi, Ethernet };
/**
* @brief The uplink that currently carries traffic
*
* Always the first interface in the hierarchy that can do it, so every consumer reads the
* same decision instead of re-testing ethernet and overriding the WiFi answer.
*/
Uplink getUplink() {
if (this->ethernet.isActive()) {
return Uplink::Ethernet;
}
if (this->wifi.isActive()) {
return Uplink::Wifi;
}
if (this->ap.isActive()) {
return Uplink::Ap;
}
return Uplink::None;
}
bool isConnected() {
return this->isStaEnabled() && NetworkConnection::getStatus() == NetworkConnection::Status::CONNECTED;
return this->getUplink() >= Uplink::Wifi;
}
bool isConnecting() {
return this->isStaEnabled() && NetworkConnection::getStatus() == NetworkConnection::Status::CONNECTING;
/**
* @brief WiFi signal quality in percent, 0 when WiFi is not carrying the uplink
*/
uint8_t getSignalQuality() {
return this->getUplink() == Uplink::Wifi ? rssiToSignalQuality(this->wifi.rssi()) : 0;
}
bool isStaEnabled() {
return (WiFi.getMode() & WIFI_STA) != 0;
/**
* @return "ethernet", "wifi", "wifi-ap" or "none"
*/
const char* getConnectionType() {
return uplinkName(this->getUplink());
}
/**
* @brief Uplink token, already in locale-key shape
*/
static const char* uplinkName(Uplink uplink) {
switch (uplink) {
case Uplink::Ethernet:
return "ethernet";
case Uplink::Wifi:
return "wifi";
case Uplink::Ap:
return "wifi-ap";
default:
return "none";
}
}
bool isApEnabled() {
return (WiFi.getMode() & WIFI_AP) != 0;
}
bool hasApClients() {
if (!this->isApEnabled()) {
return false;
}
return WiFi.softAPgetStationNum() > 0;
return this->ap.isEnabled();
}
short int getRssi() {
return WiFi.RSSI();
return this->station()->rssi();
}
IPAddress getApIp() {
return WiFi.softAPIP();
return this->ap.localIP();
}
IPAddress getStaIp() {
return WiFi.localIP();
return this->station()->localIP();
}
IPAddress getStaSubnet() {
return WiFi.subnetMask();
return this->station()->subnetMask();
}
IPAddress getStaGateway() {
return WiFi.gatewayIP();
return this->station()->gatewayIP();
}
IPAddress getStaDns() {
return WiFi.dnsIP();
return this->station()->dnsIP();
}
String getStaMac() {
return WiFi.macAddress();
return this->station()->macAddress();
}
const char* getStaSsid() {
return this->staSsid;
}
const char* getStaPassword() {
return this->staPassword;
return this->context.staSsid;
}
uint8_t getStaChannel() {
return this->staChannel;
}
bool resetWifi() {
// set policy manual for work 13 ch
{
#ifdef ARDUINO_ARCH_ESP8266
wifi_country_t country = {"JP", 1, 14, WIFI_COUNTRY_POLICY_MANUAL};
wifi_set_country(&country);
#elif defined(ARDUINO_ARCH_ESP32)
const wifi_country_t country = {"JP", 1, 14, CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER, WIFI_COUNTRY_POLICY_MANUAL};
esp_wifi_set_country(&country);
#endif
}
WiFi.persistent(false);
#if !defined(ESP_ARDUINO_VERSION_MAJOR) || ESP_ARDUINO_VERSION_MAJOR < 3
WiFi.setAutoConnect(false);
#endif
WiFi.setAutoReconnect(false);
#ifdef ARDUINO_ARCH_ESP8266
WiFi.setSleepMode(WIFI_NONE_SLEEP);
#elif defined(ARDUINO_ARCH_ESP32)
WiFi.setSleep(USE_BLE ? WIFI_PS_MIN_MODEM : WIFI_PS_NONE);
#endif
WiFi.softAPdisconnect();
#ifdef ARDUINO_ARCH_ESP8266
/*if (wifi_softap_dhcps_status() == DHCP_STARTED) {
wifi_softap_dhcps_stop();
}*/
#endif
WiFi.disconnect(false, true);
#ifdef ARDUINO_ARCH_ESP8266
/*if (wifi_station_dhcpc_status() == DHCP_STARTED) {
wifi_station_dhcpc_stop();
}*/
wifi_station_dhcpc_set_maxtry(5);
#endif
#if defined(ARDUINO_ARCH_ESP32) && ESP_ARDUINO_VERSION_MAJOR < 3
// Nothing. Because memory leaks when turn off WiFi on ESP32 SDK < 3.0.0
return true;
#else
return WiFi.mode(WIFI_OFF);
#endif
return this->context.staChannel;
}
void reconnect() {
this->reconnectFlag = true;
}
bool connect(bool force = false, unsigned int timeout = 1000u) {
if (this->isConnected() && !force) {
return true;
}
if (force && !this->isApEnabled()) {
this->resetWifi();
NetworkConnection::reset();
} else {
/*#ifdef ARDUINO_ARCH_ESP8266
if (wifi_station_dhcpc_status() == DHCP_STARTED) {
wifi_station_dhcpc_stop();
}
#endif*/
this->disconnect();
}
if (!this->hasStaCredentials()) {
return false;
}
this->delayCallback(250);
#ifdef ARDUINO_ARCH_ESP32
if (this->setWifiHostname(this->hostname)) {
Log.straceln(FPSTR(L_NETWORK), F("Set hostname '%s': success"), this->hostname);
} else {
Log.serrorln(FPSTR(L_NETWORK), F("Set hostname '%s': fail"), this->hostname);
}
#endif
if (!WiFi.mode((WiFiMode_t)(WiFi.getMode() | WIFI_STA))) {
return false;
}
this->delayCallback(250);
#ifdef ARDUINO_ARCH_ESP8266
if (this->setWifiHostname(this->hostname)) {
Log.straceln(FPSTR(L_NETWORK), F("Set hostname '%s': success"), this->hostname);
} else {
Log.serrorln(FPSTR(L_NETWORK), F("Set hostname '%s': fail"), this->hostname);
}
this->delayCallback(250);
#endif
#ifdef ARDUINO_ARCH_ESP32
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
#endif
if (!this->useDhcp) {
WiFi.begin(this->staSsid, this->staPassword, this->staChannel, nullptr, false);
WiFi.config(this->staticIp, this->staticGateway, this->staticSubnet, this->staticDns);
WiFi.reconnect();
} else {
WiFi.begin(this->staSsid, this->staPassword, this->staChannel, nullptr, true);
}
unsigned long beginConnectionTime = millis();
while (millis() - beginConnectionTime < timeout) {
this->delayCallback(100);
NetworkConnection::Status status = NetworkConnection::getStatus();
if (status != NetworkConnection::Status::CONNECTING && status != NetworkConnection::Status::NONE) {
return status == NetworkConnection::Status::CONNECTED;
}
}
return false;
}
void disconnect() {
#ifdef ARDUINO_ARCH_ESP32
WiFi.disconnectAsync(false, true);
const unsigned long start = millis();
while (WiFi.isConnected() && (millis() - start) < 5000) {
this->delayCallback(100);
}
#else
WiFi.disconnect(false, true);
#endif
this->wifi.reconnect();
}
void loop() {
if (this->reconnectFlag) {
this->delayCallback(5000);
// The top of the hierarchy polls every pass so it can take the uplink whenever it can
this->ethernet.loop();
Log.sinfoln(FPSTR(L_NETWORK), F("Reconnecting..."));
this->reconnectFlag = false;
this->disconnect();
NetworkConnection::reset();
this->delayCallback(1000);
this->trackUplink();
this->updateWifiRadio();
} else if (this->isConnected() && !this->hasStaCredentials()) {
Log.sinfoln(FPSTR(L_NETWORK), F("Reset"));
this->resetWifi();
NetworkConnection::reset();
this->delayCallback(1000);
} else if (this->isConnected()) {
if (!this->connected) {
this->connectedTime = millis();
this->connected = true;
Log.sinfoln(
FPSTR(L_NETWORK),
F("Connected, downtime: %lu s., IP: %s, RSSI: %hhd"),
(millis() - this->disconnectedTime) / 1000,
WiFi.localIP().toString().c_str(),
WiFi.RSSI()
);
}
if (this->isApEnabled() && millis() - this->connectedTime > this->reconnectInterval && !this->hasApClients()) {
Log.sinfoln(FPSTR(L_NETWORK), F("Stop AP because STA connected"));
WiFi.mode(WIFI_STA);
return;
}
#ifdef ARDUINO_ARCH_ESP8266
if (millis() - this->prevArpGratuitous > 60000) {
this->stationKeepAliveNow();
this->prevArpGratuitous = millis();
}
#endif
} else {
if (this->connected) {
this->disconnectedTime = millis();
this->connected = false;
Log.sinfoln(
FPSTR(L_NETWORK),
F("Disconnected, reason: %d, uptime: %lu s."),
NetworkConnection::getDisconnectReason(),
(millis() - this->connectedTime) / 1000
);
}
if (!this->hasStaCredentials() && !this->isApEnabled()) {
Log.sinfoln(FPSTR(L_NETWORK), F("No STA credentials, start AP"));
WiFi.mode(WIFI_AP_STA);
this->delayCallback(250);
WiFi.softAP(this->apName, this->apPassword, this->apChannel);
} else if (!this->isApEnabled() && millis() - this->disconnectedTime > this->failedConnectTimeout) {
Log.sinfoln(FPSTR(L_NETWORK), F("Disconnected for a long time, start AP"));
WiFi.mode(WIFI_AP_STA);
this->delayCallback(250);
WiFi.softAP(this->apName, this->apPassword, this->apChannel);
} else if (this->isConnecting() && millis() - this->prevReconnectingTime > this->resetConnectionTimeout) {
Log.swarningln(FPSTR(L_NETWORK), F("Connection timeout, reset wifi..."));
this->resetWifi();
NetworkConnection::reset();
this->delayCallback(250);
} else if (!this->isConnecting() && this->hasStaCredentials() && (!this->prevReconnectingTime || millis() - this->prevReconnectingTime > this->reconnectInterval)) {
Log.sinfoln(FPSTR(L_NETWORK), F("Try connect..."));
NetworkConnection::reset();
if (!this->connect(true, this->connectionTimeout)) {
Log.straceln(FPSTR(L_NETWORK), F("Connection failed. Status: %d, reason: %d, raw reason: %d"), NetworkConnection::getStatus(), NetworkConnection::getDisconnectReason(), NetworkConnection::rawDisconnectReason);
}
this->prevReconnectingTime = millis();
}
if (this->getUplink() == Uplink::Ethernet) {
return;
}
// a pending ethernet attempt holds the hierarchy: nothing below it starts until it resolves
if (this->ethernet.isPending() && !this->wifi.isActive() && !this->ap.isActive()) {
return;
}
this->wifi.loop();
// the ladder only reaches the AP once the station is out of the running
if (!this->wifi.isActive() && this->wifi.isPending()) {
return;
}
this->ap.loop();
}
static uint8_t rssiToSignalQuality(short int rssi) {
@@ -382,95 +260,55 @@ namespace NetworkUtils {
}
protected:
const unsigned int reconnectInterval = 15000;
const unsigned int failedConnectTimeout = 185000;
const unsigned int connectionTimeout = 10000;
const unsigned int resetConnectionTimeout = 90000;
UplinkContext context;
WifiUplink wifi;
ApUplink ap;
EthernetUplink ethernet;
YieldCallback yieldCallback = []() {
::yield();
};
DelayCallback delayCallback = [](unsigned int time) {
::delay(time);
};
Uplink uplink = Uplink::None;
const char* hostname = "esp";
const char* apName = "ESP";
const char* apPassword = nullptr;
uint8_t apChannel = 1;
const char* staSsid = nullptr;
const char* staPassword = nullptr;
uint8_t staChannel = 0;
bool useDhcp = true;
IPAddress staticIp;
IPAddress staticGateway;
IPAddress staticSubnet;
IPAddress staticDns;
bool connected = false;
bool reconnectFlag = false;
unsigned long prevArpGratuitous = 0;
unsigned long prevReconnectingTime = 0;
unsigned long connectedTime = 0;
unsigned long disconnectedTime = 0;
bool setWifiHostname(const char* hostname) {
if (!this->isHostnameValid(hostname)) {
return false;
}
if (strcmp(WiFi.getHostname(), hostname) == 0) {
return true;
}
return WiFi.setHostname(hostname);
}
#ifdef ARDUINO_ARCH_ESP8266
/**
* @brief
* https://github.com/arendst/Tasmota/blob/e6515883f0ee5451931b6280ff847b117de5a231/tasmota/tasmota_support/support_wifi.ino#L1196
* @brief The interface holding the station address: the wired one while it carries the
* uplink, the station otherwise
*/
static void stationKeepAliveNow(void) {
for (netif* interface = netif_list; interface != nullptr; interface = interface->next) {
if (
(interface->flags & NETIF_FLAG_LINK_UP)
&& (interface->flags & NETIF_FLAG_UP)
&& interface->num == STATION_IF
&& (!ip4_addr_isany_val(*netif_ip4_addr(interface)))
) {
etharp_gratuitous(interface);
break;
}
NetworkUplink* station() {
if (this->getUplink() == Uplink::Ethernet) {
return &this->ethernet;
}
return &this->wifi;
}
#endif
/**
* @brief check RFC compliance
* @brief Notice an uplink change so the hierarchy is walked from the top again
*/
void trackUplink() {
const Uplink current = this->getUplink();
if (current == this->uplink) {
return;
}
Log.sinfoln(FPSTR(L_NETWORK), F("Uplink: %s -> %s"), uplinkName(this->uplink), uplinkName(current));
this->uplink = current;
}
/**
* @brief Keep the WiFi radio in step with the uplink
*
* @param value
* @return true
* @return false
* WiFi is only in service while it carries the traffic. The AP is for first configuration:
* once a cable carries the uplink the radio goes off, and if that uplink never comes up the
* ladder falls back to the AP again on its own.
*/
static bool isHostnameValid(const char* value) {
size_t len = strlen(value);
if (len > 24) {
return false;
} else if (value[len - 1] == '-') {
return false;
void updateWifiRadio() {
if (this->ethernet.isActive()) {
this->wifi.suspend();
return;
}
for (size_t i = 0; i < len; i++) {
if (!isalnum(value[i]) && value[i] != '-') {
return false;
}
}
return true;
this->wifi.resume();
}
};
}
}
+143
View File
@@ -0,0 +1,143 @@
#pragma once
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include "lwip/etharp.h"
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <esp_wifi.h>
#endif
// W5500 support needs both the ESP32 core (for ETH.h) and the per-env USE_ETHERNET flag.
// USE_ETHERNET defaults to false in defines.h, so this must be a value test, not #ifdef.
#if USE_ETHERNET && defined(ARDUINO_ARCH_ESP32)
#define NETWORK_HAS_ETHERNET
#endif
namespace NetworkUtils {
typedef std::function<void()> YieldCallback;
typedef std::function<void(unsigned int)> DelayCallback;
/**
* @brief Settings and callbacks every uplink reads
*/
struct UplinkContext {
const char* hostname = "esp";
const char* staSsid = nullptr;
const char* staPassword = nullptr;
uint8_t staChannel = 0;
const char* apName = "ESP";
const char* apPassword = nullptr;
uint8_t apChannel = 1;
bool useDhcp = true;
IPAddress staticIp;
IPAddress staticGateway;
IPAddress staticSubnet;
IPAddress staticDns;
YieldCallback yieldCallback = []() {
::yield();
};
DelayCallback delayCallback = [](unsigned int time) {
::delay(time);
};
/**
* @brief check RFC compliance
*
* @param value
* @return true
* @return false
*/
static bool isHostnameValid(const char* value) {
size_t len = strlen(value);
if (len > 24) {
return false;
} else if (value[len - 1] == '-') {
return false;
}
for (size_t i = 0; i < len; i++) {
if (!isalnum(value[i]) && value[i] != '-') {
return false;
}
}
return true;
}
};
/**
* @brief How long an uplink may still take the pass
*
* Armed when the uplink starts trying, disarmed when it resolves either way. A window that has
* run out means the uplink gave up, which lets the class below it take over.
*/
class UplinkAttempt {
public:
void arm(unsigned long window) {
this->start = millis() ? millis() : 1;
this->window = window;
}
void disarm() {
this->start = 0;
this->window = 0;
}
bool isArmed() const {
return this->window > 0;
}
bool isPending() const {
return this->window > 0 && (millis() - this->start) < this->window;
}
protected:
unsigned long start = 0;
unsigned long window = 0;
};
/**
* @brief One interface that is able to carry the uplink
*/
class NetworkUplink {
public:
explicit NetworkUplink(UplinkContext* context) : context(context) {}
virtual ~NetworkUplink() {}
/**
* @brief Run one pass of this interface's state machine
*/
virtual void loop() = 0;
/**
* @brief The interface is able to carry traffic right now
*/
virtual bool isActive() = 0;
/**
* @brief The interface may still become active, so nothing below it should start
*/
virtual bool isPending() {
return !this->isActive() && this->attempt.isPending();
}
virtual IPAddress localIP() = 0;
virtual IPAddress subnetMask() = 0;
virtual IPAddress gatewayIP() = 0;
virtual IPAddress dnsIP() = 0;
virtual String macAddress() = 0;
virtual short int rssi() {
return 0;
}
protected:
UplinkContext* context;
UplinkAttempt attempt;
};
}
+431
View File
@@ -0,0 +1,431 @@
#pragma once
#include <NetworkConnection.h>
#include <NetworkUplink.h>
namespace NetworkUtils {
/**
* @brief WiFi uplink: the station association, its radio, and the fallback AP
*/
class WifiUplink : public NetworkUplink {
public:
explicit WifiUplink(UplinkContext* context) : NetworkUplink(context) {}
void loop() override {
if (this->reconnectFlag) {
this->context->delayCallback(5000);
Log.sinfoln(FPSTR(L_NETWORK), F("Reconnecting..."));
this->reconnectFlag = false;
this->disconnect();
NetworkConnection::reset();
this->context->delayCallback(1000);
return;
}
if (this->isAssociated() && !this->hasCredentials()) {
Log.sinfoln(FPSTR(L_NETWORK), F("Reset"));
this->resetWifi();
NetworkConnection::reset();
this->context->delayCallback(1000);
return;
}
if (this->isAssociated()) {
this->attempt.disarm();
if (!this->connected) {
this->connectedTime = millis();
this->connected = true;
Log.sinfoln(
FPSTR(L_NETWORK),
F("Connected, downtime: %lu s., IP: %s, RSSI: %hhd"),
(millis() - this->disconnectedTime) / 1000,
WiFi.localIP().toString().c_str(),
WiFi.RSSI()
);
}
#ifdef ARDUINO_ARCH_ESP8266
if (millis() - this->prevArpGratuitous > 60000) {
this->stationKeepAliveNow();
this->prevArpGratuitous = millis();
}
#endif
return;
}
// the association is down: track the downtime and keep asking for the network
if (this->connected) {
this->disconnectedTime = millis();
this->connected = false;
this->attempt.arm(this->failedConnectTimeout);
Log.sinfoln(
FPSTR(L_NETWORK),
F("Disconnected, reason: %d, uptime: %lu s."),
NetworkConnection::getDisconnectReason(),
(millis() - this->connectedTime) / 1000
);
}
if (!this->hasCredentials()) {
this->attempt.disarm();
return;
}
if (!this->attempt.isArmed()) {
this->attempt.arm(this->failedConnectTimeout);
}
if (this->isConnecting() && millis() - this->prevReconnectingTime > this->resetConnectionTimeout) {
Log.swarningln(FPSTR(L_NETWORK), F("Connection timeout, reset wifi..."));
this->resetWifi();
NetworkConnection::reset();
this->context->delayCallback(250);
return;
}
if (!this->isConnecting() && (!this->prevReconnectingTime || millis() - this->prevReconnectingTime > this->reconnectInterval)) {
Log.sinfoln(FPSTR(L_NETWORK), F("Try connect..."));
NetworkConnection::reset();
if (!this->connect(true, this->connectionTimeout)) {
Log.straceln(FPSTR(L_NETWORK), F("Connection failed. Status: %d, reason: %d, raw reason: %d"), NetworkConnection::getStatus(), NetworkConnection::getDisconnectReason(), NetworkConnection::rawDisconnectReason);
}
this->prevReconnectingTime = millis();
}
}
/**
* @brief WiFi carries the uplink: radio running and associated
*/
bool isActive() override {
return !this->suspended && this->isAssociated();
}
bool isAssociated() {
return this->isStaEnabled() && NetworkConnection::getStatus() == NetworkConnection::Status::CONNECTED;
}
bool isConnecting() {
return this->isStaEnabled() && NetworkConnection::getStatus() == NetworkConnection::Status::CONNECTING;
}
bool isStaEnabled() {
return (WiFi.getMode() & WIFI_STA) != 0;
}
bool isApEnabled() {
return (WiFi.getMode() & WIFI_AP) != 0;
}
/**
* @brief When the association first came up, for the fallback AP's retirement delay
*/
unsigned long getConnectedTime() {
return this->connectedTime;
}
/**
* @brief Stop the radio while another uplink carries the traffic
*
* esp_wifi_stop() parks the radio without tearing the driver and its netifs down.
* WiFi.mode(WIFI_OFF) does the same job but also deinitialises, which panicked when it
* was called from this task with lwIP live — keep the driver allocated.
*/
void suspend() {
#ifdef ARDUINO_ARCH_ESP32
if (this->suspended) {
return;
}
if (WiFi.getMode() == WIFI_MODE_NULL) {
return;
}
// a scan holds the radio: parking it mid-scan leaves the driver half torn down
if (WiFi.scanComplete() == WIFI_SCAN_RUNNING) {
return;
}
Log.sinfoln(FPSTR(L_NETWORK), F("Ethernet: uplink active, switching the WiFi radio off"));
esp_wifi_stop();
this->suspended = true;
#endif
}
/**
* @brief Bring the radio back when no other uplink carries the traffic
*/
void resume() {
#ifdef ARDUINO_ARCH_ESP32
if (!this->suspended) {
return;
}
this->suspended = false;
Log.sinfoln(FPSTR(L_NETWORK), F("Ethernet: uplink lost, switching the WiFi radio back on"));
esp_wifi_start();
this->connected = false;
this->disconnectedTime = millis();
this->prevReconnectingTime = 0;
this->attempt.arm(this->failedConnectTimeout);
NetworkConnection::reset();
if (this->hasCredentials()) {
WiFi.begin(this->context->staSsid, this->context->staPassword);
Log.sinfoln(FPSTR(L_NETWORK), F("Ethernet: reconnecting to WiFi \"%s\""), this->context->staSsid);
}
#endif
}
bool isSuspended() {
return this->suspended;
}
bool resetWifi() {
// set policy manual for work 13 ch
{
#ifdef ARDUINO_ARCH_ESP8266
wifi_country_t country = {"JP", 1, 14, WIFI_COUNTRY_POLICY_MANUAL};
wifi_set_country(&country);
#elif defined(ARDUINO_ARCH_ESP32)
const wifi_country_t country = {"JP", 1, 14, CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER, WIFI_COUNTRY_POLICY_MANUAL};
esp_wifi_set_country(&country);
#endif
}
WiFi.persistent(false);
#if !defined(ESP_ARDUINO_VERSION_MAJOR) || ESP_ARDUINO_VERSION_MAJOR < 3
WiFi.setAutoConnect(false);
#endif
WiFi.setAutoReconnect(false);
#ifdef ARDUINO_ARCH_ESP8266
WiFi.setSleepMode(WIFI_NONE_SLEEP);
#elif defined(ARDUINO_ARCH_ESP32)
WiFi.setSleep(USE_BLE ? WIFI_PS_MIN_MODEM : WIFI_PS_NONE);
#endif
WiFi.softAPdisconnect();
#ifdef ARDUINO_ARCH_ESP8266
/*if (wifi_softap_dhcps_status() == DHCP_STARTED) {
wifi_softap_dhcps_stop();
}*/
#endif
WiFi.disconnect(false, true);
#ifdef ARDUINO_ARCH_ESP8266
/*if (wifi_station_dhcpc_status() == DHCP_STARTED) {
wifi_station_dhcpc_stop();
}*/
wifi_station_dhcpc_set_maxtry(5);
#endif
#if defined(ARDUINO_ARCH_ESP32) && ESP_ARDUINO_VERSION_MAJOR < 3
// Nothing. Because memory leaks when turn off WiFi on ESP32 SDK < 3.0.0
return true;
#else
return WiFi.mode(WIFI_OFF);
#endif
}
/**
* @brief Ask for a fresh connect
*
* The attempt window is armed here so the ladder keeps the fallback AP out of the way while
* the station works on this reconnect; it expires like any other failed attempt.
*/
void reconnect() {
this->attempt.arm(this->failedConnectTimeout);
this->reconnectFlag = true;
}
bool connect(bool force = false, unsigned int timeout = 1000u) {
if (this->isAssociated() && !force) {
return true;
}
if (force && !this->isApEnabled()) {
this->resetWifi();
NetworkConnection::reset();
} else {
/*#ifdef ARDUINO_ARCH_ESP8266
if (wifi_station_dhcpc_status() == DHCP_STARTED) {
wifi_station_dhcpc_stop();
}
#endif*/
this->disconnect();
}
if (!this->hasCredentials()) {
return false;
}
this->context->delayCallback(250);
#ifdef ARDUINO_ARCH_ESP32
if (this->setHostname(this->context->hostname)) {
Log.straceln(FPSTR(L_NETWORK), F("Set hostname '%s': success"), this->context->hostname);
} else {
Log.serrorln(FPSTR(L_NETWORK), F("Set hostname '%s': fail"), this->context->hostname);
}
#endif
if (!WiFi.mode((WiFiMode_t)(WiFi.getMode() | WIFI_STA))) {
return false;
}
this->context->delayCallback(250);
#ifdef ARDUINO_ARCH_ESP8266
if (this->setHostname(this->context->hostname)) {
Log.straceln(FPSTR(L_NETWORK), F("Set hostname '%s': success"), this->context->hostname);
} else {
Log.serrorln(FPSTR(L_NETWORK), F("Set hostname '%s': fail"), this->context->hostname);
}
this->context->delayCallback(250);
#endif
#ifdef ARDUINO_ARCH_ESP32
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
#endif
if (!this->context->useDhcp) {
WiFi.begin(this->context->staSsid, this->context->staPassword, this->context->staChannel, nullptr, false);
WiFi.config(this->context->staticIp, this->context->staticGateway, this->context->staticSubnet, this->context->staticDns);
WiFi.reconnect();
} else {
#ifdef ARDUINO_ARCH_ESP32
// the interface keeps a static address from an earlier association, so the addressing has
// to be reset before the station reconnects or the switch back to DHCP never takes effect
const IPAddress noIp(0, 0, 0, 0);
WiFi.config(noIp, noIp, noIp);
#endif
WiFi.begin(this->context->staSsid, this->context->staPassword, this->context->staChannel, nullptr, true);
}
unsigned long beginConnectionTime = millis();
while (millis() - beginConnectionTime < timeout) {
this->context->delayCallback(100);
NetworkConnection::Status status = NetworkConnection::getStatus();
if (status != NetworkConnection::Status::CONNECTING && status != NetworkConnection::Status::NONE) {
return status == NetworkConnection::Status::CONNECTED;
}
}
return false;
}
void disconnect() {
#ifdef ARDUINO_ARCH_ESP32
WiFi.disconnectAsync(false, true);
const unsigned long start = millis();
while (WiFi.isConnected() && (millis() - start) < 5000) {
this->context->delayCallback(100);
}
#else
WiFi.disconnect(false, true);
#endif
}
bool setHostname(const char* hostname) {
if (!UplinkContext::isHostnameValid(hostname)) {
return false;
}
if (strcmp(WiFi.getHostname(), hostname) == 0) {
return true;
}
return WiFi.setHostname(hostname);
}
bool hasCredentials() {
return this->context->staSsid != nullptr;
}
IPAddress localIP() override {
return WiFi.localIP();
}
IPAddress subnetMask() override {
return WiFi.subnetMask();
}
IPAddress gatewayIP() override {
return WiFi.gatewayIP();
}
IPAddress dnsIP() override {
return WiFi.dnsIP();
}
String macAddress() override {
return WiFi.macAddress();
}
short int rssi() override {
return WiFi.RSSI();
}
protected:
const unsigned int reconnectInterval = 15000;
const unsigned int failedConnectTimeout = 185000;
const unsigned int connectionTimeout = 10000;
const unsigned int resetConnectionTimeout = 90000;
bool connected = false;
bool reconnectFlag = false;
bool suspended = false;
unsigned long prevArpGratuitous = 0;
unsigned long prevReconnectingTime = 0;
unsigned long connectedTime = 0;
unsigned long disconnectedTime = 0;
#ifdef ARDUINO_ARCH_ESP8266
/**
* @brief
* https://github.com/arendst/Tasmota/blob/e6515883f0ee5451931b6280ff847b117de5a231/tasmota/tasmota_support/support_wifi.ino#L1196
*/
static void stationKeepAliveNow(void) {
for (netif* interface = netif_list; interface != nullptr; interface = interface->next) {
if (
(interface->flags & NETIF_FLAG_LINK_UP)
&& (interface->flags & NETIF_FLAG_UP)
&& interface->num == STATION_IF
&& (!ip4_addr_isany_val(*netif_ip4_addr(interface)))
) {
etharp_gratuitous(interface);
break;
}
}
}
#endif
};
}
+103 -95
View File
@@ -1,6 +1,6 @@
#include <Arduino.h>
class UpgradeHandler : public AsyncWebHandler {
class UpgradeHandler : public RequestHandler {
public:
enum class UpgradeType {
FIRMWARE = 0,
@@ -12,7 +12,7 @@ public:
NO_FILE,
SUCCESS,
PROHIBITED,
SIZE_MISMATCH,
ABORTED,
ERROR_ON_START,
ERROR_ON_WRITE,
ERROR_ON_FINISH
@@ -22,21 +22,27 @@ public:
UpgradeType type;
UpgradeStatus status;
String error;
size_t progress = 0;
size_t size = 0;
} UpgradeResult;
typedef std::function<bool(AsyncWebServerRequest *request, UpgradeType)> BeforeUpgradeCallback;
typedef std::function<void(AsyncWebServerRequest *request, const UpgradeResult&, const UpgradeResult&)> AfterUpgradeCallback;
typedef std::function<bool(HTTPMethod, const String&)> CanHandleCallback;
typedef std::function<bool(const String&)> CanUploadCallback;
typedef std::function<bool(UpgradeType)> BeforeUpgradeCallback;
typedef std::function<void(const UpgradeResult&, const UpgradeResult&)> AfterUpgradeCallback;
UpgradeHandler(AsyncURIMatcher uri) : uri(uri) {}
UpgradeHandler(const char* uri) {
this->uri = uri;
}
bool canHandle(AsyncWebServerRequest *request) const override final {
if (!request->isHTTP()) {
return false;
}
return this->uri.matches(request);
UpgradeHandler* setCanHandleCallback(CanHandleCallback callback = nullptr) {
this->canHandleCallback = callback;
return this;
}
UpgradeHandler* setCanUploadCallback(CanUploadCallback callback = nullptr) {
this->canUploadCallback = callback;
return this;
}
UpgradeHandler* setBeforeUpgradeCallback(BeforeUpgradeCallback callback = nullptr) {
@@ -51,9 +57,29 @@ public:
return this;
}
void handleRequest(AsyncWebServerRequest *request) override final {
#if defined(ARDUINO_ARCH_ESP32)
bool canHandle(WebServer &server, HTTPMethod method, const String &uri) override {
return this->canHandle(method, uri);
}
#endif
bool canHandle(HTTPMethod method, const String& uri) override {
return method == HTTP_POST && uri.equals(this->uri) && (!this->canHandleCallback || this->canHandleCallback(method, uri));
}
#if defined(ARDUINO_ARCH_ESP32)
bool canUpload(WebServer &server, const String &uri) override {
return this->canUpload(uri);
}
#endif
bool canUpload(const String& uri) override {
return uri.equals(this->uri) && (!this->canUploadCallback || this->canUploadCallback(uri));
}
bool handle(WebServer& server, HTTPMethod method, const String& uri) override {
if (this->afterUpgradeCallback) {
this->afterUpgradeCallback(request, this->firmwareResult, this->filesystemResult);
this->afterUpgradeCallback(this->firmwareResult, this->filesystemResult);
}
this->firmwareResult.status = UpgradeStatus::NONE;
@@ -61,147 +87,129 @@ public:
this->filesystemResult.status = UpgradeStatus::NONE;
this->filesystemResult.error.clear();
return true;
}
void handleUpload(AsyncWebServerRequest *request, const String &fileName, size_t index, uint8_t *data, size_t dataLength, bool isFinal) override final {
UpgradeResult* result = nullptr;
if (!request->hasParam(asyncsrv::T_name, true, true)) {
// Missing content-disposition 'name' parameter
return;
}
const auto& pName = request->getParam(asyncsrv::T_name, true, true)->value();
if (pName.equals("fw")) {
void upload(WebServer& server, const String& uri, HTTPUpload& upload) override {
UpgradeResult* result;
if (upload.name.equals(F("firmware"))) {
result = &this->firmwareResult;
if (!index) {
result->progress = 0;
result->size = request->hasParam("fw_size", true)
? request->getParam("fw_size", true)->value().toInt()
: 0;
}
} else if (pName.equals("fs")) {
} else if (upload.name.equals(F("filesystem"))) {
result = &this->filesystemResult;
if (!index) {
result->progress = 0;
result->size = request->hasParam("fs_size", true)
? request->getParam("fs_size", true)->value().toInt()
: 0;
}
} else {
// Unknown parameter name
return;
}
// check result status
if (result->status != UpgradeStatus::NONE) {
return;
}
if (this->beforeUpgradeCallback && !this->beforeUpgradeCallback(request, result->type)) {
if (this->beforeUpgradeCallback && !this->beforeUpgradeCallback(result->type)) {
result->status = UpgradeStatus::PROHIBITED;
return;
}
if (!fileName.length()) {
if (!upload.filename.length()) {
result->status = UpgradeStatus::NO_FILE;
return;
}
if (!index) {
if (upload.status == UPLOAD_FILE_START) {
// reset
if (Update.isRunning()) {
Update.end(false);
Update.clearError();
}
// try begin
bool begin = false;
#ifdef ARDUINO_ARCH_ESP8266
Update.runAsync(true);
if (result->type == UpgradeType::FIRMWARE) {
begin = Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000, U_FLASH);
} else if (result->type == UpgradeType::FILESYSTEM) {
close_all_fs();
begin = Update.begin((size_t)FS_end - (size_t)FS_start, U_FS);
}
#elif defined(ARDUINO_ARCH_ESP32)
if (result->type == UpgradeType::FIRMWARE) {
begin = Update.begin(UPDATE_SIZE_UNKNOWN, U_FLASH);
} else if (result->type == UpgradeType::FILESYSTEM) {
begin = Update.begin(UPDATE_SIZE_UNKNOWN, U_SPIFFS);
}
#endif
if (!begin || Update.hasError()) {
result->status = UpgradeStatus::ERROR_ON_START;
#ifdef ARDUINO_ARCH_ESP8266
result->error = Update.getErrorString();
#else
result->error = Update.errorString();
#endif
Log.serrorln(FPSTR(L_PORTAL_OTA), "File '%s', on start: %s", fileName.c_str(), result->error.c_str());
Log.serrorln(FPSTR(L_PORTAL_OTA), F("File '%s', on start: %s"), upload.filename.c_str(), result->error.c_str());
return;
}
Log.sinfoln(FPSTR(L_PORTAL_OTA), "File '%s', started", fileName.c_str());
}
if (dataLength) {
if (Update.write(data, dataLength) != dataLength) {
Log.sinfoln(FPSTR(L_PORTAL_OTA), F("File '%s', started"), upload.filename.c_str());
} else if (upload.status == UPLOAD_FILE_WRITE) {
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
Update.end(false);
result->status = UpgradeStatus::ERROR_ON_WRITE;
#ifdef ARDUINO_ARCH_ESP8266
result->error = Update.getErrorString();
#else
result->error = Update.errorString();
#endif
Log.serrorln(
FPSTR(L_PORTAL_OTA), "File '%s', on write %d bytes, %d of %d bytes",
fileName.c_str(),
dataLength,
result->progress + dataLength,
result->size
FPSTR(L_PORTAL_OTA),
F("File '%s', on writing %d bytes: %s"),
upload.filename.c_str(), upload.totalSize, result->error.c_str()
);
return;
}
result->progress += dataLength;
Log.sinfoln(
FPSTR(L_PORTAL_OTA), "File '%s', write %d bytes, %d of %d bytes",
fileName.c_str(),
dataLength,
result->progress,
result->size
);
}
if (result->size > 0) {
if (result->progress > result->size || (isFinal && result->progress < result->size)) {
Update.end(false);
result->status = UpgradeStatus::SIZE_MISMATCH;
Log.serrorln(
FPSTR(L_PORTAL_OTA), "File '%s', size mismatch: %d of %d bytes",
fileName.c_str(),
result->progress,
result->size
);
return;
} else {
Log.sinfoln(FPSTR(L_PORTAL_OTA), F("File '%s', writed %d bytes"), upload.filename.c_str(), upload.totalSize);
}
}
if (isFinal) {
if (!Update.end(true)) {
} else if (upload.status == UPLOAD_FILE_END) {
if (Update.end(true)) {
result->status = UpgradeStatus::SUCCESS;
Log.sinfoln(FPSTR(L_PORTAL_OTA), F("File '%s': finish"), upload.filename.c_str());
} else {
result->status = UpgradeStatus::ERROR_ON_FINISH;
#ifdef ARDUINO_ARCH_ESP8266
result->error = Update.getErrorString();
#else
result->error = Update.errorString();
#endif
Log.serrorln(FPSTR(L_PORTAL_OTA), "File '%s', on finish: %s", fileName.c_str(), result->error);
return;
Log.serrorln(FPSTR(L_PORTAL_OTA), F("File '%s', on finish: %s"), upload.filename.c_str(), result->error);
}
result->status = UpgradeStatus::SUCCESS;
Log.sinfoln(FPSTR(L_PORTAL_OTA), "File '%s': finish", fileName.c_str());
}
}
} else if (upload.status == UPLOAD_FILE_ABORTED) {
Update.end(false);
result->status = UpgradeStatus::ABORTED;
bool isRequestHandlerTrivial() const override final {
return false;
Log.serrorln(FPSTR(L_PORTAL_OTA), F("File '%s': aborted"), upload.filename.c_str());
}
}
protected:
CanHandleCallback canHandleCallback;
CanUploadCallback canUploadCallback;
BeforeUpgradeCallback beforeUpgradeCallback;
AfterUpgradeCallback afterUpgradeCallback;
AsyncURIMatcher uri;
const char* uri = nullptr;
UpgradeResult firmwareResult{UpgradeType::FIRMWARE, UpgradeStatus::NONE};
UpgradeResult filesystemResult{UpgradeType::FILESYSTEM, UpgradeStatus::NONE};
+3 -3
View File
@@ -4,12 +4,12 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"cssnano": "^7.0.2",
"cssnano-preset-advanced": "^7.0.2",
"cssnano": "^9.3.2",
"cssnano-preset-advanced": "^10.0.0",
"gulp": "^5.0.0",
"gulp-concat": "^2.6.1",
"gulp-gzip": "^1.4.2",
"gulp-html-minifier-terser": "^7.1.0",
"gulp-html-minifier-terser": "^8.0.0",
"gulp-jsonminify": "^1.1.0",
"gulp-postcss": "^10.0.0",
"gulp-terser": "^2.1.0",
+364 -208
View File
@@ -1,228 +1,384 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
;extra_configs = secrets.ini
extra_configs = secrets.default.ini
core_dir = .pio
;extra_configs = secrets.ini
extra_configs = secrets.default.ini
core_dir = .pio
[env]
version = 1.6.0-passiveble
framework = arduino
lib_deps = ESP32Async/AsyncTCP@^3.4.10
ESP32Async/ESPAsyncWebServer@^3.9.4
mathieucarbou/MycilaWebSerial@^8.2.0
bblanchon/ArduinoJson@^7.4.2
;ihormelnyk/OpenTherm Library@^1.1.5
https://github.com/Laxilef/opentherm_library#esp32_timer
arduino-libraries/ArduinoMqttClient@^0.1.8
gyverlibs/FileData@^1.0.3
gyverlibs/GyverPID@^3.3.2
gyverlibs/GyverBlinker@^1.1.1
pstolarz/OneWireNg@^0.14.1
milesburton/DallasTemperature@^4.0.6
https://github.com/Laxilef/esp32DHT#idf5
;laxilef/TinyLogger@^1.1.1
https://github.com/Laxilef/TinyLogger#custom_handlers
lib_ignore = OneWire
build_type = ${secrets.build_type}
build_flags = ;-mtext-section-literals
-O2
-Wno-deprecated-declarations
-D MQTT_CLIENT_STD_FUNCTION_CALLBACK=1
;-D DEBUG_ESP_CORE -D DEBUG_ESP_WIFI -D DEBUG_ESP_HTTP_SERVER -D DEBUG_ESP_PORT=Serial
-D BUILD_VERSION='"${this.version}"'
-D BUILD_ENV='"$PIOENV"'
-D CONFIG_ASYNC_TCP_STACK_SIZE=4096
-D ARDUINOJSON_USE_DOUBLE=0
-D ARDUINOJSON_USE_LONG_LONG=0
-D TINYLOGGER_GLOBAL
-D DHT_TASK_STACK_SIZE=4096
-D DEFAULT_SERIAL_ENABLED=${secrets.serial_enabled}
-D DEFAULT_SERIAL_BAUD=${secrets.serial_baud}
-D DEFAULT_WEBSERIAL_ENABLED=${secrets.webserial_enabled}
-D DEFAULT_LOG_LEVEL=${secrets.log_level}
-D DEFAULT_HOSTNAME='"${secrets.hostname}"'
-D DEFAULT_AP_SSID='"${secrets.ap_ssid}"'
-D DEFAULT_AP_PASSWORD='"${secrets.ap_password}"'
-D DEFAULT_STA_SSID='"${secrets.sta_ssid}"'
-D DEFAULT_STA_PASSWORD='"${secrets.sta_password}"'
-D DEFAULT_PORTAL_LOGIN='"${secrets.portal_login}"'
-D DEFAULT_PORTAL_PASSWORD='"${secrets.portal_password}"'
-D DEFAULT_MQTT_ENABLED=${secrets.mqtt_enabled}
-D DEFAULT_MQTT_SERVER='"${secrets.mqtt_server}"'
-D DEFAULT_MQTT_PORT=${secrets.mqtt_port}
-D DEFAULT_MQTT_USER='"${secrets.mqtt_user}"'
-D DEFAULT_MQTT_PASSWORD='"${secrets.mqtt_password}"'
-D DEFAULT_MQTT_PREFIX='"${secrets.mqtt_prefix}"'
upload_speed = 921600
monitor_speed = 115200
;monitor_filters = direct
monitor_filters = esp32_exception_decoder
board_build.flash_mode = dio
board_build.filesystem = littlefs
check_tool = ;pvs-studio
check_flags = ;pvs-studio: --analysis-mode=4 --exclude-path=./.pio/libdeps
version = 1.6.0
framework = arduino
lib_deps =
bblanchon/ArduinoJson@^7.4.2
;ihormelnyk/OpenTherm Library@^1.1.5
https://github.com/Laxilef/opentherm_library#esp32_timer
arduino-libraries/ArduinoMqttClient@^0.1.8
lennarthennigs/ESP Telnet@^2.2.3
gyverlibs/FileData@^1.0.3
gyverlibs/GyverPID@^3.3.2
gyverlibs/GyverBlinker@^1.1.1
pstolarz/OneWireNg@^0.14.1
milesburton/DallasTemperature@^4.0.6
laxilef/TinyLogger@^1.1.1
lib_ignore = OneWire
build_type = ${secrets.build_type}
build_flags =
-mtext-section-literals
-D MQTT_CLIENT_STD_FUNCTION_CALLBACK=1
;-D DEBUG_ESP_CORE -D DEBUG_ESP_WIFI -D DEBUG_ESP_HTTP_SERVER -D DEBUG_ESP_PORT=Serial
-D BUILD_VERSION='"${this.version}"'
-D BUILD_ENV='"$PIOENV"'
-D DEFAULT_SERIAL_ENABLED=${secrets.serial_enabled}
-D DEFAULT_SERIAL_BAUD=${secrets.serial_baud}
-D DEFAULT_TELNET_ENABLED=${secrets.telnet_enabled}
-D DEFAULT_TELNET_PORT=${secrets.telnet_port}
-D DEFAULT_LOG_LEVEL=${secrets.log_level}
-D DEFAULT_HOSTNAME='"${secrets.hostname}"'
-D DEFAULT_AP_SSID='"${secrets.ap_ssid}"'
-D DEFAULT_AP_PASSWORD='"${secrets.ap_password}"'
-D DEFAULT_STA_SSID='"${secrets.sta_ssid}"'
-D DEFAULT_STA_PASSWORD='"${secrets.sta_password}"'
-D DEFAULT_PORTAL_LOGIN='"${secrets.portal_login}"'
-D DEFAULT_PORTAL_PASSWORD='"${secrets.portal_password}"'
-D DEFAULT_MQTT_ENABLED=${secrets.mqtt_enabled}
-D DEFAULT_MQTT_SERVER='"${secrets.mqtt_server}"'
-D DEFAULT_MQTT_PORT=${secrets.mqtt_port}
-D DEFAULT_MQTT_USER='"${secrets.mqtt_user}"'
-D DEFAULT_MQTT_PASSWORD='"${secrets.mqtt_password}"'
-D DEFAULT_MQTT_PREFIX='"${secrets.mqtt_prefix}"'
upload_speed = 921600
monitor_speed = 115200
;monitor_filters = direct
monitor_filters =
esp32_exception_decoder
esp8266_exception_decoder
board_build.flash_mode = dio
board_build.filesystem = littlefs
check_tool = ; pvs-studio
check_flags =
; pvs-studio:
; --analysis-mode=4
; --exclude-path=./.pio/libdeps
; Defaults
[esp8266_defaults]
platform = espressif8266@^4.2.1
platform_packages = ${env.platform_packages}
lib_deps =
${env.lib_deps}
nrwiersma/ESP8266Scheduler@^1.2
lib_ignore = ${env.lib_ignore}
extra_scripts =
post:tools/build.py
build_type = ${env.build_type}
build_flags =
${env.build_flags}
-D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
;-D PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH_LOW_FLASH
-D PIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK305
board_build.ldscript = eagle.flash.4m1m.ld
check_tool = ${env.check_tool}
check_flags = ${env.check_flags}
[esp32_defaults]
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.37/platform-espressif32.zip
platform_packages = ${env.platform_packages}
board_build.partitions = esp32_partitions.csv
lib_deps = ${env.lib_deps}
laxilef/ESP32Scheduler@^1.0.1
nimble_lib = https://github.com/h2zero/NimBLE-Arduino
lib_ignore = ${env.lib_ignore}
BluetoothSerial
SimpleBLE
ESP RainMaker
RainMaker
ESP Insights
Insights
Zigbee
Matter
OpenThread
dsp
custom_component_remove = espressif/esp_hosted
espressif/esp_wifi_remote
espressif/esp-dsp
espressif/esp_modem
espressif/esp_rainmaker
espressif/rmaker_common
espressif/esp_insights
espressif/esp_diag_data_store
espressif/esp_diagnostics
espressif/libsodium
espressif/esp-modbus
espressif/esp-cbor
espressif/esp-sr
espressif/esp32-camera
espressif/qrcode
espressif/esp-zboss-lib
espressif/esp-zigbee-lib
chmorgan/esp-libhelix-mp3
extra_scripts = pre:tools/add_build_commit.py
post:tools/esp32.py
post:tools/build.py
build_type = ${env.build_type}
build_flags = ${env.build_flags}
-D CORE_DEBUG_LEVEL=0
-Wl,--wrap=esp_panic_handler
check_tool = ${env.check_tool}
check_flags = ${env.check_flags}
;platform = espressif32@^6.7
;platform = https://github.com/platformio/platform-espressif32.git
;platform_packages =
; framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.5
; framework-arduinoespressif32-libs @ https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.1/esp32-arduino-libs-idf-release_v5.1-33fbade6.zip
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.36/platform-espressif32.zip
platform_packages = ${env.platform_packages}
board_build.partitions = esp32_partitions.csv
lib_deps =
${env.lib_deps}
laxilef/ESP32Scheduler@^1.0.1
nimble_lib = h2zero/NimBLE-Arduino@2.3.7
lib_ignore = ${env.lib_ignore}
extra_scripts =
post:tools/esp32.py
post:tools/build.py
build_type = ${env.build_type}
build_flags =
${env.build_flags}
-D CORE_DEBUG_LEVEL=0
-Wl,--wrap=esp_panic_handler
check_tool = ${env.check_tool}
check_flags = ${env.check_flags}
; Boards
[env:d1_mini]
platform = ${esp8266_defaults.platform}
platform_packages = ${esp8266_defaults.platform_packages}
board = d1_mini
lib_deps = ${esp8266_defaults.lib_deps}
lib_ignore = ${esp8266_defaults.lib_ignore}
extra_scripts = ${esp8266_defaults.extra_scripts}
board_build.ldscript = ${esp8266_defaults.board_build.ldscript}
build_type = ${esp8266_defaults.build_type}
build_flags =
${esp8266_defaults.build_flags}
-D DEFAULT_OT_IN_GPIO=4
-D DEFAULT_OT_OUT_GPIO=5
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
-D DEFAULT_SENSOR_INDOOR_GPIO=14
-D DEFAULT_STATUS_LED_GPIO=13
-D DEFAULT_OT_RX_LED_GPIO=15
check_tool = ${esp8266_defaults.check_tool}
check_flags = ${esp8266_defaults.check_flags}
[env:d1_mini_lite]
platform = ${esp8266_defaults.platform}
platform_packages = ${esp8266_defaults.platform_packages}
board = d1_mini_lite
lib_deps = ${esp8266_defaults.lib_deps}
lib_ignore = ${esp8266_defaults.lib_ignore}
extra_scripts = ${esp8266_defaults.extra_scripts}
board_build.ldscript = ${esp8266_defaults.board_build.ldscript}
build_type = ${esp8266_defaults.build_type}
build_flags =
${esp8266_defaults.build_flags}
-D DEFAULT_OT_IN_GPIO=4
-D DEFAULT_OT_OUT_GPIO=5
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
-D DEFAULT_SENSOR_INDOOR_GPIO=14
-D DEFAULT_STATUS_LED_GPIO=13
-D DEFAULT_OT_RX_LED_GPIO=15
check_tool = ${esp8266_defaults.check_tool}
check_flags = ${esp8266_defaults.check_flags}
[env:d1_mini_pro]
platform = ${esp8266_defaults.platform}
platform_packages = ${esp8266_defaults.platform_packages}
board = d1_mini_pro
lib_deps = ${esp8266_defaults.lib_deps}
lib_ignore = ${esp8266_defaults.lib_ignore}
extra_scripts = ${esp8266_defaults.extra_scripts}
board_build.ldscript = ${esp8266_defaults.board_build.ldscript}
build_type = ${esp8266_defaults.build_type}
build_flags =
${esp8266_defaults.build_flags}
-D DEFAULT_OT_IN_GPIO=4
-D DEFAULT_OT_OUT_GPIO=5
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
-D DEFAULT_SENSOR_INDOOR_GPIO=14
-D DEFAULT_STATUS_LED_GPIO=13
-D DEFAULT_OT_RX_LED_GPIO=15
check_tool = ${esp8266_defaults.check_tool}
check_flags = ${esp8266_defaults.check_flags}
[env:nodemcu_8266]
platform = ${esp8266_defaults.platform}
platform_packages = ${esp8266_defaults.platform_packages}
board = nodemcuv2
lib_deps = ${esp8266_defaults.lib_deps}
lib_ignore = ${esp8266_defaults.lib_ignore}
extra_scripts = ${esp8266_defaults.extra_scripts}
board_build.ldscript = ${esp8266_defaults.board_build.ldscript}
build_type = ${esp8266_defaults.build_type}
build_flags =
${esp8266_defaults.build_flags}
-D DEFAULT_OT_IN_GPIO=13
-D DEFAULT_OT_OUT_GPIO=15
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
-D DEFAULT_SENSOR_INDOOR_GPIO=4
-D DEFAULT_STATUS_LED_GPIO=2
-D DEFAULT_OT_RX_LED_GPIO=16
check_tool = ${esp8266_defaults.check_tool}
check_flags = ${esp8266_defaults.check_flags}
[env:s2_mini]
extends = esp32_defaults
board = lolin_s2_mini
build_unflags = -DARDUINO_USB_MODE=1
build_flags = ${esp32_defaults.build_flags}
-D ARDUINO_USB_MODE=0
-D ARDUINO_USB_CDC_ON_BOOT=1
-D DEFAULT_OT_IN_GPIO=33
-D DEFAULT_OT_OUT_GPIO=35
-D DEFAULT_SENSOR_OUTDOOR_GPIO=9
-D DEFAULT_SENSOR_INDOOR_GPIO=7
-D DEFAULT_STATUS_LED_GPIO=11
-D DEFAULT_OT_RX_LED_GPIO=12
platform = ${esp32_defaults.platform}
platform_packages = ${esp32_defaults.platform_packages}
board = lolin_s2_mini
board_build.partitions = ${esp32_defaults.board_build.partitions}
lib_deps = ${esp32_defaults.lib_deps}
lib_ignore = ${esp32_defaults.lib_ignore}
extra_scripts = ${esp32_defaults.extra_scripts}
build_unflags =
-DARDUINO_USB_MODE=1
build_type = ${esp32_defaults.build_type}
build_flags =
${esp32_defaults.build_flags}
-D ARDUINO_USB_MODE=0
-D ARDUINO_USB_CDC_ON_BOOT=1
-D DEFAULT_OT_IN_GPIO=33
-D DEFAULT_OT_OUT_GPIO=35
-D DEFAULT_SENSOR_OUTDOOR_GPIO=9
-D DEFAULT_SENSOR_INDOOR_GPIO=7
-D DEFAULT_STATUS_LED_GPIO=11
-D DEFAULT_OT_RX_LED_GPIO=12
check_tool = ${esp32_defaults.check_tool}
check_flags = ${esp32_defaults.check_flags}
[env:s3_mini]
extends = esp32_defaults
board = lolin_s3_mini
lib_deps = ${esp32_defaults.lib_deps}
${esp32_defaults.nimble_lib}
build_unflags = -DARDUINO_USB_MODE=1
build_flags = ${esp32_defaults.build_flags}
-D ARDUINO_USB_MODE=0
-D ARDUINO_USB_CDC_ON_BOOT=1
-D MYNEWT_VAL_BLE_EXT_ADV=1
-D USE_BLE=1
-D DEFAULT_OT_IN_GPIO=35
-D DEFAULT_OT_OUT_GPIO=36
-D DEFAULT_SENSOR_OUTDOOR_GPIO=13
-D DEFAULT_SENSOR_INDOOR_GPIO=12
-D DEFAULT_STATUS_LED_GPIO=11
-D DEFAULT_OT_RX_LED_GPIO=10
[env:s3_mini]
platform = ${esp32_defaults.platform}
platform_packages = ${esp32_defaults.platform_packages}
board = lolin_s3_mini
board_build.partitions = ${esp32_defaults.board_build.partitions}
lib_deps =
${esp32_defaults.lib_deps}
${esp32_defaults.nimble_lib}
lib_ignore = ${esp32_defaults.lib_ignore}
extra_scripts = ${esp32_defaults.extra_scripts}
build_unflags =
-DARDUINO_USB_MODE=1
build_type = ${esp32_defaults.build_type}
build_flags =
${esp32_defaults.build_flags}
-D ARDUINO_USB_MODE=0
-D ARDUINO_USB_CDC_ON_BOOT=1
-D MYNEWT_VAL_BLE_EXT_ADV=1
-D USE_BLE=1
-D DEFAULT_OT_IN_GPIO=35
-D DEFAULT_OT_OUT_GPIO=36
-D DEFAULT_SENSOR_OUTDOOR_GPIO=13
-D DEFAULT_SENSOR_INDOOR_GPIO=12
-D DEFAULT_STATUS_LED_GPIO=11
-D DEFAULT_OT_RX_LED_GPIO=10
check_tool = ${esp32_defaults.check_tool}
check_flags = ${esp32_defaults.check_flags}
[env:c3_mini]
extends = esp32_defaults
board = lolin_c3_mini
lib_deps = ${esp32_defaults.lib_deps}
${esp32_defaults.nimble_lib}
;build_unflags = -mtext-section-literals
build_flags = ${esp32_defaults.build_flags}
-D MYNEWT_VAL_BLE_EXT_ADV=1
-D USE_BLE=1
-D DEFAULT_OT_IN_GPIO=8
-D DEFAULT_OT_OUT_GPIO=10
-D DEFAULT_SENSOR_OUTDOOR_GPIO=0
-D DEFAULT_SENSOR_INDOOR_GPIO=1
-D DEFAULT_STATUS_LED_GPIO=4
-D DEFAULT_OT_RX_LED_GPIO=5
[env:c3_mini]
platform = ${esp32_defaults.platform}
platform_packages = ${esp32_defaults.platform_packages}
board = lolin_c3_mini
board_build.partitions = ${esp32_defaults.board_build.partitions}
lib_deps =
${esp32_defaults.lib_deps}
${esp32_defaults.nimble_lib}
lib_ignore = ${esp32_defaults.lib_ignore}
extra_scripts = ${esp32_defaults.extra_scripts}
build_unflags =
-mtext-section-literals
build_type = ${esp32_defaults.build_type}
build_flags =
${esp32_defaults.build_flags}
-D MYNEWT_VAL_BLE_EXT_ADV=1
-D USE_BLE=1
-D DEFAULT_OT_IN_GPIO=8
-D DEFAULT_OT_OUT_GPIO=10
-D DEFAULT_SENSOR_OUTDOOR_GPIO=0
-D DEFAULT_SENSOR_INDOOR_GPIO=1
-D DEFAULT_STATUS_LED_GPIO=4
-D DEFAULT_OT_RX_LED_GPIO=5
check_tool = ${esp32_defaults.check_tool}
check_flags = ${esp32_defaults.check_flags}
[env:nodemcu_32]
extends = esp32_defaults
board = nodemcu-32s
lib_deps = ${esp32_defaults.lib_deps}
${esp32_defaults.nimble_lib}
build_flags = ${esp32_defaults.build_flags}
-D USE_BLE=1
-D DEFAULT_OT_IN_GPIO=16
-D DEFAULT_OT_OUT_GPIO=4
-D DEFAULT_SENSOR_OUTDOOR_GPIO=15
-D DEFAULT_SENSOR_INDOOR_GPIO=26
-D DEFAULT_STATUS_LED_GPIO=2
-D DEFAULT_OT_RX_LED_GPIO=19
platform = ${esp32_defaults.platform}
platform_packages = ${esp32_defaults.platform_packages}
board = nodemcu-32s
board_build.partitions = ${esp32_defaults.board_build.partitions}
lib_deps =
${esp32_defaults.lib_deps}
${esp32_defaults.nimble_lib}
lib_ignore = ${esp32_defaults.lib_ignore}
extra_scripts = ${esp32_defaults.extra_scripts}
build_type = ${esp32_defaults.build_type}
build_flags =
${esp32_defaults.build_flags}
-D USE_BLE=1
-D DEFAULT_OT_IN_GPIO=16
-D DEFAULT_OT_OUT_GPIO=4
-D DEFAULT_SENSOR_OUTDOOR_GPIO=15
-D DEFAULT_SENSOR_INDOOR_GPIO=26
-D DEFAULT_STATUS_LED_GPIO=2
-D DEFAULT_OT_RX_LED_GPIO=19
check_tool = ${esp32_defaults.check_tool}
check_flags = ${esp32_defaults.check_flags}
[env:nodemcu_32_160mhz]
extends = env:nodemcu_32
board_build.f_cpu = 160000000L ; set frequency to 160MHz
[env:nodemcu_32_160mhz]
extends = env:nodemcu_32
board_build.f_cpu = 160000000L ; set frequency to 160MHz
[env:d1_mini32]
extends = esp32_defaults
board = wemos_d1_mini32
lib_deps = ${esp32_defaults.lib_deps}
${esp32_defaults.nimble_lib}
build_flags = ${esp32_defaults.build_flags}
-D USE_BLE=1
-D DEFAULT_OT_IN_GPIO=21
-D DEFAULT_OT_OUT_GPIO=22
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
-D DEFAULT_SENSOR_INDOOR_GPIO=18
-D DEFAULT_STATUS_LED_GPIO=2
-D DEFAULT_OT_RX_LED_GPIO=19
platform = ${esp32_defaults.platform}
platform_packages = ${esp32_defaults.platform_packages}
board = wemos_d1_mini32
board_build.partitions = ${esp32_defaults.board_build.partitions}
lib_deps =
${esp32_defaults.lib_deps}
${esp32_defaults.nimble_lib}
lib_ignore = ${esp32_defaults.lib_ignore}
extra_scripts = ${esp32_defaults.extra_scripts}
build_type = ${esp32_defaults.build_type}
build_flags =
${esp32_defaults.build_flags}
-D USE_BLE=1
-D DEFAULT_OT_IN_GPIO=21
-D DEFAULT_OT_OUT_GPIO=22
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
-D DEFAULT_SENSOR_INDOOR_GPIO=18
-D DEFAULT_STATUS_LED_GPIO=2
-D DEFAULT_OT_RX_LED_GPIO=19
check_tool = ${esp32_defaults.check_tool}
check_flags = ${esp32_defaults.check_flags}
[env:esp32_c6]
extends = esp32_defaults
board = esp32-c6-devkitc-1
lib_deps = ${esp32_defaults.lib_deps}
${esp32_defaults.nimble_lib}
;build_unflags = -mtext-section-literals
build_flags = ${esp32_defaults.build_flags}
-D USE_BLE=1
-D DEFAULT_OT_IN_GPIO=15
-D DEFAULT_OT_OUT_GPIO=23
-D DEFAULT_SENSOR_OUTDOOR_GPIO=0
-D DEFAULT_SENSOR_INDOOR_GPIO=0
-D DEFAULT_STATUS_LED_GPIO=11
-D DEFAULT_OT_RX_LED_GPIO=10
custom_sdkconfig = '# CONFIG_OPENTHREAD_ENABLED is not set'
'# CONFIG_ESP_WIFI_ENTERPRISE_SUPPORT is not set'
'# CONFIG_LWIP_IPV6 is not set'
'# CONFIG_LWIP_IPV6_AUTOCONFIG is not set'
'# CONFIG_LWIP_PPP_SUPPORT is not set'
; W5500 ethernet (USE_ETHERNET) is hardware-validated on this target only; every other env
; inherits the `false` default from src/defines.h and compiles the driver out.
platform = ${esp32_defaults.platform}
framework = arduino, espidf
platform_packages = ${esp32_defaults.platform_packages}
board = esp32-c6-devkitm-1
board_build.partitions = ${esp32_defaults.board_build.partitions}
board_build.embed_txtfiles =
managed_components/espressif__esp_insights/server_certs/https_server.crt
managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt
managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt
managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt
lib_deps = ${esp32_defaults.lib_deps}
lib_ignore =
${esp32_defaults.lib_ignore}
extra_scripts = ${esp32_defaults.extra_scripts}
build_unflags =
-mtext-section-literals
build_type = ${esp32_defaults.build_type}
build_flags =
${esp32_defaults.build_flags}
-D USE_BLE=1
-D USE_ETHERNET=1
-D DEFAULT_OT_IN_GPIO=15
-D DEFAULT_OT_OUT_GPIO=23
-D DEFAULT_SENSOR_OUTDOOR_GPIO=0
-D DEFAULT_SENSOR_INDOOR_GPIO=0
-D DEFAULT_STATUS_LED_GPIO=11
-D DEFAULT_OT_RX_LED_GPIO=10
check_tool = ${esp32_defaults.check_tool}
check_flags = ${esp32_defaults.check_flags}
[env:otthing]
extends = esp32_defaults
board = lolin_c3_mini
lib_deps = ${esp32_defaults.lib_deps}
${esp32_defaults.nimble_lib}
;build_unflags = -mtext-section-literals
build_flags = ${esp32_defaults.build_flags}
-D MYNEWT_VAL_BLE_EXT_ADV=1
-D USE_BLE=1
-D DEFAULT_OT_IN_GPIO=3
-D DEFAULT_OT_OUT_GPIO=1
;-D DEFAULT_SENSOR_OUTDOOR_GPIO=0
;-D DEFAULT_SENSOR_INDOOR_GPIO=1
-D DEFAULT_STATUS_LED_GPIO=8
-D DEFAULT_OT_RX_LED_GPIO=2
-D OT_BYPASS_RELAY_GPIO=20
[env:otthing]
platform = ${esp32_defaults.platform}
platform_packages = ${esp32_defaults.platform_packages}
board = lolin_c3_mini
board_build.partitions = ${esp32_defaults.board_build.partitions}
lib_deps =
${esp32_defaults.lib_deps}
${esp32_defaults.nimble_lib}
lib_ignore = ${esp32_defaults.lib_ignore}
extra_scripts = ${esp32_defaults.extra_scripts}
build_unflags =
-mtext-section-literals
build_type = ${esp32_defaults.build_type}
build_flags =
${esp32_defaults.build_flags}
-D MYNEWT_VAL_BLE_EXT_ADV=1
-D USE_BLE=1
-D DEFAULT_OT_IN_GPIO=3
-D DEFAULT_OT_OUT_GPIO=1
; -D DEFAULT_SENSOR_OUTDOOR_GPIO=0
; -D DEFAULT_SENSOR_INDOOR_GPIO=1
-D DEFAULT_STATUS_LED_GPIO=8
-D DEFAULT_OT_RX_LED_GPIO=2
-D OT_BYPASS_RELAY_GPIO=20
check_tool = ${esp32_defaults.check_tool}
check_flags = ${esp32_defaults.check_flags}
+38
View File
@@ -0,0 +1,38 @@
# Source:
# https://github.com/pioarduino/platform-espressif32/tree/main/examples/espidf-arduino-h2zero-BLE_scan
CONFIG_FREERTOS_HZ=1000
CONFIG_MBEDTLS_PSK_MODES=y
CONFIG_MBEDTLS_KEY_EXCHANGE_PSK=y
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE=y
#
# Ethernet (W5500 over SPI)
CONFIG_ETH_USE_SPI_ETHERNET=y
CONFIG_ETH_SPI_ETHERNET_W5500=y
#
# BT config
CONFIG_BT_ENABLED=y
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
CONFIG_BTDM_CTRL_MODE_BTDM=n
CONFIG_BT_BLUEDROID_ENABLED=n
CONFIG_BT_NIMBLE_ENABLED=y
#
# Arduino Configuration
CONFIG_AUTOSTART_ARDUINO=y
CONFIG_ARDUINO_SELECTIVE_COMPILATION=y
CONFIG_ARDUINO_SELECTIVE_Zigbee=n
CONFIG_ARDUINO_SELECTIVE_Matter=n
CONFIG_ARDUINO_SELECTIVE_WiFiProv=n
CONFIG_ARDUINO_SELECTIVE_BLE=n
CONFIG_ARDUINO_SELECTIVE_BluetoothSerial=n
CONFIG_ARDUINO_SELECTIVE_SimpleBLE=n
CONFIG_ARDUINO_SELECTIVE_RainMaker=n
CONFIG_ARDUINO_SELECTIVE_OpenThread=n
CONFIG_ARDUINO_SELECTIVE_Insights=n
+2 -1
View File
@@ -3,7 +3,8 @@ build_type = release
serial_enabled = true
serial_baud = 115200
webserial_enabled = true
telnet_enabled = true
telnet_port = 23
log_level = 5
hostname = opentherm
+12 -4
View File
@@ -25,6 +25,12 @@ public:
}
bool publishDynamicSensor(Sensors::Settings& sSensor, Sensors::ValueType vType = Sensors::ValueType::PRIMARY, UnitSystem unit = UnitSystem::METRIC, bool enabledByDefault = true) {
#if !USE_BLE
if (sSensor.type == Sensors::Type::BLUETOOTH) {
return false;
}
#endif
JsonDocument doc;
// set device class & unit of measurement
@@ -176,10 +182,9 @@ public:
objId.c_str()
);
// set device class, name, value template for Bluetooth/DHT sensors
// set device class, name, value template for bluetooth sensors
// or name & value template for another sensors
if (sSensor.type == Sensors::Type::BLUETOOTH ||
sSensor.type == Sensors::Type::DHT11 || sSensor.type == Sensors::Type::DHT22) {
if (sSensor.type == Sensors::Type::BLUETOOTH) {
// available state topic
doc[FPSTR(HA_AVAILABILITY)][1][FPSTR(HA_TOPIC)] = doc[FPSTR(HA_STATE_TOPIC)];
doc[FPSTR(HA_AVAILABILITY)][1][FPSTR(HA_VALUE_TEMPLATE)] = JsonString(AVAILABILITY_SENSOR_CONN, true);
@@ -1179,7 +1184,10 @@ public:
bool publishNetworkRssi(bool enabledByDefault = true) {
JsonDocument doc;
doc[FPSTR(HA_AVAILABILITY)][FPSTR(HA_TOPIC)] = this->statusTopic.c_str();
doc[FPSTR(HA_AVAILABILITY)][0][FPSTR(HA_TOPIC)] = this->statusTopic.c_str();
doc[FPSTR(HA_AVAILABILITY)][1][FPSTR(HA_TOPIC)] = this->stateTopic.c_str();
doc[FPSTR(HA_AVAILABILITY)][1][FPSTR(HA_VALUE_TEMPLATE)] = F("{{ iif(value_json.master.network.connectionType == 'wifi', 'online', 'offline') }}");
doc[FPSTR(HA_AVAILABILITY_MODE)] = F("all");
doc[FPSTR(HA_ENABLED_BY_DEFAULT)] = enabledByDefault;
doc[FPSTR(HA_UNIQUE_ID)] = this->getUniqueIdWithPrefix(FPSTR(S_RSSI));
doc[FPSTR(HA_DEFAULT_ENTITY_ID)] = this->getEntityIdWithPrefix(FPSTR(HA_ENTITY_SENSOR), FPSTR(S_RSSI));
+62 -31
View File
@@ -6,6 +6,7 @@ extern NetworkMgr* network;
extern MqttTask* tMqtt;
extern OpenThermTask* tOt;
extern FileData fsNetworkSettings, fsSettings, fsSensorsSettings;
extern ESPTelnetStream* telnetStream;
class MainTask : public Task {
@@ -39,20 +40,15 @@ protected:
PumpStartReason extPumpStartReason = PumpStartReason::NONE;
unsigned long externalPumpStartTime = 0;
bool ntpStarted = false;
bool telnetStarted = false;
bool emergencyDetected = false;
unsigned long emergencyFlipTime = 0;
bool freezeDetected = false;
unsigned long freezeDetectedTime = 0;
#if defined(ARDUINO_ARCH_ESP32)
const char* getTaskName() override {
return "Main";
}
uint32_t getTaskStackSize() override {
return 6000;
}
/*BaseType_t getTaskCore() override {
return 1;
}*/
@@ -106,11 +102,12 @@ protected:
vars.mqtt.connected = tMqtt->isConnected();
vars.network.connected = network->isConnected();
vars.network.rssi = network->isConnected() ? WiFi.RSSI() : 0;
vars.network.rssi = network->getRssi();
vars.network.connectionType = network->getUplink();
if (settings.system.logLevel >= TinyLoggerLevel::SILENT && settings.system.logLevel <= TinyLoggerLevel::VERBOSE) {
if (settings.system.logLevel >= TinyLogger::Level::SILENT && settings.system.logLevel <= TinyLogger::Level::VERBOSE) {
if (Log.getLevel() != settings.system.logLevel) {
Log.setLevel(static_cast<TinyLoggerLevel>(settings.system.logLevel));
Log.setLevel(static_cast<TinyLogger::Level>(settings.system.logLevel));
}
}
@@ -125,6 +122,11 @@ protected:
}
}
if (!this->telnetStarted && telnetStream != nullptr) {
telnetStream->begin(23, false);
this->telnetStarted = true;
}
if (settings.mqtt.enabled && !tMqtt->isEnabled()) {
tMqtt->enable();
@@ -137,6 +139,11 @@ protected:
this->ntpStarted = false;
}
if (this->telnetStarted) {
telnetStream->stop();
this->telnetStarted = false;
}
if (tMqtt->isEnabled()) {
tMqtt->disable();
}
@@ -150,10 +157,23 @@ protected:
}
this->ledStatus();
// telnet
if (this->telnetStarted) {
this->yield();
telnetStream->loop();
this->yield();
}
// anti memory leak
while (Serial.available() > 0) {
Serial.read();
for (Stream* stream : Log.getStreams()) {
while (stream->available() > 0) {
stream->read();
#ifdef ARDUINO_ARCH_ESP8266
::optimistic_yield(1000);
#endif
}
}
// heap info
@@ -192,7 +212,7 @@ protected:
vars.states.restarting = true;
}
if (settings.system.logLevel < TinyLoggerLevel::VERBOSE) {
if (settings.system.logLevel < TinyLogger::Level::VERBOSE) {
return;
}
@@ -222,7 +242,7 @@ protected:
void heating() {
// freeze protection
if (!settings.heating.enabled) {
{
float lowTemp = 255.0f;
uint8_t availableSensors = 0;
@@ -253,29 +273,40 @@ protected:
availableSensors++;
}
if (availableSensors && lowTemp <= settings.heating.freezeProtection.lowTemp) {
if (!this->freezeDetected) {
this->freezeDetected = true;
this->freezeDetectedTime = millis();
if (availableSensors) {
if (vars.master.heating.freezing) {
if (lowTemp - (float) settings.heating.freezeProtection.highTemp + 0.0001f >= 0.0f) {
vars.master.heating.freezing = false;
} else if (millis() - this->freezeDetectedTime > (settings.heating.freezeProtection.thresholdTime * 1000)) {
this->freezeDetected = false;
settings.heating.enabled = true;
fsSettings.update();
Log.sinfoln(
FPSTR(L_MAIN),
F("No freezing detected. Current low temp: %.2f, threshold (high): %hhu"),
lowTemp, settings.heating.freezeProtection.highTemp
);
}
Log.sinfoln(
FPSTR(L_MAIN),
F("Heating turned on by freeze protection, current low temp: %.2f, threshold: %hhu"),
lowTemp, settings.heating.freezeProtection.lowTemp
);
} else {
if ((float) settings.heating.freezeProtection.lowTemp - lowTemp + 0.0001f >= 0.0f) {
vars.master.heating.freezing = true;
if (!settings.heating.enabled) {
settings.heating.enabled = true;
fsSettings.update();
}
Log.sinfoln(
FPSTR(L_MAIN),
F("Freezing detected! Current low temp: %.2f, threshold (low): %hhu"),
lowTemp, settings.heating.freezeProtection.lowTemp
);
}
}
} else if (this->freezeDetected) {
this->freezeDetected = false;
}
} else if (vars.master.heating.freezing) {
vars.master.heating.freezing = false;
} else if (this->freezeDetected) {
this->freezeDetected = false;
Log.sinfoln(FPSTR(L_MAIN), F("No sensors available, freeze protection unavailable!"));
}
}
}
+1 -17
View File
@@ -292,14 +292,6 @@ protected:
this->haHelper->deleteDynamicSensor(prevSettings, Sensors::ValueType::RSSI);
break;
case Sensors::Type::DHT11:
case Sensors::Type::DHT22:
this->haHelper->deleteConnectionDynamicSensor(prevSettings);
this->haHelper->deleteSignalQualityDynamicSensor(prevSettings);
this->haHelper->deleteDynamicSensor(prevSettings, Sensors::ValueType::TEMPERATURE);
this->haHelper->deleteDynamicSensor(prevSettings, Sensors::ValueType::HUMIDITY);
break;
case Sensors::Type::DALLAS_TEMP:
this->haHelper->deleteConnectionDynamicSensor(prevSettings);
this->haHelper->deleteSignalQualityDynamicSensor(prevSettings);
@@ -327,14 +319,6 @@ protected:
this->haHelper->publishDynamicSensor(sSettings, Sensors::ValueType::RSSI, settings.system.unitSystem, false);
break;
case Sensors::Type::DHT11:
case Sensors::Type::DHT22:
this->haHelper->publishConnectionDynamicSensor(sSettings);
this->haHelper->publishSignalQualityDynamicSensor(sSettings, false);
this->haHelper->publishDynamicSensor(sSettings, Sensors::ValueType::TEMPERATURE, settings.system.unitSystem);
this->haHelper->publishDynamicSensor(sSettings, Sensors::ValueType::HUMIDITY, settings.system.unitSystem);
break;
case Sensors::Type::DALLAS_TEMP:
this->haHelper->publishConnectionDynamicSensor(sSettings);
this->haHelper->publishSignalQualityDynamicSensor(sSettings, false);
@@ -432,7 +416,7 @@ protected:
return;
}
if (settings.system.logLevel >= TinyLoggerLevel::TRACE) {
if (settings.system.logLevel >= TinyLogger::Level::TRACE) {
Log.strace(FPSTR(L_MQTT_MSG), F("Topic: %s\r\n> "), topic.c_str());
if (Log.lock()) {
for (size_t i = 0; i < length; i++) {
+2 -7
View File
@@ -37,13 +37,9 @@ protected:
const char* getTaskName() override {
return "OpenTherm";
}
uint32_t getTaskStackSize() override {
return 7500;
}
BaseType_t getTaskCore() override {
return 0;
return 1;
}
int getTaskPriority() override {
@@ -174,8 +170,7 @@ protected:
// Heating settings
vars.master.heating.enabled = this->isReady()
&& settings.heating.enabled
&& vars.cascadeControl.input
&& !vars.master.heating.blocking
&& (vars.master.heating.freezing || (vars.cascadeControl.input && !vars.master.heating.blocking))
&& !vars.master.heating.overheat;
// DHW settings
+761 -385
View File
File diff suppressed because it is too large. Load diff
+8 -7
View File
@@ -19,10 +19,6 @@ protected:
const char* getTaskName() override {
return "Regulator";
}
uint32_t getTaskStackSize() override {
return 5000;
}
/*BaseType_t getTaskCore() override {
return 1;
@@ -32,7 +28,7 @@ protected:
return 4;
}
#endif
void loop() {
if (vars.states.restarting || vars.states.upgrading) {
return;
@@ -159,7 +155,7 @@ protected:
);
float etResult = settings.heating.target + settings.equitherm.shift + sf * (
tempDelta >= 0
? pow(tempDelta, 1.0f / settings.equitherm.exponent)
? pow(tempDelta, 1.0f / settings.equitherm.exponent)
: -(pow(-(tempDelta), 1.0f / settings.equitherm.exponent))
);
@@ -208,7 +204,7 @@ protected:
}*/
float error = pidRegulator.setpoint - pidRegulator.input;
bool hasDeadband = settings.pid.deadband.enabled
bool hasDeadband = settings.pid.deadband.enabled
&& (error > -(settings.pid.deadband.thresholdHigh))
&& (error < settings.pid.deadband.thresholdLow);
@@ -244,6 +240,11 @@ protected:
) * settings.heating.turboFactor;
}
// If freezing, set temperature to no lower than low temp provided by freeze protection
if (vars.master.heating.freezing && fabsf(settings.heating.freezeProtection.lowTemp - newTemp) < 0.0001f) {
newTemp = settings.heating.freezeProtection.lowTemp;
}
return newTemp;
}
};
-2
View File
@@ -39,8 +39,6 @@ public:
NTC_10K_TEMP = 50,
DALLAS_TEMP = 51,
BLUETOOTH = 52,
DHT11 = 53,
DHT22 = 54,
HEATING_SETPOINT_TEMP = 253,
MANUAL = 254,
+562 -451
View File
File diff suppressed because it is too large. Load diff
+26 -5
View File
@@ -1,3 +1,5 @@
// NetworkSettings struct is append-only. The file is persisted across updates,
// and removing/modifying existing keys will lead to file corruption.
struct NetworkSettings {
char hostname[25] = DEFAULT_HOSTNAME;
bool useDhcp = true;
@@ -20,6 +22,22 @@ struct NetworkSettings {
char password[65] = DEFAULT_STA_PASSWORD;
uint8_t channel = 0;
} sta;
struct {
bool enabled = DEFAULT_ETHERNET_ENABLED;
// nothing reads this yet: the W5500 is the only implementation the firmware can drive
EthernetImplementation implementation = EthernetImplementation::W5500;
struct {
uint8_t clk = DEFAULT_ETH_CLK_GPIO;
uint8_t mosi = DEFAULT_ETH_MOSI_GPIO;
uint8_t miso = DEFAULT_ETH_MISO_GPIO;
uint8_t cs = DEFAULT_ETH_CS_GPIO;
uint8_t irq = DEFAULT_ETH_IRQ_GPIO;
uint8_t rst = DEFAULT_ETH_RST_GPIO;
} w5500;
} ethernet;
} networkSettings;
struct Settings {
@@ -32,8 +50,9 @@ struct Settings {
} serial;
struct {
bool enabled = DEFAULT_WEBSERIAL_ENABLED;
} webSerial;
bool enabled = DEFAULT_TELNET_ENABLED;
unsigned short port = DEFAULT_TELNET_PORT;
} telnet;
struct {
char server[49] = "pool.ntp.org";
@@ -120,8 +139,8 @@ struct Settings {
} overheatProtection;
struct {
uint8_t highTemp = 15;
uint8_t lowTemp = 10;
unsigned short thresholdTime = 600;
} freezeProtection;
} heating;
@@ -131,7 +150,7 @@ struct Settings {
uint8_t minTemp = DEFAULT_DHW_MIN_TEMP;
uint8_t maxTemp = DEFAULT_DHW_MAX_TEMP;
uint8_t maxModulation = 100;
struct {
uint8_t highTemp = 95;
uint8_t lowTemp = 90;
@@ -271,6 +290,7 @@ struct Variables {
struct {
bool connected = false;
int8_t rssi = 0;
NetworkUtils::NetworkMgr::Uplink connectionType = NetworkUtils::NetworkMgr::Uplink::None;
} network;
struct {
@@ -303,6 +323,7 @@ struct Variables {
bool enabled = false;
bool indoorTempControl = false;
bool overheat = false;
bool freezing = false;
float setpointTemp = 0.0f;
float targetTemp = 0.0f;
float currentTemp = 0.0f;
@@ -438,4 +459,4 @@ struct Variables {
bool restarting = false;
bool upgrading = false;
} states;
} vars;
} vars;
+47 -9
View File
@@ -30,10 +30,6 @@
#define BUILD_VERSION "0.0.0"
#endif
#ifndef BUILD_COMMIT
#define BUILD_COMMIT "undefined"
#endif
#ifndef BUILD_ENV
#define BUILD_ENV "undefined"
#endif
@@ -46,14 +42,23 @@
#define DEFAULT_SERIAL_BAUD 115200
#endif
#ifndef DEFAULT_WEBSERIAL_ENABLED
#define DEFAULT_WEBSERIAL_ENABLED true
#ifndef DEFAULT_TELNET_ENABLED
#define DEFAULT_TELNET_ENABLED true
#endif
#ifndef DEFAULT_TELNET_PORT
#define DEFAULT_TELNET_PORT 23
#endif
#ifndef USE_BLE
#define USE_BLE false
#endif
// ethernet (W5500 over SPI) is only validated on the esp32_c6 target: off everywhere else
#ifndef USE_ETHERNET
#define USE_ETHERNET false
#endif
#ifndef DEFAULT_HOSTNAME
#define DEFAULT_HOSTNAME ""
#endif
@@ -75,13 +80,41 @@
#endif
#ifndef DEFAULT_LOG_LEVEL
#define DEFAULT_LOG_LEVEL TinyLoggerLevel::VERBOSE
#define DEFAULT_LOG_LEVEL TinyLogger::Level::VERBOSE
#endif
#ifndef DEFAULT_STATUS_LED_GPIO
#define DEFAULT_STATUS_LED_GPIO GPIO_IS_NOT_CONFIGURED
#endif
#ifndef DEFAULT_ETHERNET_ENABLED
#define DEFAULT_ETHERNET_ENABLED false
#endif
#ifndef DEFAULT_ETH_CLK_GPIO
#define DEFAULT_ETH_CLK_GPIO GPIO_IS_NOT_CONFIGURED
#endif
#ifndef DEFAULT_ETH_MOSI_GPIO
#define DEFAULT_ETH_MOSI_GPIO GPIO_IS_NOT_CONFIGURED
#endif
#ifndef DEFAULT_ETH_MISO_GPIO
#define DEFAULT_ETH_MISO_GPIO GPIO_IS_NOT_CONFIGURED
#endif
#ifndef DEFAULT_ETH_CS_GPIO
#define DEFAULT_ETH_CS_GPIO GPIO_IS_NOT_CONFIGURED
#endif
#ifndef DEFAULT_ETH_IRQ_GPIO
#define DEFAULT_ETH_IRQ_GPIO GPIO_IS_NOT_CONFIGURED
#endif
#ifndef DEFAULT_ETH_RST_GPIO
#define DEFAULT_ETH_RST_GPIO GPIO_IS_NOT_CONFIGURED
#endif
#ifndef DEFAULT_PORTAL_LOGIN
#define DEFAULT_PORTAL_LOGIN ""
#endif
@@ -147,7 +180,7 @@
#endif
#ifndef PROGMEM
#define PROGMEM
#define PROGMEM
#endif
#ifdef ARDUINO_ARCH_ESP32
@@ -168,4 +201,9 @@ enum class HysteresisAction : uint8_t {
SET_ZERO_TARGET = 1
};
char buffer[255];
enum class EthernetImplementation : uint8_t {
NONE = 0,
W5500 = 1
};
char buffer[255];
+3
View File
@@ -0,0 +1,3 @@
dependencies:
idf: ">=5.3.2"
h2zero/esp-nimble-cpp: ">=2.2.1"
+33 -15
View File
@@ -1,8 +1,11 @@
#define ARDUINOJSON_USE_DOUBLE 0
#define ARDUINOJSON_USE_LONG_LONG 0
#include <Arduino.h>
#include <ArduinoJson.h>
#include <FileData.h>
#include <LittleFS.h>
#include <MycilaWebSerial.h>
#include <ESPTelnetStream.h>
#include "defines.h"
#include "strings.h"
@@ -34,7 +37,7 @@
using namespace NetworkUtils;
// Vars
WebSerial* webSerial = nullptr;
ESPTelnetStream* telnetStream = nullptr;
NetworkMgr* network = nullptr;
Sensors::Result sensorsResults[SENSORS_AMOUNT];
@@ -58,7 +61,7 @@ void setup() {
Sensors::results = sensorsResults;
LittleFS.begin();
Log.setLevel(TinyLoggerLevel::VERBOSE);
Log.setLevel(TinyLogger::Level::VERBOSE);
Log.setServiceTemplate("\033[1m[%s]\033[22m");
Log.setLevelTemplate("\033[1m[%s]\033[22m");
Log.setMsgPrefix("\033[m ");
@@ -71,16 +74,19 @@ void setup() {
return tm{sec, min, hour};
});
Serial.begin(115200);
#if ARDUINO_USB_MODE
Serial.setTxBufferSize(512);
#endif
Log.addHandler(&Serial);
Log.addStream(&Serial);
Log.print("\n\n\r");
//
// Network settings
// The network file has to survive updates, this ensures it doesn't get wiped when the structure is modified
fsNetworkSettings.addWithoutWipe(true);
switch (fsNetworkSettings.read()) {
case FD_FS_ERR:
Log.swarningln(FPSTR(L_NETWORK_SETTINGS), F("Filesystem error, load default"));
@@ -151,6 +157,18 @@ void setup() {
break;
}
// ethernet (W5500) is configured from the network settings, after they are loaded
network
->setEthernet(networkSettings.ethernet.enabled)
->setEthernetPins(
networkSettings.ethernet.w5500.clk,
networkSettings.ethernet.w5500.mosi,
networkSettings.ethernet.w5500.miso,
networkSettings.ethernet.w5500.cs,
networkSettings.ethernet.w5500.irq,
networkSettings.ethernet.w5500.rst
);
// generate mqtt prefix if it is empty
if (!strlen(settings.mqtt.prefix)) {
strcpy(settings.mqtt.prefix, getChipId("otgateway_").c_str());
@@ -160,24 +178,24 @@ void setup() {
// Logs settings
if (!settings.system.serial.enabled) {
Serial.end();
Log.clearHandlers();
Log.clearStreams();
} else if (settings.system.serial.baudrate != 115200) {
Serial.end();
Log.clearHandlers();
Log.clearStreams();
Serial.begin(settings.system.serial.baudrate);
Log.addHandler(&Serial);
Log.addStream(&Serial);
}
if (settings.system.webSerial.enabled) {
webSerial = new WebSerial();
webSerial->setBuffer(100);
Log.addHandler(webSerial);
if (settings.system.telnet.enabled) {
telnetStream = new ESPTelnetStream;
telnetStream->setKeepAliveInterval(500);
Log.addStream(telnetStream);
}
if (settings.system.logLevel >= TinyLoggerLevel::SILENT && settings.system.logLevel <= TinyLoggerLevel::VERBOSE) {
Log.setLevel(static_cast<TinyLoggerLevel>(settings.system.logLevel));
if (settings.system.logLevel >= TinyLogger::Level::SILENT && settings.system.logLevel <= TinyLogger::Level::VERBOSE) {
Log.setLevel(static_cast<TinyLogger::Level>(settings.system.logLevel));
}
//
@@ -213,7 +231,7 @@ void setup() {
tRegulator = new RegulatorTask(true, 10000);
Scheduler.start(tRegulator);
tPortal = new PortalTask(true, 10);
tPortal = new PortalTask(true, 0);
Scheduler.start(tPortal);
tMain = new MainTask(true, 100);
+15 -4
View File
@@ -24,7 +24,6 @@ const char L_OT_CH2[] PROGMEM = "OT.CH2";
const char L_SENSORS[] PROGMEM = "SENSORS";
const char L_SENSORS_SETTINGS[] PROGMEM = "SENSORS.SETTINGS";
const char L_SENSORS_DALLAS[] PROGMEM = "SENSORS.DALLAS";
const char L_SENSORS_DHT[] PROGMEM = "SENSORS.DHT";
const char L_SENSORS_NTC[] PROGMEM = "SENSORS.NTC";
const char L_SENSORS_BLE[] PROGMEM = "SENSORS.BLE";
const char L_REGULATOR[] PROGMEM = "REGULATOR";
@@ -49,6 +48,7 @@ const char S_AUTO_FAULT_RESET[] PROGMEM = "autoFaultReset";
const char S_BACKTRACE[] PROGMEM = "backtrace";
const char S_BATTERY[] PROGMEM = "battery";
const char S_BAUDRATE[] PROGMEM = "baudrate";
const char S_BLE[] PROGMEM = "ble";
const char S_BLOCKING[] PROGMEM = "blocking";
const char S_BSSID[] PROGMEM = "bssid";
const char S_BUILD[] PROGMEM = "build";
@@ -56,15 +56,18 @@ const char S_CASCADE_CONTROL[] PROGMEM = "cascadeControl";
const char S_CHANNEL[] PROGMEM = "channel";
const char S_CH2_ALWAYS_ENABLED[] PROGMEM = "ch2AlwaysEnabled";
const char S_CHIP[] PROGMEM = "chip";
const char S_CLK[] PROGMEM = "clk";
const char S_CODE[] PROGMEM = "code";
const char S_COMMIT[] PROGMEM = "commit";
const char S_CONNECTED[] PROGMEM = "connected";
const char S_CONFIGURED[] PROGMEM = "configured";
const char S_CONNECTION_TYPE[] PROGMEM = "connectionType";
const char S_CONTINUES[] PROGMEM = "continues";
const char S_COOLING[] PROGMEM = "cooling";
const char S_COOLING_SUPPORT[] PROGMEM = "coolingSupport";
const char S_CORE[] PROGMEM = "core";
const char S_CORES[] PROGMEM = "cores";
const char S_CRASH[] PROGMEM = "crash";
const char S_CS[] PROGMEM = "cs";
const char S_CURRENT_TEMP[] PROGMEM = "currentTemp";
const char S_DATA[] PROGMEM = "data";
const char S_DATE[] PROGMEM = "date";
@@ -84,11 +87,14 @@ const char S_ENABLED[] PROGMEM = "enabled";
const char S_ENV[] PROGMEM = "env";
const char S_EPC[] PROGMEM = "epc";
const char S_EQUITHERM[] PROGMEM = "equitherm";
const char S_ETHERNET[] PROGMEM = "ethernet";
const char S_EXPONENT[] PROGMEM = "exponent";
const char S_EXTERNAL_PUMP[] PROGMEM = "externalPump";
const char S_FACTOR[] PROGMEM = "factor";
const char S_FAULT[] PROGMEM = "fault";
const char S_FEATURES[] PROGMEM = "features";
const char S_FREEZE_PROTECTION[] PROGMEM = "freezeProtection";
const char S_FREEZING[] PROGMEM = "freezing";
const char S_FILTERING[] PROGMEM = "filtering";
const char S_FILTERING_FACTOR[] PROGMEM = "filteringFactor";
const char S_FLAGS[] PROGMEM = "flags";
@@ -120,6 +126,7 @@ const char S_INPUT[] PROGMEM = "input";
const char S_INTERVAL[] PROGMEM = "interval";
const char S_INVERT_STATE[] PROGMEM = "invertState";
const char S_IP[] PROGMEM = "ip";
const char S_IRQ[] PROGMEM = "irq";
const char S_I_FACTOR[] PROGMEM = "i_factor";
const char S_I_MULTIPLIER[] PROGMEM = "i_multiplier";
const char S_LOGIN[] PROGMEM = "login";
@@ -140,7 +147,9 @@ const char S_MIN_FREE[] PROGMEM = "minFree";
const char S_MIN_MAX_FREE_BLOCK[] PROGMEM = "minMaxFreeBlock";
const char S_MIN_POWER[] PROGMEM = "minPower";
const char S_MIN_TEMP[] PROGMEM = "minTemp";
const char S_MISO[] PROGMEM = "miso";
const char S_MODEL[] PROGMEM = "model";
const char S_MOSI[] PROGMEM = "mosi";
const char S_MODULATION[] PROGMEM = "modulation";
const char S_MQTT[] PROGMEM = "mqtt";
const char S_NAME[] PROGMEM = "name";
@@ -161,13 +170,13 @@ const char S_OVERHEAT_PROTECTION[] PROGMEM = "overheatProtectio
const char S_PASSWORD[] PROGMEM = "password";
const char S_PID[] PROGMEM = "pid";
const char S_PORT[] PROGMEM = "port";
const char S_PINS[] PROGMEM = "pins";
const char S_PORTAL[] PROGMEM = "portal";
const char S_POST_CIRCULATION_TIME[] PROGMEM = "postCirculationTime";
const char S_POWER[] PROGMEM = "power";
const char S_PREFIX[] PROGMEM = "prefix";
const char S_PROTOCOL_VERSION[] PROGMEM = "protocolVersion";
const char S_PURPOSE[] PROGMEM = "purpose";
const char S_PSRAM[] PROGMEM = "psram";
const char S_P_FACTOR[] PROGMEM = "p_factor";
const char S_P_MULTIPLIER[] PROGMEM = "p_multiplier";
const char S_REAL_SIZE[] PROGMEM = "realSize";
@@ -179,6 +188,7 @@ const char S_RESTART[] PROGMEM = "restart";
const char S_RETURN_TEMP[] PROGMEM = "returnTemp";
const char S_REV[] PROGMEM = "rev";
const char S_RSSI[] PROGMEM = "rssi";
const char S_RST[] PROGMEM = "rst";
const char S_RX_LED_GPIO[] PROGMEM = "rxLedGpio";
const char S_SDK[] PROGMEM = "sdk";
const char S_SENSORS[] PROGMEM = "sensors";
@@ -192,6 +202,7 @@ const char S_SIZE[] PROGMEM = "size";
const char S_SLAVE[] PROGMEM = "slave";
const char S_SLOPE[] PROGMEM = "slope";
const char S_SSID[] PROGMEM = "ssid";
const char S_STARTED[] PROGMEM = "started";
const char S_STA[] PROGMEM = "sta";
const char S_STATE[] PROGMEM = "state";
const char S_STATIC_CONFIG[] PROGMEM = "staticConfig";
@@ -204,6 +215,7 @@ const char S_SYSTEM[] PROGMEM = "system";
const char S_TARGET[] PROGMEM = "target";
const char S_TARGET_DIFF_FACTOR[] PROGMEM = "targetDiffFactor";
const char S_TARGET_TEMP[] PROGMEM = "targetTemp";
const char S_TELNET[] PROGMEM = "telnet";
const char S_TEMPERATURE[] PROGMEM = "temperature";
const char S_THRESHOLD_HIGH[] PROGMEM = "thresholdHigh";
const char S_THRESHOLD_LOW[] PROGMEM = "thresholdLow";
@@ -221,4 +233,3 @@ const char S_USE_DHCP[] PROGMEM = "useDhcp";
const char S_USER[] PROGMEM = "user";
const char S_VALUE[] PROGMEM = "value";
const char S_VERSION[] PROGMEM = "version";
const char S_WEBSERIAL[] PROGMEM = "webSerial";
+111 -26
View File
@@ -296,8 +296,24 @@ void networkSettingsToJson(const NetworkSettings& src, JsonVariant dst) {
dst[FPSTR(S_STA)][FPSTR(S_SSID)] = src.sta.ssid;
dst[FPSTR(S_STA)][FPSTR(S_PASSWORD)] = src.sta.password;
dst[FPSTR(S_STA)][FPSTR(S_CHANNEL)] = src.sta.channel;
#if USE_ETHERNET
auto ethernet = dst[FPSTR(S_ETHERNET)].to<JsonObject>();
ethernet[FPSTR(S_ENABLED)] = src.ethernet.enabled;
auto pins = ethernet[FPSTR(S_PINS)].to<JsonObject>();
pins[FPSTR(S_CLK)] = src.ethernet.w5500.clk;
pins[FPSTR(S_MOSI)] = src.ethernet.w5500.mosi;
pins[FPSTR(S_MISO)] = src.ethernet.w5500.miso;
pins[FPSTR(S_CS)] = src.ethernet.w5500.cs;
pins[FPSTR(S_IRQ)] = src.ethernet.w5500.irq;
pins[FPSTR(S_RST)] = src.ethernet.w5500.rst;
#endif
}
bool jsonToEthernetPins(const JsonVariantConst src, NetworkSettings& dst, bool& changed);
bool jsonToNetworkSettings(const JsonVariantConst src, NetworkSettings& dst) {
bool changed = false;
@@ -413,6 +429,19 @@ bool jsonToNetworkSettings(const JsonVariantConst src, NetworkSettings& dst) {
}
}
// ethernet
if (src[FPSTR(S_ETHERNET)][FPSTR(S_ENABLED)].is<bool>()) {
bool value = src[FPSTR(S_ETHERNET)][FPSTR(S_ENABLED)].as<bool>();
if (value != dst.ethernet.enabled) {
dst.ethernet.enabled = value;
changed = true;
}
}
jsonToEthernetPins(src[FPSTR(S_ETHERNET)][FPSTR(S_PINS)], dst, changed);
return changed;
}
@@ -425,8 +454,9 @@ void settingsToJson(const Settings& src, JsonVariant dst, bool safe = false) {
serial[FPSTR(S_ENABLED)] = src.system.serial.enabled;
serial[FPSTR(S_BAUDRATE)] = src.system.serial.baudrate;
auto webSerial = system[FPSTR(S_WEBSERIAL)].to<JsonObject>();
webSerial[FPSTR(S_ENABLED)] = src.system.webSerial.enabled;
auto telnet = system[FPSTR(S_TELNET)].to<JsonObject>();
telnet[FPSTR(S_ENABLED)] = src.system.telnet.enabled;
telnet[FPSTR(S_PORT)] = src.system.telnet.port;
auto ntp = system[FPSTR(S_NTP)].to<JsonObject>();
ntp[FPSTR(S_SERVER)] = src.system.ntp.server;
@@ -504,8 +534,8 @@ void settingsToJson(const Settings& src, JsonVariant dst, bool safe = false) {
heatingOverheatProtection[FPSTR(S_LOW_TEMP)] = src.heating.overheatProtection.lowTemp;
auto freezeProtection = heating[FPSTR(S_FREEZE_PROTECTION)].to<JsonObject>();
freezeProtection[FPSTR(S_HIGH_TEMP)] = src.heating.freezeProtection.highTemp;
freezeProtection[FPSTR(S_LOW_TEMP)] = src.heating.freezeProtection.lowTemp;
freezeProtection[FPSTR(S_THRESHOLD_TIME)] = src.heating.freezeProtection.thresholdTime;
auto dhw = dst[FPSTR(S_DHW)].to<JsonObject>();
dhw[FPSTR(S_ENABLED)] = src.dhw.enabled;
@@ -572,6 +602,55 @@ inline void safeSettingsToJson(const Settings& src, JsonVariant dst) {
settingsToJson(src, dst, true);
}
/**
* @brief Parse a single GPIO value: an empty string means "not configured"
*
* @return true if the key existed in the source document
*/
bool jsonToGpioValue(const JsonVariantConst src, const __FlashStringHelper* key, uint8_t& dst, bool& changed) {
if (src[key].isNull()) {
return false;
}
if (src[key].is<JsonString>() && src[key].as<JsonString>().size() == 0) {
if (dst != GPIO_IS_NOT_CONFIGURED) {
dst = GPIO_IS_NOT_CONFIGURED;
changed = true;
}
return true;
}
unsigned char value = src[key].as<unsigned char>();
if (GPIO_IS_VALID(value) && value != dst) {
dst = value;
changed = true;
}
return true;
}
/**
* @brief Parse the W5500 pinout from an object holding clk/mosi/miso/cs/irq/rst
*
* @return true if the source object exists
*/
bool jsonToEthernetPins(const JsonVariantConst src, NetworkSettings& dst, bool& changed) {
if (src.isNull()) {
return false;
}
jsonToGpioValue(src, FPSTR(S_CLK), dst.ethernet.w5500.clk, changed);
jsonToGpioValue(src, FPSTR(S_MOSI), dst.ethernet.w5500.mosi, changed);
jsonToGpioValue(src, FPSTR(S_MISO), dst.ethernet.w5500.miso, changed);
jsonToGpioValue(src, FPSTR(S_CS), dst.ethernet.w5500.cs, changed);
jsonToGpioValue(src, FPSTR(S_IRQ), dst.ethernet.w5500.irq, changed);
jsonToGpioValue(src, FPSTR(S_RST), dst.ethernet.w5500.rst, changed);
return true;
}
bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false) {
bool changed = false;
@@ -580,7 +659,7 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false
if (!src[FPSTR(S_SYSTEM)][FPSTR(S_LOG_LEVEL)].isNull()) {
uint8_t value = src[FPSTR(S_SYSTEM)][FPSTR(S_LOG_LEVEL)].as<uint8_t>();
if (value != dst.system.logLevel && value >= TinyLoggerLevel::SILENT && value <= TinyLoggerLevel::VERBOSE) {
if (value != dst.system.logLevel && value >= TinyLogger::Level::SILENT && value <= TinyLogger::Level::VERBOSE) {
dst.system.logLevel = value;
changed = true;
}
@@ -606,11 +685,20 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false
}
}
if (src[FPSTR(S_SYSTEM)][FPSTR(S_WEBSERIAL)][FPSTR(S_ENABLED)].is<bool>()) {
bool value = src[FPSTR(S_SYSTEM)][FPSTR(S_WEBSERIAL)][FPSTR(S_ENABLED)].as<bool>();
if (src[FPSTR(S_SYSTEM)][FPSTR(S_TELNET)][FPSTR(S_ENABLED)].is<bool>()) {
bool value = src[FPSTR(S_SYSTEM)][FPSTR(S_TELNET)][FPSTR(S_ENABLED)].as<bool>();
if (value != dst.system.webSerial.enabled) {
dst.system.webSerial.enabled = value;
if (value != dst.system.telnet.enabled) {
dst.system.telnet.enabled = value;
changed = true;
}
}
if (!src[FPSTR(S_SYSTEM)][FPSTR(S_TELNET)][FPSTR(S_PORT)].isNull()) {
unsigned short value = src[FPSTR(S_SYSTEM)][FPSTR(S_TELNET)][FPSTR(S_PORT)].as<unsigned short>();
if (value > 0 && value <= 65535 && value != dst.system.telnet.port) {
dst.system.telnet.port = value;
changed = true;
}
}
@@ -687,7 +775,6 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false
}
}
// portal
if (src[FPSTR(S_PORTAL)][FPSTR(S_AUTH)].is<bool>()) {
bool value = src[FPSTR(S_PORTAL)][FPSTR(S_AUTH)].as<bool>();
@@ -1416,6 +1503,15 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false
changed = true;
}
if (!src[FPSTR(S_HEATING)][FPSTR(S_FREEZE_PROTECTION)][FPSTR(S_HIGH_TEMP)].isNull()) {
unsigned short value = src[FPSTR(S_HEATING)][FPSTR(S_FREEZE_PROTECTION)][FPSTR(S_HIGH_TEMP)].as<uint8_t>();
if (isValidTemp(value, dst.system.unitSystem, 1, 50) && value != dst.heating.freezeProtection.highTemp) {
dst.heating.freezeProtection.highTemp = value;
changed = true;
}
}
if (!src[FPSTR(S_HEATING)][FPSTR(S_FREEZE_PROTECTION)][FPSTR(S_LOW_TEMP)].isNull()) {
unsigned short value = src[FPSTR(S_HEATING)][FPSTR(S_FREEZE_PROTECTION)][FPSTR(S_LOW_TEMP)].as<uint8_t>();
@@ -1425,15 +1521,9 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false
}
}
if (!src[FPSTR(S_HEATING)][FPSTR(S_FREEZE_PROTECTION)][FPSTR(S_THRESHOLD_TIME)].isNull()) {
unsigned short value = src[FPSTR(S_HEATING)][FPSTR(S_FREEZE_PROTECTION)][FPSTR(S_THRESHOLD_TIME)].as<unsigned short>();
if (value >= 30 && value <= 1800) {
if (value != dst.heating.freezeProtection.thresholdTime) {
dst.heating.freezeProtection.thresholdTime = value;
changed = true;
}
}
if (dst.heating.freezeProtection.highTemp < dst.heating.freezeProtection.lowTemp) {
dst.heating.freezeProtection.highTemp = dst.heating.freezeProtection.lowTemp;
changed = true;
}
@@ -1927,8 +2017,6 @@ bool jsonToSensorSettings(const uint8_t sensorId, const JsonVariantConst src, Se
case static_cast<uint8_t>(Sensors::Type::NTC_10K_TEMP):
case static_cast<uint8_t>(Sensors::Type::DALLAS_TEMP):
case static_cast<uint8_t>(Sensors::Type::BLUETOOTH):
case static_cast<uint8_t>(Sensors::Type::DHT11):
case static_cast<uint8_t>(Sensors::Type::DHT22):
case static_cast<uint8_t>(Sensors::Type::HEATING_SETPOINT_TEMP):
case static_cast<uint8_t>(Sensors::Type::MANUAL):
case static_cast<uint8_t>(Sensors::Type::NOT_CONFIGURED):
@@ -1945,8 +2033,7 @@ bool jsonToSensorSettings(const uint8_t sensorId, const JsonVariantConst src, Se
// gpio
if (!src[FPSTR(S_GPIO)].isNull()) {
if (dst.type != Sensors::Type::DALLAS_TEMP && dst.type != Sensors::Type::NTC_10K_TEMP &&
dst.type != Sensors::Type::DHT11 && dst.type != Sensors::Type::DHT22) {
if (dst.type != Sensors::Type::DALLAS_TEMP && dst.type != Sensors::Type::NTC_10K_TEMP) {
if (dst.gpio != GPIO_IS_NOT_CONFIGURED) {
dst.gpio = GPIO_IS_NOT_CONFIGURED;
changed = true;
@@ -2087,10 +2174,6 @@ void sensorResultToJson(const uint8_t sensorId, JsonVariant dst) {
dst[FPSTR(S_BATTERY)] = roundf(rSensor.values[static_cast<uint8_t>(Sensors::ValueType::BATTERY)], 1);
dst[FPSTR(S_RSSI)] = roundf(rSensor.values[static_cast<uint8_t>(Sensors::ValueType::RSSI)], 0);
} else if (sSensor.type == Sensors::Type::DHT11 || sSensor.type == Sensors::Type::DHT22) {
dst[FPSTR(S_TEMPERATURE)] = roundf(rSensor.values[static_cast<uint8_t>(Sensors::ValueType::TEMPERATURE)], 3);
dst[FPSTR(S_HUMIDITY)] = roundf(rSensor.values[static_cast<uint8_t>(Sensors::ValueType::HUMIDITY)], 3);
} else {
dst[FPSTR(S_VALUE)] = roundf(rSensor.values[static_cast<uint8_t>(Sensors::ValueType::PRIMARY)], 3);
}
@@ -2167,6 +2250,7 @@ void varsToJson(const Variables& src, JsonVariant dst) {
mHeating[FPSTR(S_BLOCKING)] = src.master.heating.blocking;
mHeating[FPSTR(S_INDOOR_TEMP_CONTROL)] = src.master.heating.indoorTempControl;
mHeating[FPSTR(S_OVERHEAT)] = src.master.heating.overheat;
mHeating[FPSTR(S_FREEZING)] = src.master.heating.freezing;
mHeating[FPSTR(S_SETPOINT_TEMP)] = roundf(src.master.heating.setpointTemp, 2);
mHeating[FPSTR(S_TARGET_TEMP)] = roundf(src.master.heating.targetTemp, 2);
mHeating[FPSTR(S_CURRENT_TEMP)] = roundf(src.master.heating.currentTemp, 2);
@@ -2187,6 +2271,7 @@ void varsToJson(const Variables& src, JsonVariant dst) {
master[FPSTR(S_NETWORK)][FPSTR(S_CONNECTED)] = src.network.connected;
master[FPSTR(S_NETWORK)][FPSTR(S_RSSI)] = src.network.rssi;
master[FPSTR(S_NETWORK)][FPSTR(S_CONNECTION_TYPE)] = NetworkUtils::NetworkMgr::uplinkName(src.network.connectionType);
master[FPSTR(S_MQTT)][FPSTR(S_CONNECTED)] = src.mqtt.connected;
master[FPSTR(S_EMERGENCY)][FPSTR(S_STATE)] = src.emergency.state;
master[FPSTR(S_EXTERNAL_PUMP)][FPSTR(S_STATE)] = src.externalPump.state;
+38 -10
View File
@@ -44,7 +44,6 @@
"build": {
"title": "Build",
"version": "固件版本",
"commit": "Commit",
"date": "日期",
"core": "内核版本",
"sdk": "SDK"
@@ -152,6 +151,7 @@
"section": {
"static": "静态设置",
"ethernet": "以太网",
"availableNetworks": "可用网络",
"staSettings": "WiFi 设置",
"apSettings": "AP 设置"
@@ -159,7 +159,20 @@
"scan": {
"pos": "#",
"info": "Info"
"info": "Info",
"unavailable": "请启用 WiFi 以扫描网络"
},
"ethernet": {
"enable": "启用以太网",
"notConfigured": "填写全部六个 GPIO 引脚后才能启用以太网。",
"clk": "SPI 时钟 GPIO",
"mosi": "SPI MOSI GPIO",
"miso": "SPI MISO GPIO",
"cs": "SPI CS GPIO",
"irq": "中断 GPIO",
"rst": "复位 GPIO",
"note": "W5500 SPI 接线"
},
"wifi": {
@@ -177,7 +190,14 @@
"ip": "IP",
"subnet": "子网掩码",
"gateway": "网关",
"dns": "DNS 服务器"
"dns": "DNS 服务器",
"connection": "连接",
"connectionType": {
"ethernet": "以太网",
"wifi": "WiFi",
"wifi-ap": "WiFi 接入点",
"none": "无"
}
},
"sta": {
@@ -249,8 +269,6 @@
"ntcTemp": "NTC 传感器",
"dallasTemp": "DALLAS 传感器",
"bluetooth": "BLE 传感器",
"dht11": "DHT11 传感器",
"dht22": "DHT22 传感器",
"heatSetpointTemp": "Heating, setpoint temp",
"manual": "通过 MQTT/API 手动配置",
"notConfigured": "未配置"
@@ -323,9 +341,15 @@
},
"freezeProtection": {
"title": "防冻保护",
"desc": "当热媒或室内温度在<b>等待时间</b> 内降至<b>低温阈值</b>以下时,系统将强制启动加热功能。",
"lowTemp": "低温阈值",
"thresholdTime": "等待时间<small>(秒)</small>"
"desc": "如果热载体或室内温度低于 <b>低温</b>,加热将被强制开启。",
"highTemp": {
"title": "高温阈值",
"note": "防冻保护激活后系统恢复正常模式的阈值"
},
"lowTemp": {
"title": "低温阈值",
"note": "强制开启加热的阈值"
}
},
"portal": {
@@ -345,8 +369,12 @@
"enable": "启用串口",
"baud": "串口波特率"
},
"webSerial": {
"enable": "启用 WebSerial"
"telnet": {
"enable": "启用 Telnet",
"port": {
"title": "Telnet 端口",
"note": "默认值:23"
}
},
"ntp": {
"server": "NTP服务器",
+39 -10
View File
@@ -44,7 +44,6 @@
"build": {
"title": "Build",
"version": "Version",
"commit": "Commit",
"date": "Date",
"core": "Core",
"sdk": "SDK"
@@ -120,6 +119,7 @@
"mHeatEnabled": "Heating enabled",
"mHeatBlocking": "Heating blocked",
"mHeatOverheat": "Heating overheat",
"mHeatFreezing": "Heating freezing",
"sHeatActive": "Heating active",
"mHeatSetpointTemp": "Heating setpoint temp",
"mHeatTargetTemp": "Heating target temp",
@@ -152,6 +152,7 @@
"section": {
"static": "Static settings",
"ethernet": "Ethernet",
"availableNetworks": "Available networks",
"staSettings": "WiFi settings",
"apSettings": "AP settings"
@@ -159,7 +160,20 @@
"scan": {
"pos": "#",
"info": "Info"
"info": "Info",
"unavailable": "Please enable WiFi to scan for networks"
},
"ethernet": {
"enable": "Enable ethernet",
"notConfigured": "Fill in all six GPIO pins to enable ethernet.",
"clk": "SPI clock GPIO",
"mosi": "SPI MOSI GPIO",
"miso": "SPI MISO GPIO",
"cs": "SPI CS GPIO",
"irq": "Interrupt GPIO",
"rst": "Reset GPIO",
"note": "W5500 SPI wiring"
},
"wifi": {
@@ -177,7 +191,14 @@
"ip": "IP",
"subnet": "Subnet",
"gateway": "Gateway",
"dns": "DNS"
"dns": "DNS",
"connection": "Connection",
"connectionType": {
"ethernet": "Ethernet",
"wifi": "WiFi",
"wifi-ap": "WiFi AP",
"none": "None"
}
},
"sta": {
@@ -249,8 +270,6 @@
"ntcTemp": "NTC sensor",
"dallasTemp": "DALLAS sensor",
"bluetooth": "BLE sensor",
"dht11": "DHT11 sensor",
"dht22": "DHT22 sensor",
"heatSetpointTemp": "Heating, setpoint temp",
"manual": "Manual via MQTT/API",
"notConfigured": "Not configured"
@@ -323,9 +342,15 @@
},
"freezeProtection": {
"title": "Freeze protection",
"desc": "Heating will be forced to turn on if the heat carrier or indoor temperature drops below <b>Low temperature</b> during <b>Waiting time</b>.",
"lowTemp": "Low temperature threshold",
"thresholdTime": "Waiting time <small>(sec)</small>"
"desc": "Heating will be forced to turn on if the heat carrier or indoor temperature drops below <b>Low temperature</b>.",
"highTemp": {
"title": "High temperature threshold",
"note": "Threshold when the system returns to normal mode after freeze protection activation"
},
"lowTemp": {
"title": "Low temperature threshold",
"note": "Threshold when heating is forced to turn on"
}
},
"portal": {
@@ -345,8 +370,12 @@
"enable": "Enabled Serial port",
"baud": "Serial port baud rate"
},
"webSerial": {
"enable": "Enabled WebSerial"
"telnet": {
"enable": "Enabled Telnet",
"port": {
"title": "Telnet port",
"note": "Default: 23"
}
},
"ntp": {
"server": "NTP server",
+38 -10
View File
@@ -44,7 +44,6 @@
"build": {
"title": "Build",
"version": "Versione",
"commit": "Commit",
"date": "Data",
"core": "Core",
"sdk": "SDK"
@@ -152,6 +151,7 @@
"section": {
"static": "Impostazioni statico",
"ethernet": "Ethernet",
"availableNetworks": "Reti disponibili",
"staSettings": "Impostazioni WiFi",
"apSettings": "Impostazioni AP"
@@ -159,7 +159,20 @@
"scan": {
"pos": "#",
"info": "Info"
"info": "Info",
"unavailable": "Abilita il WiFi per cercare le reti"
},
"ethernet": {
"enable": "Abilita ethernet",
"notConfigured": "Compilare tutti e sei i pin GPIO per abilitare ethernet.",
"clk": "GPIO clock SPI",
"mosi": "GPIO MOSI SPI",
"miso": "GPIO MISO SPI",
"cs": "GPIO CS SPI",
"irq": "GPIO interrupt",
"rst": "GPIO reset",
"note": "Cablaggio SPI del W5500"
},
"wifi": {
@@ -177,7 +190,14 @@
"ip": "IP",
"subnet": "Subnet",
"gateway": "Gateway",
"dns": "DNS"
"dns": "DNS",
"connection": "Connessione",
"connectionType": {
"ethernet": "Ethernet",
"wifi": "WiFi",
"wifi-ap": "WiFi AP",
"none": "Nessuno"
}
},
"sta": {
@@ -249,8 +269,6 @@
"ntcTemp": "Sensore NTC",
"dallasTemp": "Sensore DALLAS",
"bluetooth": "Sensore BLE",
"dht11": "Sensore DHT11",
"dht22": "Sensore DHT22",
"heatSetpointTemp": "Riscaldamento, temp impostata",
"manual": "Manuale via MQTT/API",
"notConfigured": "Non configurato"
@@ -323,9 +341,15 @@
},
"freezeProtection": {
"title": "Protezione antigelo",
"desc": "Il riscaldamento verrà attivato forzatamente se la temperatura del vettore di calore o interna scende al di sotto della <b>temperatura minima</b> durante il <b>tempo di attesa</b>.",
"lowTemp": "Soglia di temperatura minima",
"thresholdTime": "Tempo di attesa <small>(sec)</small>"
"desc": "Il riscaldamento verrà forzatamente attivato se la temperatura del vettore termico o la temperatura interna scende al di sotto della <b>Soglia di temperatura bassa</b>.",
"highTemp": {
"title": "Soglia di temperatura alta",
"note": "Soglia quando il sistema ritorna alla modalità normale dopo l'attivazione della protezione antigelo"
},
"lowTemp": {
"title": "Soglia di temperatura bassa",
"note": "Soglia quando il riscaldamento viene forzatamente attivato"
}
},
"portal": {
@@ -345,8 +369,12 @@
"enable": "Porta seriale attivata",
"baud": "Porta seriale baud rate"
},
"webSerial": {
"enable": "WebSerial attivato"
"telnet": {
"enable": "Telnet attivato",
"port": {
"title": "Porta Telnet",
"note": "Default: 23"
}
},
"ntp": {
"server": "NTP server",
+40 -11
View File
@@ -40,7 +40,6 @@
"build": {
"title": "Build",
"version": "Versie",
"commit": "Commit",
"date": "Datum",
"core": "Core",
"sdk": "SDK"
@@ -137,13 +136,27 @@
"name": "Netwerkinstellingen",
"section": {
"static": "Statische instellingen",
"ethernet": "Ethernet",
"availableNetworks": "Beschikbare netwerken",
"staSettings": "WiFi-instellingen",
"apSettings": "AP-instellingen"
},
"scan": {
"pos": "#",
"info": "Info"
"info": "Info",
"unavailable": "Schakel WiFi in om naar netwerken te zoeken"
},
"ethernet": {
"enable": "Ethernet inschakelen",
"notConfigured": "Vul alle zes GPIO-pinnen in om ethernet in te schakelen.",
"clk": "SPI-klok GPIO",
"mosi": "SPI MOSI GPIO",
"miso": "SPI MISO GPIO",
"cs": "SPI CS GPIO",
"irq": "Interrupt GPIO",
"rst": "Reset GPIO",
"note": "W5500 SPI-bedrading"
},
"wifi": {
"ssid": "SSID",
@@ -159,7 +172,14 @@
"ip": "IP",
"subnet": "Subnet",
"gateway": "Gateway",
"dns": "DNS"
"dns": "DNS",
"connection": "Verbinding",
"connectionType": {
"ethernet": "Ethernet",
"wifi": "WiFi",
"wifi-ap": "WiFi AP",
"none": "Geen"
}
},
"sta": {
"channel.note": "zet op 0 voor automatische selectie"
@@ -228,8 +248,6 @@
"ntcTemp": "NTC-sensor",
"dallasTemp": "DALLAS-sensor",
"bluetooth": "BLE-sensor",
"dht11": "DHT11-sensor",
"dht22": "DHT22-sensor",
"heatSetpointTemp": "Verwarming, insteltemperatuur",
"manual": "Handmatig via MQTT/API",
"notConfigured": "Niet geconfigureerd"
@@ -297,11 +315,18 @@
}
},
"freezeProtection": {
"title": "Vorstbeveiliging",
"desc": "De verwarming wordt geforceerd ingeschakeld als de temperatuur van de warmtedrager of de binnentemperatuur onder de <b>Lage temperatuur</b> daalt gedurende de <b>Wachttijd</b>.",
"lowTemp": "Drempelwaarde lage temperatuur",
"thresholdTime": "Wachttijd <small>(sec)</small>"
"title": "Vorbeveiliging",
"desc": "Verwarming zal geforceerd worden ingeschakeld als de temperatuur van de warmtedrager of de binnentemperatuur daalt onder de <b>Lage temperatuurdrempel</b>.",
"highTemp": {
"title": "Hoge temperatuurdrempel",
"note": "Drempel waarna het systeem terugkeert naar de normale modus na activering van de vorbeveiliging"
},
"lowTemp": {
"title": "Lage temperatuurdrempel",
"note": "Drempel wanneer de verwarming geforceerd wordt ingeschakeld"
}
},
"portal": {
"login": "Gebruikersnaam",
"password": "Wachtwoord",
@@ -318,8 +343,12 @@
"enable": "Seriële poort ingeschakeld",
"baud": "Baudrate seriële poort"
},
"webSerial": {
"enable": "WebSerial ingeschakeld"
"telnet": {
"enable": "Telnet ingeschakeld",
"port": {
"title": "Telnet-poort",
"note": "Standaard: 23"
}
},
"ntp": {
"server": "NTP-server",
+38 -10
View File
@@ -44,7 +44,6 @@
"build": {
"title": "Билд",
"version": "Версия",
"commit": "Коммит",
"date": "Дата",
"core": "Ядро",
"sdk": "SDK"
@@ -152,6 +151,7 @@
"section": {
"static": "Статические параметры",
"ethernet": "Ethernet",
"availableNetworks": "Доступные сети",
"staSettings": "Настройки подключения",
"apSettings": "Настройки точки доступа"
@@ -159,7 +159,20 @@
"scan": {
"pos": "#",
"info": "Инфо"
"info": "Инфо",
"unavailable": "Включите WiFi, чтобы искать сети"
},
"ethernet": {
"enable": "Включить ethernet",
"notConfigured": "Заполните все шесть выводов GPIO, чтобы включить ethernet.",
"clk": "GPIO тактирования SPI",
"mosi": "GPIO MOSI SPI",
"miso": "GPIO MISO SPI",
"cs": "GPIO CS SPI",
"irq": "GPIO прерывания",
"rst": "GPIO сброса",
"note": "Подключение W5500 по SPI"
},
"wifi": {
@@ -177,7 +190,14 @@
"ip": "IP адрес",
"subnet": "Адрес подсети",
"gateway": "Адрес шлюза",
"dns": "DNS адрес"
"dns": "DNS адрес",
"connection": "Подключение",
"connectionType": {
"ethernet": "Ethernet",
"wifi": "WiFi",
"wifi-ap": "WiFi AP",
"none": "Нет"
}
},
"sta": {
@@ -249,8 +269,6 @@
"ntcTemp": "NTC датчик",
"dallasTemp": "DALLAS датчик",
"bluetooth": "BLE датчик",
"dht11": "DHT11 датчик",
"dht22": "DHT22 датчик",
"heatSetpointTemp": "Отопление, температура уставки",
"manual": "Вручную через MQTT/API",
"notConfigured": "Не сконфигурировано"
@@ -323,9 +341,15 @@
},
"freezeProtection": {
"title": "Защита от замерзания",
"desc": "Отопление будет принудительно включено, если темп. теплоносителя или внутренняя темп. опустится ниже <b>нижнего порога</b> в течение <b>времени ожидания</b>.",
"lowTemp": "Нижний порог температуры",
"thresholdTime": "Время ожидания <small>(сек)</small>"
"desc": "Отопление будет принудительно включено, если темп. теплоносителя или внутренняя темп. опустится ниже <b>нижнего порога</b>.",
"highTemp": {
"title": "Верхний порог температуры",
"note": "Порог, при котором система вернется в нормальное состояние после активации защиты от замерзания"
},
"lowTemp": {
"title": "Нижний порог температуры",
"note": "Порог, при котором отопление будет принудительно включено"
}
},
"portal": {
@@ -345,8 +369,12 @@
"enable": "Вкл. Serial порт",
"baud": "Скорость Serial порта"
},
"webSerial": {
"enable": "Вкл. WebSerial"
"telnet": {
"enable": "Вкл. Telnet",
"port": {
"title": "Telnet порт",
"note": "По умолчанию: 23"
}
},
"ntp": {
"server": "NTP сервер",
+10 -4
View File
@@ -195,6 +195,10 @@
<th scope="row" data-i18n>dashboard.states.mHeatOverheat</th>
<td><i class="mHeatOverheat"></i></td>
</tr>
<tr>
<th scope="row" data-i18n>dashboard.states.mHeatFreezing</th>
<td><i class="mHeatFreezing"></i></td>
</tr>
<tr>
<th scope="row" data-i18n>dashboard.states.sHeatActive</th>
<td><i class="sHeatActive"></i></td>
@@ -320,7 +324,7 @@
document.addEventListener('DOMContentLoaded', async () => {
const lang = new Lang(document.getElementById('lang'));
lang.build();
await lang.build();
let actionTimer = null;
let actionLongPress = false;
@@ -491,9 +495,6 @@
if (modified) {
parameters.method = "POST";
parameters.body = JSON.stringify(newSettings);
parameters.headers = {
"Content-Type": "application/json"
};
}
const response = await fetch("/api/settings", parameters);
@@ -636,6 +637,11 @@
result.master.heating.overheat ? "success" : "error",
result.master.heating.overheat ? "red" : "green"
);
setStatus(
'.mHeatFreezing',
result.master.heating.freezing ? "success" : "error",
result.master.heating.freezing ? "red" : "green"
);
setValue('.mHeatSetpointTemp', result.master.heating.setpointTemp);
setValue('.mHeatTargetTemp', result.master.heating.targetTemp);
setValue('.mHeatCurrTemp', result.master.heating.currentTemp);
+16 -5
View File
@@ -50,15 +50,19 @@
<th scope="row" data-i18n>network.params.mac</th>
<td><b id="network-mac"></b></td>
</tr>
<tr>
<th scope="row" data-i18n>network.params.connection</th>
<td><b id="network-connection"></b></td>
</tr>
<tr>
<th scope="row" data-i18n>network.wifi.connected</th>
<td><i id="network-connected"></i></td>
</tr>
<tr>
<tr id="network-ssid-row">
<th scope="row" data-i18n>network.wifi.ssid</th>
<td><b id="network-ssid"></b></td>
</tr>
<tr>
<tr id="network-signal-row">
<th scope="row" data-i18n>network.wifi.signal</th>
<td><b id="network-signal"></b> %</td>
</tr>
@@ -104,7 +108,6 @@
<th scope="row" data-i18n>index.system.build.title</th>
<td>
Env: <b id="build-env"></b><br />
<span data-i18n>index.system.build.commit</span>: <b id="build-commit"></b><br />
<span data-i18n>index.system.build.date</span>: <b id="build-date"></b><br />
<span data-i18n>index.system.build.core</span>: <b id="build-core"></b><br />
<span data-i18n>index.system.build.sdk</span>: <b id="build-sdk"></b>
@@ -170,7 +173,7 @@
<script>
document.addEventListener('DOMContentLoaded', async () => {
const lang = new Lang(document.getElementById('lang'));
lang.build();
await lang.build();
setTimeout(async function onLoadPage() {
try {
@@ -193,6 +196,7 @@
setValue('#network-hostname', result.network.hostname);
setValue('#network-mac', result.network.mac);
setValue('#network-connection', i18n(`network.params.connectionType.${result.network.connectionType}`));
setStatus(
'#network-connected',
result.network.connected ? "success" : "error",
@@ -200,6 +204,14 @@
);
setValue('#network-ssid', result.network.ssid);
setValue('#network-signal', result.network.signalQuality);
// SSID and signal strength only describe the uplink when WiFi carries it; with
// ethernet up the radio is parked and both values are meaningless
const wifiUplink = result.network.connectionType === "wifi";
document.getElementById("network-ssid-row")?.classList.toggle("hidden", !wifiUplink);
document.getElementById("network-signal-row")?.classList.toggle("hidden", !wifiUplink);
setValue('#network-ip', result.network.ip);
setValue('#network-subnet', result.network.subnet);
setValue('#network-gateway', result.network.gateway);
@@ -207,7 +219,6 @@
setBusy('#main-busy', '#main-table', false);
setValue('#build-version', result.build.version);
setValue('#build-commit', result.build.commit);
setValue('#build-date', result.build.date);
setValue('#build-env', result.build.env);
setValue('#build-core', result.build.core);
+116 -7
View File
@@ -79,6 +79,7 @@
</div>
</article>
<article>
<div>
<hgroup>
@@ -100,6 +101,7 @@
</table>
</div>
<p id="scan-unavailable" class="hidden" data-i18n>network.scan.unavailable</p>
<button type="submit" data-i18n>button.refresh</button>
</form>
@@ -162,6 +164,62 @@
</form>
</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">
<label>
<input type="checkbox" name="ethernet[enabled]" value="true">
<span data-i18n>network.ethernet.enable</span>
</label>
<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[pins][clk]" min="0" max="254" step="1">
</label>
<label>
<span data-i18n>network.ethernet.mosi</span>
<input type="number" inputmode="numeric" name="ethernet[pins][mosi]" min="0" max="254" step="1">
</label>
<label>
<span data-i18n>network.ethernet.miso</span>
<input type="number" inputmode="numeric" name="ethernet[pins][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[pins][cs]" min="0" max="254" step="1">
</label>
<label>
<span data-i18n>network.ethernet.irq</span>
<input type="number" inputmode="numeric" name="ethernet[pins][irq]" min="0" max="254" step="1">
</label>
<label>
<span data-i18n>network.ethernet.rst</span>
<input type="number" inputmode="numeric" name="ethernet[pins][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>
</article>
</main>
<footer class="container">
@@ -179,7 +237,7 @@
<script>
document.addEventListener('DOMContentLoaded', async () => {
const lang = new Lang(document.getElementById('lang'));
lang.build();
await lang.build();
const fillData = (data) => {
setInputValue("[name='hostname']", data.hostname);
@@ -190,6 +248,29 @@
setInputValue("[name='staticConfig[dns]']", data.staticConfig.dns);
setBusy('#network-settings-busy', '#network-settings', false);
const ethernet = data.ethernet || {};
const ethernetConfigured = !!ethernet.configured;
const ethernetPins = ethernet.pins || {};
const pinValue = (value) => (value ?? 255) < 255 ? value : '';
setInputValue("[name='ethernet[pins][clk]']", pinValue(ethernetPins.clk));
setInputValue("[name='ethernet[pins][mosi]']", pinValue(ethernetPins.mosi));
setInputValue("[name='ethernet[pins][miso]']", pinValue(ethernetPins.miso));
setInputValue("[name='ethernet[pins][cs]']", pinValue(ethernetPins.cs));
setInputValue("[name='ethernet[pins][irq]']", pinValue(ethernetPins.irq));
setInputValue("[name='ethernet[pins][rst]']", pinValue(ethernetPins.rst));
setCheckboxValue("[name='ethernet[enabled]']", ethernetConfigured ? !!ethernet.enabled : false);
const ethernetCheckbox = document.querySelector("[name='ethernet[enabled]']");
if (ethernetCheckbox) {
ethernetCheckbox.disabled = !ethernetConfigured;
}
document.getElementById('ethernet-not-configured')?.classList.toggle('hidden', ethernetConfigured);
setBusy('#ethernet-settings-busy', '#ethernet-settings', false);
setInputValue("[name='sta[ssid]']", data.sta.ssid);
setInputValue("[name='sta[password]']", data.sta.password);
setInputValue("[name='sta[channel]']", data.sta.channel);
@@ -201,21 +282,49 @@
setBusy('#ap-settings-busy', '#ap-settings', false);
};
const applyCapabilities = (info) => {
// pages and firmware ship together: the section stays hidden unless the build says it can do ethernet
const supported = info?.features?.ethernet === true;
document.getElementById('ethernet-section')?.classList.toggle('hidden', !supported);
return supported;
};
try {
const response = await fetch("/api/network/settings", {
cache: "no-cache",
credentials: "include"
});
const [response, infoResponse] = await Promise.all([
fetch("/api/network/settings", {
cache: "no-cache",
credentials: "include"
}),
fetch("/api/info", {
cache: "no-cache",
credentials: "include"
})
]);
if (!response.ok) {
throw new Error('Response not valid');
}
const info = infoResponse.ok ? await infoResponse.json() : null;
const ethernetSupported = applyCapabilities(info);
const result = await response.json();
fillData(result);
setupForm('#network-settings', fillData, ['hostname']);
setupNetworkScanForm('#network-scan', '#networks');
// scanning needs the radio, which stays parked while ethernet carries the uplink
const radioParked = info?.network?.connectionType === 'ethernet';
setupNetworkScanForm('#network-scan', '#networks', !radioParked);
document.querySelector('#network-scan button[type="submit"]').disabled = radioParked;
document.querySelector('#scan-unavailable').classList.toggle('hidden', !radioParked);
if (ethernetSupported) {
setupForm('#ethernet-settings', fillData);
}
setupForm('#sta-settings', fillData, ['sta.ssid', 'sta.password']);
setupForm('#ap-settings', fillData, ['ap.ssid', 'ap.password']);
+39 -19
View File
@@ -38,6 +38,8 @@
<p></p>
</hgroup>
<small id="ble-not-supported" class="hidden" data-i18n>settings.note.bleDevice</small>
<details id="template" class="sensor hidden" data-id="" data-preloaded="0">
<summary><b>#<span class="pos"></span>: <span class="name"></span></b></summary>
@@ -117,9 +119,7 @@
<option value="50" data-i18n>sensors.types.ntcTemp</option>
<option value="51" data-i18n>sensors.types.dallasTemp</option>
<option value="52" data-i18n>sensors.types.bluetooth</option>
<option value="53" data-i18n>sensors.types.dht11</option>
<option value="54" data-i18n>sensors.types.dht22</option>
<option value="52" data-requires="ble" disabled data-i18n>sensors.types.bluetooth</option>
<option value="253" data-i18n>sensors.types.heatSetpointTemp</option>
<option value="254" data-i18n>sensors.types.manual</option>
<option value="255" data-i18n>sensors.types.notConfigured</option>
@@ -203,21 +203,43 @@
<script>
document.addEventListener("DOMContentLoaded", async () => {
const lang = new Lang(document.getElementById("lang"));
lang.build();
await lang.build();
const container = document.querySelector("article");
const templateNode = container.querySelector("#template");
try {
const response = await fetch("/api/sensors", {
cache: "no-cache",
credentials: "include"
let bleSupported = false;
const applyCapabilities = (info, root) => {
// pages and firmware ship together: BLE stays disabled unless the build says it has the stack
bleSupported = info?.features?.ble === true;
root.querySelectorAll('[data-requires="ble"]').forEach((option) => {
option.disabled = !bleSupported;
});
document.getElementById("ble-not-supported")?.classList.toggle("hidden", bleSupported);
};
try {
const [response, infoResponse] = await Promise.all([
fetch("/api/sensors", {
cache: "no-cache",
credentials: "include"
}),
fetch("/api/info", {
cache: "no-cache",
credentials: "include"
})
]);
if (!response.ok) {
throw new Error("Response not valid");
}
const info = infoResponse.ok ? await infoResponse.json() : null;
applyCapabilities(info, templateNode);
const result = await response.json();
for (const sensorId in result) {
const sensorNode = templateNode.cloneNode(true);
@@ -273,35 +295,33 @@
}
switch(parseInt(event.target.value)) {
// NTC10K
// ntc
case 50:
parentGpio.classList.remove("hidden");
parentAddress.classList.add("hidden");
address.removeAttribute("pattern");
break;
// OneWire
// dallas
case 51:
parentGpio.classList.remove("hidden");
parentAddress.classList.remove("hidden");
address.setAttribute("pattern", "([A-Fa-f0-9]{2}:){7}[A-Fa-f0-9]{2}");
break;
// Bluetooth
// ble
case 52:
if (!bleSupported) {
parentGpio.classList.add("hidden");
parentAddress.classList.add("hidden");
break;
}
parentGpio.classList.add("hidden");
parentAddress.classList.remove("hidden");
address.setAttribute("pattern", "([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}");
break;
// DHT
case 53:
case 54:
parentGpio.classList.remove("hidden");
parentAddress.classList.add("hidden");
address.removeAttribute("pattern");
break;
// other
default:
parentGpio.classList.add("hidden");
+21 -9
View File
@@ -126,8 +126,8 @@
</label>
<label>
<input type="checkbox" name="system[webSerial][enabled]" value="true">
<span data-i18n>settings.system.webSerial.enable</span>
<input type="checkbox" name="system[telnet][enabled]" value="true">
<span data-i18n>settings.system.telnet.enable</span>
</label>
<label>
@@ -156,6 +156,12 @@
<option value="115200">115200</option>
</select>
</label>
<label>
<span data-i18n>settings.system.telnet.port.title</span>
<input type="number" inputmode="numeric" name="system[telnet][port]" min="1" max="65535" step="1" required>
<small data-i18n>settings.system.telnet.port.note</small>
</label>
</div>
<mark data-i18n>settings.note.restart</mark>
@@ -259,13 +265,15 @@
<div class="grid">
<label>
<span data-i18n>settings.freezeProtection.lowTemp</span>
<input type="number" inputmode="numeric" name="heating[freezeProtection][lowTemp]" min="0" max="0" step="1" required>
<span data-i18n>settings.freezeProtection.highTemp.title</span>
<input type="number" inputmode="numeric" name="heating[freezeProtection][highTemp]" min="0" max="0" step="1" required>
<small data-i18n>settings.freezeProtection.highTemp.note</small>
</label>
<label>
<span data-i18n>settings.freezeProtection.thresholdTime</span>
<input type="number" inputmode="numeric" name="heating[freezeProtection][thresholdTime]" min="30" max="1800" step="1" required>
<span data-i18n>settings.freezeProtection.lowTemp.title</span>
<input type="number" inputmode="numeric" name="heating[freezeProtection][lowTemp]" min="0" max="0" step="1" required>
<small data-i18n>settings.freezeProtection.lowTemp.note</small>
</label>
</div>
@@ -919,7 +927,7 @@
<script>
document.addEventListener('DOMContentLoaded', async () => {
const lang = new Lang(document.getElementById('lang'));
lang.build();
await lang.build();
let etChart = null;
let etChartConfig = {
@@ -1077,7 +1085,8 @@
setSelectValue("[name='system[logLevel]']", data.system.logLevel);
setCheckboxValue("[name='system[serial][enabled]']", data.system.serial.enabled);
setSelectValue("[name='system[serial][baudrate]']", data.system.serial.baudrate);
setCheckboxValue("[name='system[webSerial][enabled]']", data.system.webSerial.enabled);
setCheckboxValue("[name='system[telnet][enabled]']", data.system.telnet.enabled);
setInputValue("[name='system[telnet][port]']", data.system.telnet.port);
setInputValue("[name='system[ntp][server]']", data.system.ntp.server);
setInputValue("[name='system[ntp][timezone]']", data.system.ntp.timezone);
setRadioValue("[name='system[unitSystem]']", data.system.unitSystem);
@@ -1177,11 +1186,14 @@
"min": 0,
"max": data.system.unitSystem == 0 ? 99 : 211
});
setInputValue("[name='heating[freezeProtection][highTemp]']", data.heating.freezeProtection.highTemp, {
"min": data.system.unitSystem == 0 ? 1 : 34,
"max": data.system.unitSystem == 0 ? 50 : 122
});
setInputValue("[name='heating[freezeProtection][lowTemp]']", data.heating.freezeProtection.lowTemp, {
"min": data.system.unitSystem == 0 ? 1 : 34,
"max": data.system.unitSystem == 0 ? 30 : 86
});
setInputValue("[name='heating[freezeProtection][thresholdTime]']", data.heating.freezeProtection.thresholdTime);
setBusy('#heating-settings-busy', '#heating-settings', false);
// DHW
+8 -124
View File
@@ -62,19 +62,19 @@
<form action="/api/upgrade" id="upgrade">
<fieldset class="primary">
<label>
<label for="firmware-file">
<span data-i18n>upgrade.fw</span>:
<div class="grid">
<input type="file" name="fw" accept=".bin">
<button type="button" class="fwResult hidden" disabled></button>
<input type="file" name="firmware" id="firmware-file" accept=".bin">
<button type="button" class="upgrade-firmware-result hidden" disabled></button>
</div>
</label>
<label>
<label for="filesystem-file">
<span data-i18n>upgrade.fs</span>:
<div class="grid">
<input type="file" name="fs" accept=".bin">
<button type="button" class="fsResult hidden" disabled></button>
<input type="file" name="filesystem" id="filesystem-file" accept=".bin">
<button type="button" class="upgrade-filesystem-result hidden" disabled></button>
</div>
</label>
</fieldset>
@@ -105,126 +105,10 @@
<script>
document.addEventListener('DOMContentLoaded', async () => {
const lang = new Lang(document.getElementById('lang'));
lang.build();
await lang.build();
setupRestoreBackupForm('#restore');
const upgradeForm = document.querySelector('#upgrade');
if (upgradeForm) {
upgradeForm.reset();
const statusToText = (status) => {
switch (status) {
case 0:
return "None";
case 1:
return "No file";
case 2:
return "Success";
case 3:
return "Prohibited";
case 4:
return "Size mismatch";
case 5:
return "Error on start";
case 6:
return "Error on write";
case 7:
return "Error on finish";
default:
return "Unknown";
}
};
upgradeForm.addEventListener('submit', async (event) => {
event.preventDefault();
hide('.fwResult');
hide('.fsResult');
let button = upgradeForm.querySelector('button[type="submit"]');
button.textContent = i18n('button.uploading');
button.setAttribute('disabled', true);
button.setAttribute('aria-busy', true);
try {
let fd = new FormData();
const fw = upgradeForm.querySelector("[name='fw']").files;
if (fw.length > 0) {
fd.append("fw_size", fw[0].size);
fd.append("fw", fw[0]);
}
const fs = upgradeForm.querySelector("[name='fs']").files;
if (fs.length > 0) {
fd.append("fs_size", fs[0].size);
fd.append("fs", fs[0]);
}
let response = await fetch(upgradeForm.action, {
method: "POST",
cache: "no-cache",
credentials: "include",
body: fd
});
if (response.status != 202 && response.status != 406) {
throw new Error('Response not valid');
}
const result = await response.json();
let resItem = upgradeForm.querySelector('.fwResult');
if (resItem && result.firmware.status > 1) {
resItem.textContent = statusToText(result.firmware.status);
resItem.classList.remove('hidden');
if (result.firmware.status == 2) {
resItem.classList.remove('failed');
resItem.classList.add('success');
} else {
resItem.classList.remove('success');
resItem.classList.add('failed');
if (result.firmware.error != "") {
resItem.textContent += `: ${result.firmware.error}`;
}
}
}
resItem = upgradeForm.querySelector('.fsResult');
if (resItem && result.filesystem.status > 1) {
resItem.textContent = statusToText(result.filesystem.status);
resItem.classList.remove('hidden');
if (result.filesystem.status == 2) {
resItem.classList.remove('failed');
resItem.classList.add('success');
} else {
resItem.classList.remove('success');
resItem.classList.add('failed');
if (result.filesystem.error != "") {
resItem.textContent += `: ${result.filesystem.error}`;
}
}
}
} catch (err) {
console.log(err);
button.textContent = i18n('button.error');
button.classList.add('failed');
} finally {
setTimeout(() => {
button.removeAttribute('aria-busy');
button.removeAttribute('disabled');
button.classList.remove('success', 'failed');
button.textContent = i18n(button.dataset.i18n);
upgradeForm.reset();
}, 10000);
}
});
}
setupUpgradeForm('#upgrade');
});
</script>
</body>
+16 -20
View File
@@ -92,7 +92,7 @@ const setupForm = (formSelector, onResultCallback = null, noCastItems = []) => {
});
}
const setupNetworkScanForm = (formSelector, tableSelector) => {
const setupNetworkScanForm = (formSelector, tableSelector, autorun = true) => {
const form = document.querySelector(formSelector);
if (!form) {
console.error("form not found");
@@ -253,7 +253,9 @@ const setupNetworkScanForm = (formSelector, tableSelector) => {
};
form.addEventListener('submit', onSubmitFn);
onSubmitFn();
if (autorun) {
onSubmitFn();
}
}
const setupRestoreBackupForm = (formSelector) => {
@@ -318,25 +320,19 @@ const setupRestoreBackupForm = (formSelector) => {
console.log("Backup: ", data);
if (data.settings != undefined) {
for (var key in data.settings) {
let response = await fetch(url, {
method: "POST",
cache: "no-cache",
credentials: "include",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"settings": {
[key]: data.settings[key]
}
})
});
let response = await fetch(url, {
method: "POST",
cache: "no-cache",
credentials: "include",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({"settings": data.settings})
});
if (!response.ok) {
onFailed();
return;
}
if (!response.ok) {
onFailed();
return;
}
}
-16
View File
@@ -1,16 +0,0 @@
import subprocess
Import("env")
try:
commit_hash = "undefined"
result = subprocess.check_output(
["git", "rev-parse", "--short", "HEAD"]
)
commit_hash = result.decode("utf-8").strip()
env.Append(
CPPDEFINES=[
("BUILD_COMMIT", '\\"{}\\"'.format(commit_hash))
]
)
except Exception as error:
print("Failed to get commit hash: {}".format(error))