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..cb87b57fe57 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 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. 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();