Browse Source

Add TinyGsmAutoBaud

v_master
Volodymyr Shymanskyy 7 years ago
parent
commit
b534d6a5f6
1 changed files with 22 additions and 0 deletions
  1. +22
    -0
      TinyGsmCommon.h

+ 22
- 0
TinyGsmCommon.h View File

@ -71,4 +71,26 @@ const T& TinyGsmMax(const T& a, const T& b)
return (b < a) ? a : b;
}
template<class T>
uint32_t TinyGsmAutoBaud(T& SerialAT)
{
static uint32_t rates[] = { 115200, 57600, 38400, 19200, 9600, 74400, 74880, 230400, 460800, 2400, 4800, 14400, 28800 };
for (unsigned i = 0; i < sizeof(rates)/sizeof(rates[0]); i++) {
uint32_t rate = rates[i];
DBG("Trying baud rate", rate, "...");
SerialAT.begin(rate);
delay(10);
for (int i=0; i<3; i++) {
SerialAT.print("AT\r\n");
String input = SerialAT.readString();
if (input.indexOf("OK") >= 0) {
DBG("Modem responded at rate", rate);
return rate;
}
}
}
return 0;
}
#endif

Loading…
Cancel
Save