mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-26 18:13:36 +05:00
Compare commits
4 Commits
1.5.3
...
2e5e5e59a8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e5e5e59a8 | ||
|
|
e1623e7b63 | ||
|
|
80b91d9a01 | ||
|
|
25b70e4db5 |
@@ -84,7 +84,7 @@ board_build.ldscript = eagle.flash.4m1m.ld
|
|||||||
;platform_packages =
|
;platform_packages =
|
||||||
; framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.5
|
; 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
|
; 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/53.03.11/platform-espressif32.zip
|
platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.12/platform-espressif32.zip
|
||||||
platform_packages =
|
platform_packages =
|
||||||
board_build.partitions = esp32_partitions.csv
|
board_build.partitions = esp32_partitions.csv
|
||||||
lib_deps =
|
lib_deps =
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
//#define PORTAL_CACHE "max-age=86400"
|
//#define PORTAL_CACHE "max-age=86400"
|
||||||
#define PORTAL_CACHE nullptr
|
#define PORTAL_CACHE nullptr
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
|
#include <ESP8266mDNS.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
#include <Updater.h>
|
#include <Updater.h>
|
||||||
using WebServer = ESP8266WebServer;
|
using WebServer = ESP8266WebServer;
|
||||||
#else
|
#else
|
||||||
|
#include <ESPmDNS.h>
|
||||||
#include <WebServer.h>
|
#include <WebServer.h>
|
||||||
#include <Update.h>
|
#include <Update.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -53,7 +55,6 @@ protected:
|
|||||||
bool webServerEnabled = false;
|
bool webServerEnabled = false;
|
||||||
bool dnsServerEnabled = false;
|
bool dnsServerEnabled = false;
|
||||||
unsigned long webServerChangeState = 0;
|
unsigned long webServerChangeState = 0;
|
||||||
unsigned long dnsServerChangeState = 0;
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
const char* getTaskName() override {
|
const char* getTaskName() override {
|
||||||
@@ -872,6 +873,10 @@ protected:
|
|||||||
this->startWebServer();
|
this->startWebServer();
|
||||||
Log.straceln(FPSTR(L_PORTAL_WEBSERVER), F("Started: AP up or STA connected"));
|
Log.straceln(FPSTR(L_PORTAL_WEBSERVER), F("Started: AP up or STA connected"));
|
||||||
|
|
||||||
|
if (MDNS.begin(networkSettings.hostname)) {
|
||||||
|
MDNS.addService("http", "tcp", 80);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
::optimistic_yield(1000);
|
::optimistic_yield(1000);
|
||||||
#endif
|
#endif
|
||||||
@@ -880,13 +885,15 @@ protected:
|
|||||||
this->stopWebServer();
|
this->stopWebServer();
|
||||||
Log.straceln(FPSTR(L_PORTAL_WEBSERVER), F("Stopped: AP and STA down"));
|
Log.straceln(FPSTR(L_PORTAL_WEBSERVER), F("Stopped: AP and STA down"));
|
||||||
|
|
||||||
|
MDNS.end();
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
::optimistic_yield(1000);
|
::optimistic_yield(1000);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// dns server
|
// dns server
|
||||||
if (!this->stateDnsServer() && this->stateWebServer() && network->isApEnabled() && network->hasApClients() && millis() - this->dnsServerChangeState >= this->changeStateInterval) {
|
if (!this->stateDnsServer() && !network->isConnected() && network->isApEnabled() && this->stateWebServer()) {
|
||||||
this->startDnsServer();
|
this->startDnsServer();
|
||||||
Log.straceln(FPSTR(L_PORTAL_DNSSERVER), F("Started: AP up"));
|
Log.straceln(FPSTR(L_PORTAL_DNSSERVER), F("Started: AP up"));
|
||||||
|
|
||||||
@@ -894,9 +901,9 @@ protected:
|
|||||||
::optimistic_yield(1000);
|
::optimistic_yield(1000);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} else if (this->stateDnsServer() && (!network->isApEnabled() || !this->stateWebServer())) {
|
} else if (this->stateDnsServer() && (network->isConnected() || !network->isApEnabled() || !this->stateWebServer())) {
|
||||||
this->stopDnsServer();
|
this->stopDnsServer();
|
||||||
Log.straceln(FPSTR(L_PORTAL_DNSSERVER), F("Stopped: AP down"));
|
Log.straceln(FPSTR(L_PORTAL_DNSSERVER), F("Stopped: AP down/STA connected"));
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
::optimistic_yield(1000);
|
::optimistic_yield(1000);
|
||||||
@@ -1006,7 +1013,6 @@ protected:
|
|||||||
|
|
||||||
this->dnsServer->start(53, "*", network->getApIp());
|
this->dnsServer->start(53, "*", network->getApIp());
|
||||||
this->dnsServerEnabled = true;
|
this->dnsServerEnabled = true;
|
||||||
this->dnsServerChangeState = millis();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopDnsServer() {
|
void stopDnsServer() {
|
||||||
@@ -1017,6 +1023,5 @@ protected:
|
|||||||
//this->dnsServer->processNextRequest();
|
//this->dnsServer->processNextRequest();
|
||||||
this->dnsServer->stop();
|
this->dnsServer->stop();
|
||||||
this->dnsServerEnabled = false;
|
this->dnsServerEnabled = false;
|
||||||
this->dnsServerChangeState = millis();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DEFAULT_HOSTNAME
|
#ifndef DEFAULT_HOSTNAME
|
||||||
#define DEFAULT_HOSTNAME "opentherm"
|
#define DEFAULT_HOSTNAME ""
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DEFAULT_AP_SSID
|
#ifndef DEFAULT_AP_SSID
|
||||||
@@ -111,7 +111,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DEFAULT_MQTT_PREFIX
|
#ifndef DEFAULT_MQTT_PREFIX
|
||||||
#define DEFAULT_MQTT_PREFIX "opentherm"
|
#define DEFAULT_MQTT_PREFIX ""
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DEFAULT_OT_IN_GPIO
|
#ifndef DEFAULT_OT_IN_GPIO
|
||||||
|
|||||||
12
src/main.cpp
12
src/main.cpp
@@ -102,6 +102,12 @@ void setup() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// generate hostname if it is empty
|
||||||
|
if (!strlen(networkSettings.hostname)) {
|
||||||
|
strcpy(networkSettings.hostname, getChipId("otgateway-").c_str());
|
||||||
|
fsNetworkSettings.update();
|
||||||
|
}
|
||||||
|
|
||||||
network = (new NetworkMgr)
|
network = (new NetworkMgr)
|
||||||
->setHostname(networkSettings.hostname)
|
->setHostname(networkSettings.hostname)
|
||||||
->setStaCredentials(
|
->setStaCredentials(
|
||||||
@@ -148,6 +154,12 @@ void setup() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// generate mqtt prefix if it is empty
|
||||||
|
if (!strlen(settings.mqtt.prefix)) {
|
||||||
|
strcpy(settings.mqtt.prefix, getChipId("otgateway_").c_str());
|
||||||
|
fsSettings.update();
|
||||||
|
}
|
||||||
|
|
||||||
// Logs settings
|
// Logs settings
|
||||||
if (!settings.system.serial.enabled) {
|
if (!settings.system.serial.enabled) {
|
||||||
Serial.end();
|
Serial.end();
|
||||||
|
|||||||
34
src/utils.h
34
src/utils.h
@@ -1,5 +1,37 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
String getChipId(const char* prefix = nullptr, const char* suffix = nullptr) {
|
||||||
|
String chipId;
|
||||||
|
chipId.reserve(
|
||||||
|
6
|
||||||
|
+ (prefix != nullptr ? strlen(prefix) : 0)
|
||||||
|
+ (suffix != nullptr ? strlen(suffix) : 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (prefix != nullptr) {
|
||||||
|
chipId.concat(prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t cid = 0;
|
||||||
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
|
cid = ESP.getChipId();
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
// https://github.com/espressif/arduino-esp32/blob/master/libraries/ESP32/examples/ChipID/GetChipID/GetChipID.ino
|
||||||
|
for (uint8_t i = 0; i < 17; i = i + 8) {
|
||||||
|
cid |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
chipId += String(cid, HEX);
|
||||||
|
|
||||||
|
if (suffix != nullptr) {
|
||||||
|
chipId.concat(suffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
chipId.trim();
|
||||||
|
return chipId;
|
||||||
|
}
|
||||||
|
|
||||||
bool isLeapYear(short year) {
|
bool isLeapYear(short year) {
|
||||||
if (year % 4 != 0) {
|
if (year % 4 != 0) {
|
||||||
return false;
|
return false;
|
||||||
@@ -1791,7 +1823,7 @@ bool jsonToSensorSettings(const uint8_t sensorId, const JsonVariantConst src, Se
|
|||||||
if (!src[FPSTR(S_FACTOR)].isNull()) {
|
if (!src[FPSTR(S_FACTOR)].isNull()) {
|
||||||
float value = src[FPSTR(S_FACTOR)].as<float>();
|
float value = src[FPSTR(S_FACTOR)].as<float>();
|
||||||
|
|
||||||
if (value > 0.09f && value <= 10.0f && fabsf(value - dst.factor) > 0.0001f) {
|
if (value > 0.09f && value <= 100.0f && fabsf(value - dst.factor) > 0.0001f) {
|
||||||
dst.factor = roundf(value, 3);
|
dst.factor = roundf(value, 3);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@
|
|||||||
|
|
||||||
<label>
|
<label>
|
||||||
<span data-i18n>sensors.correction.factor</span>
|
<span data-i18n>sensors.correction.factor</span>
|
||||||
<input type="number" inputmode="decimal" name="factor" min="0.01" max="10" step="0.01" required>
|
<input type="number" inputmode="decimal" name="factor" min="0.01" max="100" step="0.01" required>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
Reference in New Issue
Block a user