Skip to content

Commit

Permalink
Increase AT timeout to 10s in AT_CellularSMS::send_sms
Browse files Browse the repository at this point in the history
For some devices sending can be slow (as an example see SIM800, it can be up to 60s), command is being run properly but default timeout is returning an invalid error.
See https://www.elecrow.com/wiki/images/2/20/SIM800_Series_AT_Command_Manual_V1.09.pdf
  • Loading branch information
davidalo authored and david-alonso-orca committed Apr 5, 2024
1 parent baf6a30 commit 0986ddd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions connectivity/cellular/source/framework/AT/AT_CellularSMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
}

_at.lock();
_at.set_at_timeout(10s);

int write_size = 0;

Expand All @@ -437,6 +438,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
// sending can be cancelled by giving <ESC> character (IRA 27).
_at.cmd_start(ESC);
_at.cmd_stop();
_at.restore_at_timeout();
_at.unlock();
return write_size;
}
Expand Down Expand Up @@ -482,6 +484,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
pdu_str = create_pdu(phone_number, message + i * concatenated_sms_length, pdu_len,
sms_count, i + 1, header_len);
if (!pdu_str) {
_at.restore_at_timeout();
_at.unlock();
return NSAPI_ERROR_NO_MEMORY;
}
Expand Down Expand Up @@ -509,6 +512,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
// sending can be cancelled by giving <ESC> character (IRA 27).
_at.cmd_start(ESC);
_at.cmd_stop();
_at.restore_at_timeout();
_at.unlock();
delete [] pdu_str;
return msg_write_len;
Expand All @@ -523,13 +527,15 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
delete [] pdu_str;
remaining_len -= concatenated_sms_length;
if (_at.get_last_error() != NSAPI_ERROR_OK) {
_at.restore_at_timeout();
return _at.unlock_return_error();
}
}
}

_sms_message_ref_number++;
nsapi_error_t ret = _at.get_last_error();
_at.restore_at_timeout();
_at.unlock();

return (ret == NSAPI_ERROR_OK) ? msg_len : ret;
Expand Down

0 comments on commit 0986ddd

Please sign in to comment.