4 Commits
1.4.1 ... 1.4.2

Author SHA1 Message Date
Yurii
769daa0857 chore: bump version to 1.4.2 2024-06-15 03:03:50 +03:00
Yurii
76979531b8 feat: added more info about the build to the portal 2024-06-15 03:03:31 +03:00
Yurii
7779076498 refactor: optimizing work with network 2024-06-14 18:18:43 +03:00
Yurii
45e2e0334e chore: added nodemcu v3 board; changed default gpio for nodemcu 32s 2024-06-14 18:17:12 +03:00
8 changed files with 67 additions and 23 deletions

View File

@@ -13,6 +13,7 @@ void NetworkConnection::setup(bool useDhcp) {
void NetworkConnection::reset() {
status = Status::NONE;
rawDisconnectReason = 0;
disconnectReason = DisconnectReason::NONE;
}
@@ -33,22 +34,25 @@ void NetworkConnection::onEvent(System_Event_t *event) {
switch (event->event) {
case EVENT_STAMODE_CONNECTED:
status = useDhcp ? Status::CONNECTING : Status::CONNECTED;
rawDisconnectReason = 0;
disconnectReason = DisconnectReason::NONE;
break;
case EVENT_STAMODE_GOT_IP:
status = Status::CONNECTED;
rawDisconnectReason = 0;
disconnectReason = DisconnectReason::NONE;
break;
case EVENT_STAMODE_DHCP_TIMEOUT:
status = Status::DISCONNECTED;
rawDisconnectReason = 0;
disconnectReason = DisconnectReason::DHCP_TIMEOUT;
break;
case EVENT_STAMODE_DISCONNECTED:
status = Status::DISCONNECTED;
rawDisconnectReason = event->event_info.disconnected.reason;
disconnectReason = convertDisconnectReason(event->event_info.disconnected.reason);
// https://github.com/esp8266/Arduino/blob/d5eb265f78bff9deb7063d10030a02d021c8c66c/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp#L231
@@ -63,6 +67,7 @@ void NetworkConnection::onEvent(System_Event_t *event) {
auto& src = event->event_info.auth_change;
if ((src.old_mode != AUTH_OPEN) && (src.new_mode == AUTH_OPEN)) {
status = Status::DISCONNECTED;
rawDisconnectReason = 0;
disconnectReason = DisconnectReason::OTHER;
wifi_station_disconnect();
@@ -79,25 +84,27 @@ void NetworkConnection::onEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
switch (event) {
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
status = useDhcp ? Status::CONNECTING : Status::CONNECTED;
rawDisconnectReason = 0;
disconnectReason = DisconnectReason::NONE;
break;
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
status = Status::CONNECTED;
rawDisconnectReason = 0;
disconnectReason = DisconnectReason::NONE;
break;
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
status = Status::DISCONNECTED;
rawDisconnectReason = 0;
disconnectReason = DisconnectReason::DHCP_TIMEOUT;
break;
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
status = Status::DISCONNECTED;
rawDisconnectReason = info.wifi_sta_disconnected.reason;
disconnectReason = convertDisconnectReason(info.wifi_sta_disconnected.reason);
break;
default:
@@ -147,4 +154,5 @@ NetworkConnection::DisconnectReason NetworkConnection::convertDisconnectReason(u
bool NetworkConnection::useDhcp = false;
NetworkConnection::Status NetworkConnection::status = Status::NONE;
NetworkConnection::DisconnectReason NetworkConnection::disconnectReason = DisconnectReason::NONE;
NetworkConnection::DisconnectReason NetworkConnection::disconnectReason = DisconnectReason::NONE;
uint8_t NetworkConnection::rawDisconnectReason = 0;

View File

@@ -27,6 +27,7 @@ namespace NetworkUtils {
static Status status;
static DisconnectReason disconnectReason;
static uint8_t rawDisconnectReason;
static void setup(bool useDhcp);
static void setUseDhcp(bool value);

View File

@@ -212,7 +212,7 @@ namespace NetworkUtils {
}
#endif*/
WiFi.disconnect(false, true);
this->disconnect();
}
if (!this->hasStaCredentials()) {
@@ -266,13 +266,17 @@ namespace NetworkUtils {
return false;
}
void disconnect() {
WiFi.disconnect(false, true);
}
void loop() {
if (this->reconnectFlag) {
this->delayCallback(5000);
Log.sinfoln(FPSTR(L_NETWORK), F("Reconnecting..."));
this->reconnectFlag = false;
this->resetWifi();
this->disconnect();
NetworkConnection::reset();
this->delayCallback(1000);
@@ -297,7 +301,7 @@ namespace NetworkUtils {
}
if (this->isApEnabled() && millis() - this->connectedTime > this->reconnectInterval && !this->hasApClients()) {
Log.sinfoln(FPSTR(L_NETWORK), F("Stop AP because connected, start only STA"));
Log.sinfoln(FPSTR(L_NETWORK), F("Stop AP because STA connected"));
WiFi.mode(WIFI_STA);
return;
@@ -348,7 +352,7 @@ namespace NetworkUtils {
NetworkConnection::reset();
if (!this->connect(true, this->connectionTimeout)) {
Log.straceln(FPSTR(L_NETWORK), F("Connection failed. Status: %d, reason: %d"), NetworkConnection::getStatus(), NetworkConnection::getDisconnectReason());
Log.straceln(FPSTR(L_NETWORK), F("Connection failed. Status: %d, reason: %d, raw reason: %d"), NetworkConnection::getStatus(), NetworkConnection::getDisconnectReason(), NetworkConnection::rawDisconnectReason);
}
this->prevReconnectingTime = millis();

View File

@@ -13,6 +13,7 @@
extra_configs = secrets.default.ini
[env]
version = 1.4.2
framework = arduino
lib_deps =
bblanchon/ArduinoJson@^7.0.4
@@ -33,6 +34,8 @@ 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 USE_SERIAL=${secrets.use_serial}
-D USE_TELNET=${secrets.use_telnet}
-D DEBUG_BY_DEFAULT=${secrets.debug}
@@ -53,7 +56,6 @@ monitor_speed = 115200
monitor_filters = direct
board_build.flash_mode = dio
board_build.filesystem = littlefs
version = 1.4.1
; Defaults
[esp8266_defaults]
@@ -136,6 +138,22 @@ build_flags =
-D DEFAULT_STATUS_LED_GPIO=13
-D DEFAULT_OT_RX_LED_GPIO=15
[env:nodemcu_8266]
platform = ${esp8266_defaults.platform}
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_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
[env:s2_mini]
platform = ${esp32_defaults.platform}
platform_packages = ${esp32_defaults.platform_packages}
@@ -203,7 +221,7 @@ build_flags =
-D DEFAULT_STATUS_LED_GPIO=4
-D DEFAULT_OT_RX_LED_GPIO=5
[env:nodemcu_32s]
[env:nodemcu_32]
platform = ${esp32_defaults.platform}
platform_packages = ${esp32_defaults.platform_packages}
board = nodemcu-32s
@@ -216,11 +234,11 @@ extra_scripts = ${esp32_defaults.extra_scripts}
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=13
-D DEFAULT_STATUS_LED_GPIO=2 ; 18
-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
;-D WOKWI=1

View File

@@ -163,7 +163,7 @@ protected:
// ha helper settings
this->haHelper->setDevicePrefix(settings.mqtt.prefix);
this->haHelper->setDeviceVersion(PROJECT_VERSION);
this->haHelper->setDeviceVersion(BUILD_VERSION);
this->haHelper->setDeviceModel(PROJECT_NAME);
this->haHelper->setDeviceName(PROJECT_NAME);
this->haHelper->setWriter(this->writer);

View File

@@ -82,7 +82,7 @@ protected:
String result;
if (strcmp(var, "ver") == 0) {
result = PROJECT_VERSION;
result = BUILD_VERSION;
}
return result;
@@ -513,8 +513,9 @@ protected:
doc["network"]["gateway"] = isConnected ? network->getStaGateway().toString() : "";
doc["network"]["dns"] = isConnected ? network->getStaDns().toString() : "";
doc["system"]["version"] = PROJECT_VERSION;
doc["system"]["buildVersion"] = BUILD_VERSION;
doc["system"]["buildDate"] = __DATE__ " " __TIME__;
doc["system"]["buildEnv"] = BUILD_ENV;
doc["system"]["uptime"] = millis() / 1000ul;
doc["system"]["totalHeap"] = getTotalHeap();
doc["system"]["freeHeap"] = getFreeHeap();
@@ -623,6 +624,10 @@ protected:
if (this->stateWebServer()) {
this->webServer->handleClient();
}
if (!this->stateDnsServer() && !this->stateWebServer()) {
this->delay(250);
}
}
bool isAuthRequired() {

View File

@@ -1,5 +1,4 @@
#define PROJECT_NAME "OpenTherm Gateway"
#define PROJECT_VERSION "1.4.1"
#define PROJECT_REPO "https://github.com/Laxilef/OTGateway"
#define MQTT_RECONNECT_INTERVAL 15000
@@ -23,6 +22,14 @@
#define THERMOSTAT_INDOOR_MIN_TEMP 5
#define THERMOSTAT_INDOOR_MAX_TEMP 30
#ifndef BUILD_VERSION
#define BUILD_VERSION "0.0.0"
#endif
#ifndef BUILD_ENV
#define BUILD_ENV "undefined"
#endif
#ifndef USE_SERIAL
#define USE_SERIAL true
#endif

View File

@@ -87,11 +87,11 @@
<tbody>
<tr>
<th scope="row">Version:</th>
<td><b id="version"></b>, core/sdk: <b id="core-version"></b></td>
<td><b id="build-version"></b></td>
</tr>
<tr>
<th scope="row">Build date:</th>
<td><b id="build-date"></b></td>
<th scope="row">Build:</th>
<td>Env: <b id="build-env"></b><br />Date: <b id="build-date"></b><br />Core/SDK: <b id="core-version"></b></td>
</tr>
<tr>
<th scope="row">Uptime:</th>
@@ -155,8 +155,9 @@
setValue('#network-dns', result.network.dns);
setBusy('#main-busy', '#main-table', false);
setValue('#version', result.system.version);
setValue('#build-version', result.system.buildVersion);
setValue('#build-date', result.system.buildDate);
setValue('#build-env', result.system.buildEnv);
setValue('#uptime', result.system.uptime);
setValue('#uptime-days', Math.floor(result.system.uptime / 86400));
setValue('#uptime-hours', Math.floor(result.system.uptime % 86400 / 3600));