Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions libraries/PPP/src/PPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions libraries/PPP/src/PPP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading