Skip to content

Commit 1899a0a

Browse files
committed
feat(ppp): Add variation of PPPClass::cmd()
Add variation of PPPClass::cmd() function that returns more detailed response.
1 parent fc85010 commit 1899a0a

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

libraries/PPP/src/PPP.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,30 @@ String PPPClass::cmd(const char *at_command, int timeout) {
757757
return String(out);
758758
}
759759

760+
bool PPPClass::cmd(const char *at_command, String &response, int timeout) {
761+
PPP_CMD_MODE_CHECK(false);
762+
763+
char out[128] = {0};
764+
esp_err_t err = _esp_modem_at(_dce, at_command, out, timeout);
765+
response = String(out);
766+
767+
if (err != ESP_OK) {
768+
log_e("esp_modem_at failed %d %s", err, esp_err_to_name(err));
769+
770+
if (err == ESP_FAIL && response.isEmpty()) {
771+
response = "ERROR";
772+
}
773+
774+
return false;
775+
}
776+
777+
if (response.isEmpty()) {
778+
response = "OK";
779+
}
780+
781+
return true;
782+
}
783+
760784
size_t PPPClass::printDriverInfo(Print &out) const {
761785
size_t bytes = 0;
762786
if (_dce == NULL || _mode == ESP_MODEM_MODE_DATA) {

libraries/PPP/src/PPP.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,26 @@ class PPPClass : public NetworkInterface {
7373
}
7474

7575
// Send AT command with timeout in milliseconds
76+
// Function deprecated - kept for backward compatibility
77+
// Function may return empty string in multiple cases:
78+
// - When timeout occured;
79+
// - When "OK" AT response was received;
80+
// - When "ERROR" AT response was received.
81+
// For more detailed return, usage of `bool PPPClass::cmd(at_command, response, timeout)` is recommended.
7682
String cmd(const char *at_command, int timeout);
7783
String cmd(String at_command, int timeout) {
7884
return cmd(at_command.c_str(), timeout);
7985
}
8086

87+
// Send AT command with timeout in milliseconds
88+
// When PPP is not started or timeout occurs: Function returns false; response string is not modified
89+
// When AT error response is received: Function returns false; response contains "ERROR" or detailed AT response
90+
// When AT success response is received: Function returns true; response contains "OK" or detailed AT response
91+
bool cmd(const char *at_command, String &response, int timeout);
92+
bool cmd(String at_command, String &response, int timeout) {
93+
return cmd(at_command.c_str(), response, timeout);
94+
}
95+
8196
// untested
8297
bool powerDown();
8398
bool reset();

0 commit comments

Comments
 (0)