From 1899a0a6b3532f398a58c8f2d01ae4ee1a65ce2e Mon Sep 17 00:00:00 2001 From: Piotr Gniado Date: Sun, 16 Nov 2025 16:49:21 +0100 Subject: [PATCH 1/2] feat(ppp): Add variation of PPPClass::cmd() Add variation of PPPClass::cmd() function that returns more detailed response. --- libraries/PPP/src/PPP.cpp | 24 ++++++++++++++++++++++++ libraries/PPP/src/PPP.h | 15 +++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/libraries/PPP/src/PPP.cpp b/libraries/PPP/src/PPP.cpp index 76c5fad0d78..01989429ae5 100644 --- a/libraries/PPP/src/PPP.cpp +++ b/libraries/PPP/src/PPP.cpp @@ -757,6 +757,30 @@ String PPPClass::cmd(const char *at_command, int timeout) { return String(out); } +bool PPPClass::cmd(const char *at_command, String &response, int timeout) { + PPP_CMD_MODE_CHECK(false); + + char out[128] = {0}; + esp_err_t err = _esp_modem_at(_dce, at_command, out, timeout); + response = String(out); + + if (err != ESP_OK) { + log_e("esp_modem_at failed %d %s", err, esp_err_to_name(err)); + + if (err == ESP_FAIL && response.isEmpty()) { + response = "ERROR"; + } + + return false; + } + + if (response.isEmpty()) { + response = "OK"; + } + + return true; +} + size_t PPPClass::printDriverInfo(Print &out) const { size_t bytes = 0; if (_dce == NULL || _mode == ESP_MODEM_MODE_DATA) { diff --git a/libraries/PPP/src/PPP.h b/libraries/PPP/src/PPP.h index 189825b61a1..703db6ef6b6 100644 --- a/libraries/PPP/src/PPP.h +++ b/libraries/PPP/src/PPP.h @@ -73,11 +73,26 @@ class PPPClass : public NetworkInterface { } // Send AT command with timeout in milliseconds + // Function deprecated - kept for backward compatibility + // Function may return empty string in multiple cases: + // - When timeout occured; + // - When "OK" AT response was received; + // - When "ERROR" AT response was received. + // For more detailed return, usage of `bool PPPClass::cmd(at_command, response, timeout)` is recommended. String cmd(const char *at_command, int timeout); String cmd(String at_command, int timeout) { return cmd(at_command.c_str(), timeout); } + // Send AT command with timeout in milliseconds + // When PPP is not started or timeout occurs: Function returns false; response string is not modified + // When AT error response is received: Function returns false; response contains "ERROR" or detailed AT response + // When AT success response is received: Function returns true; response contains "OK" or detailed AT response + bool cmd(const char *at_command, String &response, int timeout); + bool cmd(String at_command, String &response, int timeout) { + return cmd(at_command.c_str(), response, timeout); + } + // untested bool powerDown(); bool reset(); From 35de66592c5d56ce02d46922b2a5160c83e774e9 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Mon, 17 Nov 2025 13:10:12 +0200 Subject: [PATCH 2/2] fix(pr): Fix typo in comment about timeout occurrence --- libraries/PPP/src/PPP.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/PPP/src/PPP.h b/libraries/PPP/src/PPP.h index 703db6ef6b6..cb87b57fe57 100644 --- a/libraries/PPP/src/PPP.h +++ b/libraries/PPP/src/PPP.h @@ -75,7 +75,7 @@ class PPPClass : public NetworkInterface { // Send AT command with timeout in milliseconds // Function deprecated - kept for backward compatibility // Function may return empty string in multiple cases: - // - When timeout occured; + // - When timeout occurred; // - When "OK" AT response was received; // - When "ERROR" AT response was received. // For more detailed return, usage of `bool PPPClass::cmd(at_command, response, timeout)` is recommended.