mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-05-01 19:55:14 +00:00
fix merge issues
This commit is contained in:
@@ -38,6 +38,15 @@
|
|||||||
#include "../test/test.h"
|
#include "../test/test.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NO_TLS_SUPPORT
|
||||||
|
#define ENABLE_SMTP
|
||||||
|
#define USE_ESP_SSLCLIENT
|
||||||
|
#define READYCLIENT_SSL_CLIENT ESP_SSLClient
|
||||||
|
#define READYCLIENT_TYPE_1 // TYPE 1 when using ESP_SSLClient
|
||||||
|
#include <ESP_SSLClient.h>
|
||||||
|
#include <ReadyMail.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
// Languages supported. Note: the order is important
|
// Languages supported. Note: the order is important
|
||||||
@@ -106,6 +115,110 @@ bool System::command_send(const char * value, const int8_t id) {
|
|||||||
return EMSESP::txservice_.send_raw(value); // ignore id
|
return EMSESP::txservice_.send_raw(value); // ignore id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool System::command_sendmail(const char * value, const int8_t id) {
|
||||||
|
bool enabled = false;
|
||||||
|
bool ssl, starttls;
|
||||||
|
uint16_t port;
|
||||||
|
String server, login, pass, sender, recp, subject;
|
||||||
|
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
||||||
|
enabled = settings.email_enabled;
|
||||||
|
ssl = settings.email_ssl;
|
||||||
|
starttls = settings.email_starttls;
|
||||||
|
server = settings.email_server;
|
||||||
|
port = settings.email_port;
|
||||||
|
login = settings.email_login;
|
||||||
|
pass = settings.email_pass;
|
||||||
|
sender = settings.email_sender;
|
||||||
|
recp = settings.email_recp;
|
||||||
|
subject = settings.email_subject;
|
||||||
|
});
|
||||||
|
if (!enabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
LOG_DEBUG("Command sendmail port %d%s called with '%s'", port, ssl ? " (SSL)" : starttls ? " (STARTTLS)" : "", value);
|
||||||
|
// LOG_DEBUG("Command sendmail port %d called with '%s'", port, value);
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
|
#ifndef NO_TLS_SUPPORT
|
||||||
|
WiFiClient * basic_client;
|
||||||
|
ESP_SSLClient * ssl_client;
|
||||||
|
ReadyClient * r_client; // rClient(ssl_client);
|
||||||
|
SMTPClient * smtp; // smtp(rClient);
|
||||||
|
basic_client = new WiFiClient;
|
||||||
|
ssl_client = new ESP_SSLClient;
|
||||||
|
r_client = new ReadyClient(*ssl_client);
|
||||||
|
smtp = new SMTPClient(*r_client);
|
||||||
|
|
||||||
|
ssl_client->setClient(basic_client);
|
||||||
|
ssl_client->setInsecure();
|
||||||
|
ssl_client->setBufferSizes(1024, 1024);
|
||||||
|
r_client->addPort(port, starttls ? readymail_protocol_tls : ssl ? readymail_protocol_ssl : readymail_protocol_plain_text);
|
||||||
|
|
||||||
|
// smtp->connect(server, port, sendmailCallback);
|
||||||
|
smtp->connect(server, port);
|
||||||
|
if (!smtp->isConnected()) {
|
||||||
|
LOG_ERROR("Sendmail connection error");
|
||||||
|
delete smtp;
|
||||||
|
delete r_client;
|
||||||
|
delete ssl_client;
|
||||||
|
delete basic_client;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// LOG_INFO("authenticate %s:%s", login.c_str(), pass.c_str());
|
||||||
|
smtp->authenticate(login, pass, readymail_auth_password);
|
||||||
|
if (!smtp->isAuthenticated()) {
|
||||||
|
LOG_ERROR("Sendmail authenticate error");
|
||||||
|
delete smtp;
|
||||||
|
delete r_client;
|
||||||
|
delete ssl_client;
|
||||||
|
delete basic_client;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JsonDocument doc;
|
||||||
|
String body = value;
|
||||||
|
if (body.length()) {
|
||||||
|
auto error = deserializeJson(doc, (const char *)value);
|
||||||
|
if (!error && doc.as<JsonObject>().size() >= 0) {
|
||||||
|
subject = doc["subject"] | subject;
|
||||||
|
recp = doc["to"] | recp;
|
||||||
|
sender = doc["from"] | sender;
|
||||||
|
body = doc["body"] | body;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SMTPMessage & msg = smtp->getMessage();
|
||||||
|
msg.headers.add(rfc822_subject, subject);
|
||||||
|
msg.headers.add(rfc822_from, sender);
|
||||||
|
msg.headers.add(rfc822_to, recp);
|
||||||
|
|
||||||
|
// Use addCustom to add custom header e.g. Importance and Priority.
|
||||||
|
// msg.headers.addCustom("Importance", PRIORITY);
|
||||||
|
// msg.headers.addCustom("X-MSMail-Priority", PRIORITY);
|
||||||
|
// msg.headers.addCustom("X-Priority", PRIORITY_NUM);
|
||||||
|
|
||||||
|
msg.text.body(body);
|
||||||
|
|
||||||
|
// bodyText.replace("\r\n", "<br>\r\n");
|
||||||
|
// msg.html.body("<html><body><div style=\"color:#cc0066;\">" + bodyText + "</div></body></html>");
|
||||||
|
// msg.html.transferEncoding("base64");
|
||||||
|
|
||||||
|
// With embedFile function, the html message will send as attachment.
|
||||||
|
// if (EMBED_MESSAGE)
|
||||||
|
// msg.html.embedFile(true, "msg.html", embed_message_type_attachment);
|
||||||
|
|
||||||
|
msg.timestamp = time(nullptr);
|
||||||
|
|
||||||
|
success = smtp->send(msg);
|
||||||
|
|
||||||
|
delete smtp;
|
||||||
|
delete r_client;
|
||||||
|
delete ssl_client;
|
||||||
|
delete basic_client;
|
||||||
|
#endif
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
// return string of languages and count
|
// return string of languages and count
|
||||||
std::string System::languages_string() {
|
std::string System::languages_string() {
|
||||||
std::string languages_string = std::to_string(NUM_LANGUAGES) + " languages (";
|
std::string languages_string = std::to_string(NUM_LANGUAGES) + " languages (";
|
||||||
@@ -463,7 +576,6 @@ void System::system_restart(const char * partitionname) {
|
|||||||
|
|
||||||
Mqtt::disconnect(); // gracefully disconnect MQTT, needed for QOS1
|
Mqtt::disconnect(); // gracefully disconnect MQTT, needed for QOS1
|
||||||
EMSuart::stop(); // stop UART so there is no interference
|
EMSuart::stop(); // stop UART so there is no interference
|
||||||
|
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
delay(1000); // wait 1 second
|
delay(1000); // wait 1 second
|
||||||
ESP.restart(); // ka-boom! - this is the only place where the ESP32 restart is called
|
ESP.restart(); // ka-boom! - this is the only place where the ESP32 restart is called
|
||||||
@@ -565,7 +677,6 @@ void System::store_settings(WebSettings & settings) {
|
|||||||
|
|
||||||
locale_ = settings.locale;
|
locale_ = settings.locale;
|
||||||
developer_mode_ = settings.developer_mode;
|
developer_mode_ = settings.developer_mode;
|
||||||
|
|
||||||
// start services
|
// start services
|
||||||
if (settings.modbus_enabled) {
|
if (settings.modbus_enabled) {
|
||||||
if (EMSESP::modbus_ == nullptr) {
|
if (EMSESP::modbus_ == nullptr) {
|
||||||
@@ -607,20 +718,11 @@ void System::start() {
|
|||||||
appfree_ = esp_ota_get_running_partition()->size / 1024 - appused_;
|
appfree_ = esp_ota_get_running_partition()->size / 1024 - appused_;
|
||||||
refreshHeapMem(); // refresh free heap and max alloc heap
|
refreshHeapMem(); // refresh free heap and max alloc heap
|
||||||
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2
|
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2
|
||||||
#if ESP_IDF_VERSION_MAJOR < 5
|
|
||||||
temp_sensor_config_t temp_sensor = TSENS_CONFIG_DEFAULT();
|
|
||||||
temp_sensor_get_config(&temp_sensor);
|
|
||||||
temp_sensor.dac_offset = TSENS_DAC_DEFAULT; // DEFAULT: range:-10℃ ~ 80℃, error < 1℃.
|
|
||||||
temp_sensor_set_config(temp_sensor);
|
|
||||||
temp_sensor_start();
|
|
||||||
temp_sensor_read_celsius(&temperature_);
|
|
||||||
#else
|
|
||||||
temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(-10, 80);
|
temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(-10, 80);
|
||||||
temperature_sensor_install(&temp_sensor_config, &temperature_handle_);
|
temperature_sensor_install(&temp_sensor_config, &temperature_handle_);
|
||||||
temperature_sensor_enable(temperature_handle_);
|
temperature_sensor_enable(temperature_handle_);
|
||||||
temperature_sensor_get_celsius(temperature_handle_, &temperature_);
|
temperature_sensor_get_celsius(temperature_handle_, &temperature_);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
EMSESP::esp32React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
|
EMSESP::esp32React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
|
||||||
@@ -841,16 +943,9 @@ void System::send_info_mqtt() {
|
|||||||
doc["IPv4 gateway"] = uuid::printable_to_string(WiFi.gatewayIP());
|
doc["IPv4 gateway"] = uuid::printable_to_string(WiFi.gatewayIP());
|
||||||
doc["IPv4 nameserver"] = uuid::printable_to_string(WiFi.dnsIP());
|
doc["IPv4 nameserver"] = uuid::printable_to_string(WiFi.dnsIP());
|
||||||
|
|
||||||
#if ESP_IDF_VERSION_MAJOR < 5
|
|
||||||
if (WiFi.localIPv6().toString() != "0000:0000:0000:0000:0000:0000:0000:0000" && WiFi.localIPv6().toString() != "::") {
|
|
||||||
doc["IPv6 address"] = uuid::printable_to_string(WiFi.localIPv6());
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (WiFi.linkLocalIPv6().toString() != "0000:0000:0000:0000:0000:0000:0000:0000" && WiFi.linkLocalIPv6().toString() != "::") {
|
if (WiFi.linkLocalIPv6().toString() != "0000:0000:0000:0000:0000:0000:0000:0000" && WiFi.linkLocalIPv6().toString() != "::") {
|
||||||
doc["IPv6 address"] = uuid::printable_to_string(WiFi.linkLocalIPv6());
|
doc["IPv6 address"] = uuid::printable_to_string(WiFi.linkLocalIPv6());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
Mqtt::queue_publish_retain(F_(info), doc.as<JsonObject>()); // topic called "info" and it's Retained
|
Mqtt::queue_publish_retain(F_(info), doc.as<JsonObject>()); // topic called "info" and it's Retained
|
||||||
@@ -959,13 +1054,8 @@ void System::network_init() {
|
|||||||
delay(500);
|
delay(500);
|
||||||
digitalWrite(eth_power_, HIGH);
|
digitalWrite(eth_power_, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ESP_IDF_VERSION_MAJOR < 5
|
|
||||||
eth_present_ = ETH.begin(phy_addr, power, mdc, mdio, type, clock_mode);
|
|
||||||
#else
|
|
||||||
eth_present_ = ETH.begin(type, phy_addr, mdc, mdio, power, clock_mode);
|
eth_present_ = ETH.begin(type, phy_addr, mdc, mdio, power, clock_mode);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check health of system, done every 5 seconds
|
// check health of system, done every 5 seconds
|
||||||
@@ -976,13 +1066,9 @@ void System::system_check() {
|
|||||||
|
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2
|
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2
|
||||||
#if ESP_IDF_VERSION_MAJOR < 5
|
|
||||||
temp_sensor_read_celsius(&temperature_);
|
|
||||||
#else
|
|
||||||
temperature_sensor_get_celsius(temperature_handle_, &temperature_);
|
temperature_sensor_get_celsius(temperature_handle_, &temperature_);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef EMSESP_PINGTEST
|
#ifdef EMSESP_PINGTEST
|
||||||
static uint64_t ping_count = 0;
|
static uint64_t ping_count = 0;
|
||||||
@@ -1034,6 +1120,7 @@ void System::commands_init() {
|
|||||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(read), System::command_read, FL_(read_cmd), CommandFlag::ADMIN_ONLY);
|
Command::add(EMSdevice::DeviceType::SYSTEM, F_(read), System::command_read, FL_(read_cmd), CommandFlag::ADMIN_ONLY);
|
||||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(send), System::command_send, FL_(send_cmd), CommandFlag::ADMIN_ONLY);
|
Command::add(EMSdevice::DeviceType::SYSTEM, F_(send), System::command_send, FL_(send_cmd), CommandFlag::ADMIN_ONLY);
|
||||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(fetch), System::command_fetch, FL_(fetch_cmd), CommandFlag::ADMIN_ONLY);
|
Command::add(EMSdevice::DeviceType::SYSTEM, F_(fetch), System::command_fetch, FL_(fetch_cmd), CommandFlag::ADMIN_ONLY);
|
||||||
|
Command::add(EMSdevice::DeviceType::SYSTEM, F_(sendmail), System::command_sendmail, FL_(sendmail_cmd), CommandFlag::ADMIN_ONLY);
|
||||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(restart), System::command_restart, FL_(restart_cmd), CommandFlag::ADMIN_ONLY);
|
Command::add(EMSdevice::DeviceType::SYSTEM, F_(restart), System::command_restart, FL_(restart_cmd), CommandFlag::ADMIN_ONLY);
|
||||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(format), System::command_format, FL_(format_cmd), CommandFlag::ADMIN_ONLY);
|
Command::add(EMSdevice::DeviceType::SYSTEM, F_(format), System::command_format, FL_(format_cmd), CommandFlag::ADMIN_ONLY);
|
||||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(txpause), System::command_txpause, FL_(txpause_cmd), CommandFlag::ADMIN_ONLY);
|
Command::add(EMSdevice::DeviceType::SYSTEM, F_(txpause), System::command_txpause, FL_(txpause_cmd), CommandFlag::ADMIN_ONLY);
|
||||||
@@ -1275,16 +1362,9 @@ void System::show_system(uuid::console::Shell & shell) {
|
|||||||
shell.printfln(" IPv4 address: %s/%s", uuid::printable_to_string(WiFi.localIP()).c_str(), uuid::printable_to_string(WiFi.subnetMask()).c_str());
|
shell.printfln(" IPv4 address: %s/%s", uuid::printable_to_string(WiFi.localIP()).c_str(), uuid::printable_to_string(WiFi.subnetMask()).c_str());
|
||||||
shell.printfln(" IPv4 gateway: %s", uuid::printable_to_string(WiFi.gatewayIP()).c_str());
|
shell.printfln(" IPv4 gateway: %s", uuid::printable_to_string(WiFi.gatewayIP()).c_str());
|
||||||
shell.printfln(" IPv4 nameserver: %s", uuid::printable_to_string(WiFi.dnsIP()).c_str());
|
shell.printfln(" IPv4 nameserver: %s", uuid::printable_to_string(WiFi.dnsIP()).c_str());
|
||||||
#if ESP_IDF_VERSION_MAJOR < 5
|
|
||||||
if (WiFi.localIPv6().toString() != "0000:0000:0000:0000:0000:0000:0000:0000" && WiFi.localIPv6().toString() != "::") {
|
|
||||||
shell.printfln(" IPv6 address: %s", uuid::printable_to_string(WiFi.localIPv6()).c_str());
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (WiFi.linkLocalIPv6().toString() != "0000:0000:0000:0000:0000:0000:0000:0000" && WiFi.linkLocalIPv6().toString() != "::") {
|
if (WiFi.linkLocalIPv6().toString() != "0000:0000:0000:0000:0000:0000:0000:0000" && WiFi.linkLocalIPv6().toString() != "::") {
|
||||||
shell.printfln(" IPv6 address: %s", uuid::printable_to_string(WiFi.linkLocalIPv6()).c_str());
|
shell.printfln(" IPv6 address: %s", uuid::printable_to_string(WiFi.linkLocalIPv6()).c_str());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WL_CONNECT_FAILED:
|
case WL_CONNECT_FAILED:
|
||||||
@@ -1315,15 +1395,9 @@ void System::show_system(uuid::console::Shell & shell) {
|
|||||||
shell.printfln(" IPv4 address: %s/%s", uuid::printable_to_string(ETH.localIP()).c_str(), uuid::printable_to_string(ETH.subnetMask()).c_str());
|
shell.printfln(" IPv4 address: %s/%s", uuid::printable_to_string(ETH.localIP()).c_str(), uuid::printable_to_string(ETH.subnetMask()).c_str());
|
||||||
shell.printfln(" IPv4 gateway: %s", uuid::printable_to_string(ETH.gatewayIP()).c_str());
|
shell.printfln(" IPv4 gateway: %s", uuid::printable_to_string(ETH.gatewayIP()).c_str());
|
||||||
shell.printfln(" IPv4 nameserver: %s", uuid::printable_to_string(ETH.dnsIP()).c_str());
|
shell.printfln(" IPv4 nameserver: %s", uuid::printable_to_string(ETH.dnsIP()).c_str());
|
||||||
#if ESP_IDF_VERSION_MAJOR < 5
|
|
||||||
if (ETH.localIPv6().toString() != "0000:0000:0000:0000:0000:0000:0000:0000" && ETH.localIPv6().toString() != "::") {
|
|
||||||
shell.printfln(" IPv6 address: %s", uuid::printable_to_string(ETH.localIPv6()).c_str());
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (ETH.linkLocalIPv6().toString() != "0000:0000:0000:0000:0000:0000:0000:0000" && ETH.linkLocalIPv6().toString() != "::") {
|
if (ETH.linkLocalIPv6().toString() != "0000:0000:0000:0000:0000:0000:0000:0000" && ETH.linkLocalIPv6().toString() != "::") {
|
||||||
shell.printfln(" IPv6 address: %s", uuid::printable_to_string(ETH.linkLocalIPv6()).c_str());
|
shell.printfln(" IPv6 address: %s", uuid::printable_to_string(ETH.linkLocalIPv6()).c_str());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
shell.println();
|
shell.println();
|
||||||
|
|
||||||
@@ -1345,7 +1419,6 @@ void System::show_system(uuid::console::Shell & shell) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
shell.println();
|
shell.println();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1648,8 +1721,8 @@ bool System::check_upgrade() {
|
|||||||
return false; // no reboot required
|
return false; // no reboot required
|
||||||
}
|
}
|
||||||
|
|
||||||
// map each config filename to its human-readable section key
|
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
|
// map each config filename to its human-readable section key
|
||||||
static const std::pair<const char *, const char *> SECTION_MAP[] = {
|
static const std::pair<const char *, const char *> SECTION_MAP[] = {
|
||||||
{NETWORK_SETTINGS_FILE, "Network"},
|
{NETWORK_SETTINGS_FILE, "Network"},
|
||||||
{AP_SETTINGS_FILE, "AP"},
|
{AP_SETTINGS_FILE, "AP"},
|
||||||
@@ -1763,38 +1836,29 @@ void System::exportSystemBackup(JsonObject output) {
|
|||||||
|
|
||||||
const char * nvs_part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, "nvs1") ? "nvs1" : "nvs"; // nvs1 is on 16MBs
|
const char * nvs_part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, "nvs1") ? "nvs1" : "nvs"; // nvs1 is on 16MBs
|
||||||
nvs_iterator_t it = nullptr;
|
nvs_iterator_t it = nullptr;
|
||||||
#if ESP_IDF_VERSION_MAJOR < 5
|
|
||||||
it = nvs_entry_find(nvs_part, "ems-esp", NVS_TYPE_ANY);
|
|
||||||
if (it == nullptr) {
|
|
||||||
#else
|
|
||||||
esp_err_t err = nvs_entry_find(nvs_part, "ems-esp", NVS_TYPE_ANY, &it);
|
esp_err_t err = nvs_entry_find(nvs_part, "ems-esp", NVS_TYPE_ANY, &it);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
#endif
|
|
||||||
LOG_ERROR("Failed to find NVS entry for %s", nvs_part);
|
LOG_ERROR("Failed to find NVS entry for %s", nvs_part);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonArray entries = node["nvs"].to<JsonArray>();
|
JsonArray entries = node["nvs"].to<JsonArray>();
|
||||||
#if ESP_IDF_VERSION_MAJOR < 5
|
|
||||||
while (it != nullptr) {
|
|
||||||
nvs_entry_info_t info;
|
|
||||||
nvs_entry_info(it, &info);
|
|
||||||
#else
|
|
||||||
while (err == ESP_OK) {
|
while (err == ESP_OK) {
|
||||||
nvs_entry_info_t info;
|
nvs_entry_info_t info;
|
||||||
nvs_entry_info(it, &info);
|
nvs_entry_info(it, &info);
|
||||||
#endif
|
|
||||||
JsonObject entry = entries.add<JsonObject>();
|
JsonObject entry = entries.add<JsonObject>();
|
||||||
entry["type"] = info.type;
|
entry["type"] = info.type; // e.g. NVS_TYPE_U32 or NVS_TYPE_STR etc
|
||||||
entry["key"] = info.key;
|
entry["key"] = info.key;
|
||||||
|
|
||||||
LOG_DEBUG("Exporting NVS value: %s = %d", info.key, info.type);
|
LOG_DEBUG("Exporting NVS value: %s = %d", info.key, info.type);
|
||||||
|
|
||||||
|
// serialize based on the type. We use putString, putChar, putUChar, putDouble, putBool, putULong only
|
||||||
switch (info.type) {
|
switch (info.type) {
|
||||||
case NVS_TYPE_I8:
|
case NVS_TYPE_I8:
|
||||||
entry["value"] = EMSESP::nvs_.getChar(info.key);
|
entry["value"] = EMSESP::nvs_.getChar(info.key);
|
||||||
break;
|
break;
|
||||||
case NVS_TYPE_U8:
|
case NVS_TYPE_U8:
|
||||||
|
// also used for bool
|
||||||
entry["value"] = EMSESP::nvs_.getUChar(info.key);
|
entry["value"] = EMSESP::nvs_.getUChar(info.key);
|
||||||
break;
|
break;
|
||||||
case NVS_TYPE_I32:
|
case NVS_TYPE_I32:
|
||||||
@@ -1810,22 +1874,19 @@ void System::exportSystemBackup(JsonObject output) {
|
|||||||
entry["value"] = EMSESP::nvs_.getULong64(info.key);
|
entry["value"] = EMSESP::nvs_.getULong64(info.key);
|
||||||
break;
|
break;
|
||||||
case NVS_TYPE_BLOB:
|
case NVS_TYPE_BLOB:
|
||||||
entry["value"] = EMSESP::nvs_.getDouble(info.key); // bytes used for double values
|
// used for double (e.g. sensor values, nrgheat, nrgww), and stored as bytes in NVS
|
||||||
|
entry["value"] = EMSESP::nvs_.getDouble(info.key);
|
||||||
break;
|
break;
|
||||||
case NVS_TYPE_STR:
|
case NVS_TYPE_STR:
|
||||||
case NVS_TYPE_ANY:
|
case NVS_TYPE_ANY:
|
||||||
default:
|
default:
|
||||||
|
// any other value we store as a string
|
||||||
entry["value"] = EMSESP::nvs_.getString(info.key);
|
entry["value"] = EMSESP::nvs_.getString(info.key);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ESP_IDF_VERSION_MAJOR < 5
|
|
||||||
it = nvs_entry_next(it);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
err = nvs_entry_next(&it);
|
err = nvs_entry_next(&it);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (it != nullptr) {
|
if (it != nullptr) {
|
||||||
nvs_release_iterator(it);
|
nvs_release_iterator(it);
|
||||||
@@ -3323,6 +3384,10 @@ void System::set_valid_system_gpios() {
|
|||||||
} else {
|
} else {
|
||||||
valid_system_gpios_ = string_range_to_vector("0-39", "6-11, 20, 24, 28-31");
|
valid_system_gpios_ = string_range_to_vector("0-39", "6-11, 20, 24, 28-31");
|
||||||
}
|
}
|
||||||
|
#elif CONFIG_IDF_TARGET_ESP32C6
|
||||||
|
// https://docs.espressif.com/projects/esp-idf/en/v5.5.3/esp32c6/api-reference/peripherals/gpio.html
|
||||||
|
// 24-30 used for flash, 12-13 USB, 16-17 uart0
|
||||||
|
valid_system_gpios_ = string_range_to_vector("0-30", "12-13, 16-17, 24-30");
|
||||||
#elif defined(EMSESP_STANDALONE)
|
#elif defined(EMSESP_STANDALONE)
|
||||||
valid_system_gpios_ = string_range_to_vector("0-39");
|
valid_system_gpios_ = string_range_to_vector("0-39");
|
||||||
#endif
|
#endif
|
||||||
@@ -3407,3 +3472,4 @@ void System::restore_snapshot_gpios(std::vector<int8_t> & u_gpios, std::vector<i
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace emsesp
|
} // namespace emsesp
|
||||||
|
|
||||||
@@ -83,6 +83,20 @@ void WebSettings::read(WebSettings & settings, JsonObject root) {
|
|||||||
root["modbus_max_clients"] = settings.modbus_max_clients;
|
root["modbus_max_clients"] = settings.modbus_max_clients;
|
||||||
root["modbus_timeout"] = settings.modbus_timeout;
|
root["modbus_timeout"] = settings.modbus_timeout;
|
||||||
root["developer_mode"] = settings.developer_mode;
|
root["developer_mode"] = settings.developer_mode;
|
||||||
|
#ifndef NO_TLS_SUPPORT
|
||||||
|
root["email_enabled"] = settings.email_enabled;
|
||||||
|
#else
|
||||||
|
root["email_enabled"] = false;
|
||||||
|
#endif
|
||||||
|
root["email_ssl"] = settings.email_ssl;
|
||||||
|
root["email_starttls"] = settings.email_starttls;
|
||||||
|
root["email_server"] = settings.email_server;
|
||||||
|
root["email_port"] = settings.email_port;
|
||||||
|
root["email_login"] = settings.email_login;
|
||||||
|
root["email_pass"] = settings.email_pass;
|
||||||
|
root["email_sender"] = settings.email_sender;
|
||||||
|
root["email_recp"] = settings.email_recp;
|
||||||
|
root["email_subject"] = settings.email_subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
// call on initialization and also when settings are updated/saved via web or console
|
// call on initialization and also when settings are updated/saved via web or console
|
||||||
@@ -243,13 +257,9 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) {
|
|||||||
|
|
||||||
// Modbus settings
|
// Modbus settings
|
||||||
settings.modbus_enabled = root["modbus_enabled"] | EMSESP_DEFAULT_MODBUS_ENABLED;
|
settings.modbus_enabled = root["modbus_enabled"] | EMSESP_DEFAULT_MODBUS_ENABLED;
|
||||||
check_flag(original_settings.modbus_enabled, settings.modbus_enabled, ChangeFlags::RESTART);
|
|
||||||
settings.modbus_port = root["modbus_port"] | EMSESP_DEFAULT_MODBUS_PORT;
|
settings.modbus_port = root["modbus_port"] | EMSESP_DEFAULT_MODBUS_PORT;
|
||||||
check_flag(original_settings.modbus_port, settings.modbus_port, ChangeFlags::RESTART);
|
|
||||||
settings.modbus_max_clients = root["modbus_max_clients"] | EMSESP_DEFAULT_MODBUS_MAX_CLIENTS;
|
settings.modbus_max_clients = root["modbus_max_clients"] | EMSESP_DEFAULT_MODBUS_MAX_CLIENTS;
|
||||||
check_flag(original_settings.modbus_max_clients, settings.modbus_max_clients, ChangeFlags::RESTART);
|
|
||||||
settings.modbus_timeout = root["modbus_timeout"] | EMSESP_DEFAULT_MODBUS_TIMEOUT;
|
settings.modbus_timeout = root["modbus_timeout"] | EMSESP_DEFAULT_MODBUS_TIMEOUT;
|
||||||
check_flag(original_settings.modbus_timeout, settings.modbus_timeout, ChangeFlags::RESTART);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// these may need mqtt restart to rebuild HA discovery topics
|
// these may need mqtt restart to rebuild HA discovery topics
|
||||||
@@ -300,6 +310,20 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) {
|
|||||||
settings.weblog_level = root["weblog_level"] | EMSESP_DEFAULT_WEBLOG_LEVEL;
|
settings.weblog_level = root["weblog_level"] | EMSESP_DEFAULT_WEBLOG_LEVEL;
|
||||||
settings.weblog_compact = root["weblog_compact"] | EMSESP_DEFAULT_WEBLOG_COMPACT;
|
settings.weblog_compact = root["weblog_compact"] | EMSESP_DEFAULT_WEBLOG_COMPACT;
|
||||||
|
|
||||||
|
settings.email_enabled = root["email_enabled"] | FACTORY_EMAIL_ENABLE;
|
||||||
|
settings.email_ssl = root["email_ssl"] | FACTORY_EMAIL_SSL;
|
||||||
|
settings.email_starttls = root["email_starttls"] | FACTORY_EMAIL_STARTTLS;
|
||||||
|
settings.email_server = root["email_server"] | FACTORY_EMAIL_SERVER;
|
||||||
|
settings.email_port = root["email_port"] | FACTORY_EMAIL_PORT;
|
||||||
|
settings.email_login = root["email_login"] | FACTORY_EMAIL_LOGIN;
|
||||||
|
settings.email_pass = root["email_pass"] | FACTORY_EMAIL_PASSWORD;
|
||||||
|
settings.email_sender = root["email_sender"] | FACTORY_EMAIL_FROM;
|
||||||
|
settings.email_recp = root["email_recp"] | FACTORY_EMAIL_TO;
|
||||||
|
settings.email_subject = root["email_subject"] | FACTORY_EMAIL_SUBJECT;
|
||||||
|
|
||||||
|
if (settings.email_ssl && settings.email_starttls) {
|
||||||
|
settings.email_ssl = false;
|
||||||
|
}
|
||||||
// if no psram limit weblog buffer to 25 messages
|
// if no psram limit weblog buffer to 25 messages
|
||||||
if (EMSESP::system_.PSram() > 0) {
|
if (EMSESP::system_.PSram() > 0) {
|
||||||
settings.weblog_buffer = root["weblog_buffer"] | EMSESP_DEFAULT_WEBLOG_BUFFER;
|
settings.weblog_buffer = root["weblog_buffer"] | EMSESP_DEFAULT_WEBLOG_BUFFER;
|
||||||
@@ -458,23 +482,14 @@ void WebSettings::set_board_profile(WebSettings & settings) {
|
|||||||
#if CONFIG_IDF_TARGET_ESP32
|
#if CONFIG_IDF_TARGET_ESP32
|
||||||
// check for no PSRAM, could be a E32 or S32?
|
// check for no PSRAM, could be a E32 or S32?
|
||||||
if (!ESP.getPsramSize()) {
|
if (!ESP.getPsramSize()) {
|
||||||
#if ESP_ARDUINO_VERSION_MAJOR < 3
|
|
||||||
if (ETH.begin(1, 16, 23, 18, ETH_PHY_LAN8720, ETH_CLOCK_GPIO0_IN)) {
|
|
||||||
#else
|
|
||||||
if (ETH.begin(ETH_PHY_LAN8720, 1, 23, 18, 16, ETH_CLOCK_GPIO0_IN)) {
|
if (ETH.begin(ETH_PHY_LAN8720, 1, 23, 18, 16, ETH_CLOCK_GPIO0_IN)) {
|
||||||
#endif
|
|
||||||
settings.board_profile = "E32"; // Ethernet without PSRAM
|
settings.board_profile = "E32"; // Ethernet without PSRAM
|
||||||
} else {
|
} else {
|
||||||
settings.board_profile = "S32"; // ESP32 standard WiFi without PSRAM
|
settings.board_profile = "S32"; // ESP32 standard WiFi without PSRAM
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// check for boards with PSRAM, could be a E32V2 otherwise default back to the S32
|
// check for boards with PSRAM, could be a E32V2 otherwise default back to the S32
|
||||||
#if ESP_ARDUINO_VERSION_MAJOR < 3
|
|
||||||
if (ETH.begin(0, 15, 23, 18, ETH_PHY_LAN8720, ETH_CLOCK_GPIO0_OUT)) {
|
|
||||||
#else
|
|
||||||
if (ETH.begin(ETH_PHY_LAN8720, 0, 23, 18, 15, ETH_CLOCK_GPIO0_OUT)) {
|
if (ETH.begin(ETH_PHY_LAN8720, 0, 23, 18, 15, ETH_CLOCK_GPIO0_OUT)) {
|
||||||
#endif
|
|
||||||
|
|
||||||
if (analogReadMilliVolts(39) > 700) { // core voltage > 2.6V
|
if (analogReadMilliVolts(39) > 700) { // core voltage > 2.6V
|
||||||
settings.board_profile = "E32V2_2"; // Ethernet, PSRAM, internal sensors
|
settings.board_profile = "E32V2_2"; // Ethernet, PSRAM, internal sensors
|
||||||
} else {
|
} else {
|
||||||
@@ -551,3 +566,4 @@ uint8_t WebSettings::get_flags() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace emsesp
|
} // namespace emsesp
|
||||||
|
|
||||||
Reference in New Issue
Block a user