From f668c3ef944d35d717c8ef1f6c69b7b8fb31fa68 Mon Sep 17 00:00:00 2001 From: real-bombinho <37409530+real-bombinho@users.noreply.github.com> Date: Sun, 21 Sep 2025 14:13:25 +0100 Subject: [PATCH 1/3] Update AlertMe.h error messages stored in PROGMEM --- src/AlertMe.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/AlertMe.h b/src/AlertMe.h index 20fa2d1..3444daa 100644 --- a/src/AlertMe.h +++ b/src/AlertMe.h @@ -16,6 +16,16 @@ #include #include //https://github.com/bblanchon/ArduinoJson +static const char ErrorSendingMessage[] PROGMEM = "Sending message error"; +static const char ErrorSMTPQuit[] PROGMEM = "SMTP QUIT error"; +static const char ErrorNotConnected[] PROGMEM = "Could not connect to mail server"; +static const char ErrorConnection[] PROGMEM = "Connection Error"; +static const char ErrorIdentification[] PROGMEM = "Identification error"; +static const char ErrorAuthentification[] PROGMEM = "SMTP AUTH error"; +static const char ErrorSMTPData[] PROGMEM = "SMTP DATA error"; +static const char ErrorNotSent[] PROGMEM = "Sending message error"; +static const char ErrorSMTPTimeout[] PROGMEM = "SMTP Response TIMEOUT!"; + class AlertMe{ public: AlertMe(); From 38983c73e384df15b6b1dd32443289d182bd9012 Mon Sep 17 00:00:00 2001 From: real-bombinho <37409530+real-bombinho@users.noreply.github.com> Date: Sun, 21 Sep 2025 14:43:09 +0100 Subject: [PATCH 2/3] Update AlertMe.cpp Updated error assignment to make use of PROGMEM --- src/AlertMe.cpp | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/AlertMe.cpp b/src/AlertMe.cpp index 4aef0f2..cbfde2e 100644 --- a/src/AlertMe.cpp +++ b/src/AlertMe.cpp @@ -29,7 +29,7 @@ uint16_t smtp_port = 0; char smtp_server[40]; bool needs_save = false; bool alert_debug = false; -char* last_error = ""; +char last_error[35] = ""; bool stmp_connect_fail = false; @@ -40,7 +40,10 @@ void DEBUG_AM(Generic text) { Serial.println(text); } } - + +#define DEBUG_AMF(f_, ...) if (alert_debug) printf((f_), ##__VA_ARGS__) +#define FV(s) (reinterpret_cast(s)) + AlertMe::AlertMe(){} // BASE64 ----------------------------------------------------------- @@ -116,12 +119,12 @@ class Gsender protected: Gsender(); private: - const char* _error = nullptr; + const __FlashStringHelper* _error = nullptr; char* _subject = nullptr; String _serverResponse; static Gsender* _instance; bool AwaitSMTPResponse(WiFiClientSecure &client, const String &resp = "", uint16_t timeOut = 10000); - + void setError(const __FlashStringHelper* err); public: static Gsender* Instance(); Gsender* Subject(const char* subject); @@ -129,7 +132,7 @@ class Gsender bool Send(const String &to, const String &message); bool TestConnection(char* server, uint16_t port); String getLastResponse(); - const char* getError(); + void getError(); }; Gsender* Gsender::_instance = 0; @@ -159,7 +162,7 @@ bool Gsender::AwaitSMTPResponse(WiFiClientSecure &client, const String &resp, ui while (!client.available()) { if (millis() > (ts + timeOut)) { - _error = "SMTP Response TIMEOUT!"; + setError(FV(ErrorSMTPTimeout)); return false; } } @@ -174,9 +177,14 @@ String Gsender::getLastResponse() return _serverResponse; } -const char* Gsender::getError() -{ - return _error; +void Gsender::getError() +{ + // Copy from PROGMEM to RAM + strncpy_P(last_error, reinterpret_cast(_error), sizeof(last_error)); +} + +void Gsender::setError(const __FlashStringHelper* err) { + _error = err; } bool Gsender::Send(const String &to, const String &message) @@ -185,18 +193,18 @@ bool Gsender::Send(const String &to, const String &message) DEBUG_AM("Connecting to :"); DEBUG_AM(smtp_server); if (!client.connect(smtp_server, smtp_port)) { - _error = "Could not connect to mail server"; + setError(FV(ErrorNotConnected)); return false; } if (!AwaitSMTPResponse(client, "220")) { - _error = "Connection Error"; + setError(FV(ErrorConnection)); return false; } DEBUG_AM("HELO friend:"); client.println("HELO friend"); if (!AwaitSMTPResponse(client, "250")) { - _error = "identification error"; + setError(FV(ErrorIdentification)); return false; } @@ -215,7 +223,7 @@ bool Gsender::Send(const String &to, const String &message) client.println(encode64(EMAIL_PASSWORD)); if (!AwaitSMTPResponse(client, "235")) { - _error = "SMTP AUTH error"; + setError(FV(ErrorAuthentification)); return false; } @@ -232,7 +240,7 @@ bool Gsender::Send(const String &to, const String &message) DEBUG_AM("DATA:"); client.println("DATA"); if (!AwaitSMTPResponse(client, "354")) { - _error = "SMTP DATA error"; + setError(FV(ErrorSMTPData)); return false; } @@ -250,12 +258,12 @@ bool Gsender::Send(const String &to, const String &message) client.println(body); client.println("."); if (!AwaitSMTPResponse(client, "250")) { - _error = "Sending message error"; + setError(FV(ErrorNotSent)); return false; } client.println("QUIT"); if (!AwaitSMTPResponse(client, "221")) { - _error = "SMTP QUIT error"; + setError(FV(ErrorSMTPQuit)); return false; } return true; @@ -266,18 +274,18 @@ bool Gsender::TestConnection(char* server, uint16_t port) { DEBUG_AM("Connecting to :"); DEBUG_AM(server); if (!client.connect(server, port)) { - _error = "Could not connect to mail server"; + setError(FV(ErrorNotConnected)); return false; } if (!AwaitSMTPResponse(client, "220")) { - _error = "Connection Error"; + setError(FV(ErrorConnection)); return false; } DEBUG_AM("HELO friend:"); client.println("HELO friend"); if (!AwaitSMTPResponse(client, "250")) { - _error = "identification error"; + setError(FV(ErrorIdentification)); return false; } @@ -298,7 +306,7 @@ bool Gsender::TestConnection(char* server, uint16_t port) { client.println(encode64(EMAIL_PASSWORD)); if (!AwaitSMTPResponse(client, "235")) { - _error = "SMTP AUTH error"; + setError(FV(ErrorAuthentification)); return false; } From ca8c2b6b2b1a1b9fe95a483cdb8c8bfcfdcddcef Mon Sep 17 00:00:00 2001 From: real-bombinho <37409530+real-bombinho@users.noreply.github.com> Date: Sun, 5 Oct 2025 09:59:35 +0100 Subject: [PATCH 3/3] Update AlertMe.cpp omitted change to getError call corrected --- src/AlertMe.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AlertMe.cpp b/src/AlertMe.cpp index cbfde2e..7b6ae9b 100644 --- a/src/AlertMe.cpp +++ b/src/AlertMe.cpp @@ -466,7 +466,7 @@ const char* AlertMe::send(String subject, String message, String dest) { return "SENT"; } else { - strcpy(last_error,gsender->getError()); + getError(); DEBUG_AM("Message sending failed. ("); DEBUG_AM(last_error);