Add TinyGsmAutoBaud
This commit is contained in:
@@ -71,4 +71,26 @@ const T& TinyGsmMax(const T& a, const T& b)
|
|||||||
return (b < a) ? a : 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
|
#endif
|
||||||
|
Reference in New Issue
Block a user