Skip to content

Commit

Permalink
Merge branch 'mega' into feature/esp-now-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
TD-er authored Feb 3, 2025
2 parents d40f5d8 + a952e41 commit dff4863
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 51 deletions.
4 changes: 3 additions & 1 deletion docs/source/Notify/N001.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ From the *Notifications* page, press *Edit* on an available *Nr* option. Next, C
* SMTP Server Settings

* **Domain :** Mail provider domain.
* **Server :** Mail server address (DNS or IP number). Must support non-secure SMTP.
* **Server :** Mail server address (DNS or IP number).
* **Port :** Server port number. (see note below)
* **Timeout :** Maximum allowed time for server reply. Increase value if server timeouts occur.

Expand Down Expand Up @@ -114,6 +114,8 @@ ESP8266 simply doesn't have enough free memory available to setup a SSL connecti

Only SSL port 465 is supported, as for using port 587 (typically named "TLS") extra steps are required to make a connection.
This may be added later.

ESP32: (With TLS enabled in the build) To use the basic SMTP protocol (not SMTPS), configure port ``25`` or ``2525``. For other port numbers, a secure SMTP connection will be attempted.
|
Email Server Requirements with SSL
Expand Down
4 changes: 3 additions & 1 deletion docs/source/Plugin/P137.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ Hardware outputs AXP192

* *LilyGO T-Beam* Settings for the LilyGO T-Beam series of GPS/LoRa devices with optional OLed display.

* *User defined* To be able to configure all available output pins the User defined option is available, f.e. when using a custom designed, or not yet supported, hardware setup.
* *M5Stack StickC Plus* Settings for the M5Stack StickC Plus hardware. (Not applicable for the M5Stack StickC Plus 2, as that unit doesn't have an AXP192 power management controller).

* *User defined* To be able to configure are available output pins the User defined option is available, f.e. when using a custom designed, or not yet supported, hardware setup.

When available, new predefined devices will be added. The User defined option will stay the last option.

Expand Down
Binary file modified docs/source/Plugin/P137_PredefinedDeviceOptions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/AXP2101/src/AXP2101_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ AXP2101_settings AXP2101_deviceSettingsArray[] =
/* M5Stack Core2 v1.1 */ { 3300, 0, 3300, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, AXP_pin_s::Protected, AXP_pin_s::Disabled, AXP_pin_s::Protected, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP2101_chargeled_d::Off },
/* M5Stack CoreS3 */ { 3300, 0, 3300, 0, 0, 1800, 3300, 3300, 3300, 0, 0, 0, 0, 0, AXP_pin_s::Protected, AXP_pin_s::Disabled, AXP_pin_s::Protected, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP_pin_s::Protected, AXP_pin_s::Protected, AXP_pin_s::Default, AXP_pin_s::Protected, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP2101_chargeled_d::Off },
/* LilyGo TBeam v1.2 */ { 3300, 0, 2500, 0, 0, 0, 3300, 3300, 0, 0, 0, 0, 0, 0, AXP_pin_s::Protected, AXP_pin_s::Disabled, AXP_pin_s::Protected, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP_pin_s::Default, AXP2101_chargeled_d::Off },
/* LilyGo TBeamS3 */ { 3300, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, AXP_pin_s::Protected, AXP_pin_s::Disabled, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP2101_chargeled_d::Off },
/* LilyGo TBeamS3 */ { 3300, 500, 500, 1800, 3300, 1800, 3300, 3300, 3300, 1800, 3300, 3300, 2300, 2300, AXP_pin_s::Protected, AXP_pin_s::Disabled, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP2101_chargeled_d::Off },
/* LilyGo TPCie v1.2 */ { 3300, 900, 900, 1100, 1200, 1800, 2800, 3300, 2900, 1800, 2800, 500, 1900, 1300, AXP_pin_s::Protected, AXP_pin_s::Disabled, AXP_pin_s::Protected, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP_pin_s::Disabled, AXP2101_chargeled_d::Off },
/* Userdefined */ { 3300, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP_pin_s::Default, AXP2101_chargeled_d::Off },
};
Expand Down
5 changes: 3 additions & 2 deletions src/_P037_MQTTImport.ino
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,10 @@ bool MQTTSubscribe_037(struct EventStruct *event)
for (uint8_t x = 0; x < VARS_PER_TASK; x++) {
String subscribeTo = P037_data->getFullMQTTTopic(x);

if (!subscribeTo.isEmpty()) {
parseSystemVariables(subscribeTo, false);
parseSystemVariables(subscribeTo, false);
subscribeTo.trim();

if (!subscribeTo.isEmpty()) {
if (MQTTclient.subscribe(subscribeTo.c_str())) {
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
addLog(LOG_LEVEL_INFO, strformat(F("IMPT : [%s#%s] subscribed to %s"),
Expand Down
4 changes: 4 additions & 0 deletions src/_P137_AXP192.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

/**
* Changelog:
* 2025-01-21 tonhuisman: Bugfix: commands axp,ldo2,x to axp,dcdc3,x weren't working as intended
* 2025-01-18 tonhuisman: Add predefined config settings for M5Stack StickC Plus units
* 2022-12-27 tonhuisman: Add predefined config settings for LilyGO T-Beam LoRa units
* 2022-12-07 tonhuisman: Re-order device configuration to use PLUGIN_WEBFORM_LOAD_OUTPUT_SELECTOR
* Enable PluginStats feature
Expand Down Expand Up @@ -181,13 +183,15 @@ boolean Plugin_137(uint8_t function, struct EventStruct *event, String& string)
toString(P137_PredefinedDevices_e::M5Stack_StickC),
toString(P137_PredefinedDevices_e::M5Stack_Core2),
toString(P137_PredefinedDevices_e::LilyGO_TBeam),
toString(P137_PredefinedDevices_e::M5Stack_StickCPlus),
toString(P137_PredefinedDevices_e::UserDefined) // keep last and at 99 !!
};
const int predefinedValues[] = {
static_cast<int>(P137_PredefinedDevices_e::Unselected),
static_cast<int>(P137_PredefinedDevices_e::M5Stack_StickC),
static_cast<int>(P137_PredefinedDevices_e::M5Stack_Core2),
static_cast<int>(P137_PredefinedDevices_e::LilyGO_TBeam),
static_cast<int>(P137_PredefinedDevices_e::M5Stack_StickCPlus),
static_cast<int>(P137_PredefinedDevices_e::UserDefined) }; // keep last and at 99 !!
constexpr size_t optionCount = NR_ELEMENTS(predefinedValues);
FormSelectorOptions selector(optionCount, predefinedNames, predefinedValues);
Expand Down
6 changes: 6 additions & 0 deletions src/src/CustomBuild/define_plugin_sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,12 @@ To create/register a plugin, you have to :
#ifndef USES_P135
#define USES_P135 // SCD4x
#endif
#if !defined(USES_P137) && defined(ESP32)
#define USES_P137 // AXP192
#endif
#if !defined(USES_P139) && defined(ESP32)
#define USES_P139 // AXP2101
#endif
#ifndef USES_P144
#define USES_P144 // Dust - PM1006(K) (Vindriktning)
#endif
Expand Down
12 changes: 8 additions & 4 deletions src/src/ESPEasyCore/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,15 @@ bool MQTTConnect(controllerIndex_t controller_idx)
String subscribeTo = ControllerSettings->Subscribe;

parseSystemVariables(subscribeTo, false);
MQTTclient.subscribe(subscribeTo.c_str());
subscribeTo.trim();

if (loglevelActiveFor(LOG_LEVEL_INFO))
{
addLogMove(LOG_LEVEL_INFO, concat(F("Subscribed to: "), subscribeTo));
if (!subscribeTo.isEmpty()) {
MQTTclient.subscribe(subscribeTo.c_str());

if (loglevelActiveFor(LOG_LEVEL_INFO))
{
addLogMove(LOG_LEVEL_INFO, concat(F("Subscribed to: "), subscribeTo));
}
}

updateMQTTclient_connected();
Expand Down
73 changes: 45 additions & 28 deletions src/src/NotifierStructs/N001_data_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,48 @@

bool NPlugin_001_send(const NotificationSettingsStruct& notificationsettings, String& subject, String& body)
{
bool myStatus = false;
bool failFlag = false;
bool myStatus = false;
bool failFlag = false;
bool deleteClient = true;

WiFiClient *client = nullptr;

# if FEATURE_EMAIL_TLS

// values are based on the NPLUGIN_001_PKT_SZ
BearSSL::WiFiClientSecure_light client(4096, 4096);
client.setUtcTime_fcn(getUnixTime);
client.setCfgTime_fcn(get_build_unixtime);
client.setTrustAnchor(Tasmota_TA, Tasmota_TA_size);

client.setInsecure();
BearSSL::WiFiClientSecure_light secureClient(4096, 4096);

// Port 25 or 2525 is a standard WiFiClient, all else is a secure client...
if ((notificationsettings.Port != 25) && (notificationsettings.Port != 2525)) {
secureClient.setUtcTime_fcn(getUnixTime);
secureClient.setCfgTime_fcn(get_build_unixtime);
secureClient.setTrustAnchor(Tasmota_TA, Tasmota_TA_size);
secureClient.setInsecure();
client = &secureClient;
deleteClient = false;
} else {
client = new (std::nothrow) WiFiClient();

if (!client) { return false; }
}

# else // if FEATURE_EMAIL_TLS

// Use WiFiClient class to create TCP connections
WiFiClient client;
client = new (std::nothrow) WiFiClient();

if (!client) { return false; }
# endif // if FEATURE_EMAIL_TLS

# ifdef MUSTFIX_CLIENT_TIMEOUT_IN_SECONDS

// See: https://github.com/espressif/arduino-esp32/pull/6676
client.setTimeout((notificationsettings.Timeout_ms + 500) / 1000); // in seconds!!!!
Client *pClient = &client;
client->setTimeout((notificationsettings.Timeout_ms + 500) / 1000); // in seconds!!!!
Client *pClient = client;
pClient->setTimeout(notificationsettings.Timeout_ms);
# else // ifdef MUSTFIX_CLIENT_TIMEOUT_IN_SECONDS
client.setTimeout(notificationsettings.Timeout_ms); // in msec as it should be!
client->setTimeout(notificationsettings.Timeout_ms); // in msec as it should be!
# endif // ifdef MUSTFIX_CLIENT_TIMEOUT_IN_SECONDS

# ifndef BUILD_NO_DEBUG
Expand All @@ -61,14 +76,14 @@ bool NPlugin_001_send(const NotificationSettingsStruct& notificationsettings, St
}
# endif // ifndef BUILD_NO_DEBUG

if (!connectClient(client, notificationsettings.Server, notificationsettings.Port, notificationsettings.Timeout_ms)) {
if (!connectClient(*client, notificationsettings.Server, notificationsettings.Port, notificationsettings.Timeout_ms)) {
if (loglevelActiveFor(LOG_LEVEL_ERROR)) {
# if FEATURE_EMAIL_TLS
addLog(LOG_LEVEL_ERROR, strformat(
F("Email: Error connecting to %s:%u Error code: %d"),
notificationsettings.Server,
notificationsettings.Port,
client.getLastError()));
secureClient.getLastError()));

# else // if FEATURE_EMAIL_TLS
addLog(LOG_LEVEL_ERROR, strformat(
Expand Down Expand Up @@ -176,7 +191,7 @@ bool NPlugin_001_send(const NotificationSettingsStruct& notificationsettings, St
}

# if FEATURE_EMAIL_TLS
client.setDomainName(notificationsettings.Domain);
secureClient.setDomainName(notificationsettings.Domain);

# endif // if FEATURE_EMAIL_TLS

Expand All @@ -201,7 +216,7 @@ bool NPlugin_001_send(const NotificationSettingsStruct& notificationsettings, St
// exit using break;
// However this is way too complex using both a failFlag and break
// and not even consistently.
if (!NPlugin_001_MTA(client, EMPTY_STRING, 220, clientTimeout)) {
if (!NPlugin_001_MTA(*client, EMPTY_STRING, 220, clientTimeout)) {
# ifndef BUILD_NO_DEBUG

if (loglevelActiveFor(LOG_LEVEL_DEBUG)) {
Expand All @@ -220,7 +235,7 @@ bool NPlugin_001_send(const NotificationSettingsStruct& notificationsettings, St
const String astr = strformat(F("EHLO %s"), notificationsettings.Domain);

if (!NPlugin_001_MTA(
client,
*client,
astr,
250,
clientTimeout)) {
Expand All @@ -239,12 +254,12 @@ bool NPlugin_001_send(const NotificationSettingsStruct& notificationsettings, St

bool done = false;

while (client.available() && !done) {
while (client->available() && !done) {
if (timeOutReached(timer)) {
failFlag = true;
break;
}
done = safeReadStringUntil(client, replyStr, '\n', NPLUGIN_001_PKT_SZ);
done = safeReadStringUntil(*client, replyStr, '\n', NPLUGIN_001_PKT_SZ);
catStr += replyStr;
}

Expand All @@ -269,7 +284,7 @@ bool NPlugin_001_send(const NotificationSettingsStruct& notificationsettings, St
}
# endif // ifndef BUILD_NO_DEBUG

if (!NPlugin_001_Auth(client, notificationsettings.User, notificationsettings.Pass, clientTimeout)) {
if (!NPlugin_001_Auth(*client, notificationsettings.User, notificationsettings.Pass, clientTimeout)) {
# ifndef BUILD_NO_DEBUG

addLog(LOG_LEVEL_DEBUG, F("Email: User/Pass Fail"));
Expand All @@ -286,7 +301,7 @@ bool NPlugin_001_send(const NotificationSettingsStruct& notificationsettings, St

const String astr = strformat(F("MAIL FROM:<%s>"), email_address.c_str());

if (!NPlugin_001_MTA(client, astr, 250, clientTimeout)) {
if (!NPlugin_001_MTA(*client, astr, 250, clientTimeout)) {
# ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("Email: Addr Fail"));
# endif // ifndef BUILD_NO_DEBUG
Expand All @@ -313,7 +328,7 @@ bool NPlugin_001_send(const NotificationSettingsStruct& notificationsettings, St
addLog(LOG_LEVEL_INFO, concat(F("Email: To "), emailTo));
}

if (!NPlugin_001_MTA(client, strformat(F("RCPT TO:<%s>"), emailTo.c_str()), 250, clientTimeout))
if (!NPlugin_001_MTA(*client, strformat(F("RCPT TO:<%s>"), emailTo.c_str()), 250, clientTimeout))
{
break;
}
Expand All @@ -323,14 +338,14 @@ bool NPlugin_001_send(const NotificationSettingsStruct& notificationsettings, St
}

if (!failFlag) {
if (!NPlugin_001_MTA(client, F("DATA"), 354, clientTimeout)) {
if (!NPlugin_001_MTA(*client, F("DATA"), 354, clientTimeout)) {
failFlag = true;
break;
}
}

if (!failFlag) {
if (!NPlugin_001_MTA(client, strformat(F("%s%s\r\n.\r\n"), mailheader.c_str(), body.c_str()), 250, clientTimeout)) {
if (!NPlugin_001_MTA(*client, strformat(F("%s%s\r\n.\r\n"), mailheader.c_str(), body.c_str()), 250, clientTimeout)) {
failFlag = true;
break;
}
Expand All @@ -341,22 +356,24 @@ bool NPlugin_001_send(const NotificationSettingsStruct& notificationsettings, St
myStatus = true;
}

NPlugin_001_MTA(client, F("QUIT"), 221, clientTimeout); // Sent successfully, close SMTP protocol, ignore failure
NPlugin_001_MTA(*client, F("QUIT"), 221, clientTimeout); // Sent successfully, close SMTP protocol, ignore failure
break;
}
}

// client.PR_9453_FLUSH_TO_CLEAR();
client.stop();

if (myStatus == true) {
if (myStatus) {
addLog(LOG_LEVEL_INFO, F("Email: Connection Closed Successfully"));
} else {
if (loglevelActiveFor(LOG_LEVEL_ERROR)) {
addLogMove(LOG_LEVEL_ERROR, concat(F("Email: Connection Closed With Error. Used header: "), mailheader));
}
}
}

client->stop();

if (deleteClient) { delete client; }

return myStatus;
}

Expand Down
Loading

0 comments on commit dff4863

Please sign in to comment.