Skip to content

Commit 3ffc324

Browse files
committed
Modem: add retry if begin fails
1 parent 836caeb commit 3ffc324

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

libraries/WiFiS3/src/Modem.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ ModemClass::~ModemClass() {
3030
}
3131

3232
/* -------------------------------------------------------------------------- */
33-
void ModemClass::begin(int badurate){
33+
void ModemClass::begin(int badurate, int retry){
3434
/* -------------------------------------------------------------------------- */
3535
if(_serial != nullptr && !beginned) {
3636
_serial->begin(badurate);
3737
string res = "";
3838
_serial->flush();
3939
modem.timeout(500);
40-
beginned = modem.write(string(PROMPT(_SOFTRESETWIFI)),res, "%s" , CMD(_SOFTRESETWIFI));
40+
while(!beginned && retry > 0) {
41+
beginned = modem.write(string(PROMPT(_SOFTRESETWIFI)),res, "%s" , CMD(_SOFTRESETWIFI));
42+
retry -= 1;
43+
}
4144
modem.timeout(MODEM_TIMEOUT);
4245
}
4346
}

libraries/WiFiS3/src/Modem.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ModemClass {
2222
ModemClass(UART * _serial);
2323
~ModemClass();
2424

25-
void begin(int badurate = 115200);
25+
void begin(int badurate = 115200, int retry = 3);
2626
void end();
2727
bool write(const std::string &cmd, std::string &str, const char * fmt, ...);
2828
void write_nowait(const std::string &cmd, std::string &str, const char * fmt, ...);

0 commit comments

Comments
 (0)