mirror of
				https://github.com/KevinMidboe/TinyGSM.git
				synced 2025-10-29 18:00:18 +00:00 
			
		
		
		
	Allow to specify rate manually
This commit is contained in:
		| @@ -8,6 +8,13 @@ | |||||||
|  * |  * | ||||||
|  **************************************************************/ |  **************************************************************/ | ||||||
|  |  | ||||||
|  | // Select your modem: | ||||||
|  | #define TINY_GSM_MODEM_SIM800 | ||||||
|  | //#define TINY_GSM_MODEM_SIM900 | ||||||
|  | //#define TINY_GSM_MODEM_M590 | ||||||
|  |  | ||||||
|  | #include <TinyGsmClient.h> | ||||||
|  |  | ||||||
| // Set serial for debug console (to the Serial Monitor, speed 115200) | // Set serial for debug console (to the Serial Monitor, speed 115200) | ||||||
| #define SerialMon Serial | #define SerialMon Serial | ||||||
|  |  | ||||||
| @@ -19,9 +26,11 @@ | |||||||
| //#include <SoftwareSerial.h> | //#include <SoftwareSerial.h> | ||||||
| //SoftwareSerial SerialAT(2, 3); // RX, TX | //SoftwareSerial SerialAT(2, 3); // RX, TX | ||||||
|  |  | ||||||
| #include <TinyGsmClient.h> |  | ||||||
| TinyGsm modem(SerialAT); | TinyGsm modem(SerialAT); | ||||||
|  |  | ||||||
|  | // Module baud rate | ||||||
|  | uint32_t rate = 0; // Set to 0 for Auto-Detect | ||||||
|  |  | ||||||
| void setup() { | void setup() { | ||||||
|   // Set console baud rate |   // Set console baud rate | ||||||
|   SerialMon.begin(115200); |   SerialMon.begin(115200); | ||||||
| @@ -29,22 +38,23 @@ void setup() { | |||||||
| } | } | ||||||
|  |  | ||||||
| void loop() { | void loop() { | ||||||
|   // Detect module baud rate |  | ||||||
|   uint32_t rate = 0; |  | ||||||
|   uint32_t rates[] = { 115200, 9600, 57600, 19200, 74400, 74880 }; |  | ||||||
|  |  | ||||||
|   SerialMon.println("Autodetecting baud rate"); |   if (!rate) { | ||||||
|   for (unsigned i = 0; i < sizeof(rates)/sizeof(rates[0]); i++) { |       static uint32_t rates[] = { 115200, 9600, 57600, 19200, 38400, 74400, 74880, 230400, 460800, 2400, 4800, 14400, 28800 }; | ||||||
|     SerialMon.print(String("Trying baud rate ") + rates[i] + "... "); |  | ||||||
|     SerialAT.begin(rates[i]); |       SerialMon.println("Autodetecting baud rate"); | ||||||
|     delay(10); |       for (unsigned i = 0; i < sizeof(rates)/sizeof(rates[0]); i++) { | ||||||
|     if (modem.autoBaud(2000)) { |         SerialMon.print(String("Trying baud rate ") + rates[i] + "... "); | ||||||
|       rate = rates[i]; |         SerialAT.begin(rates[i]); | ||||||
|       SerialMon.println(F("OK")); |         delay(10); | ||||||
|       break; |         if (modem.autoBaud(1000)) { | ||||||
|     } else { |           rate = rates[i]; | ||||||
|       SerialMon.println(F("fail")); |           SerialMon.println(F("OK")); | ||||||
|     } |           break; | ||||||
|  |         } else { | ||||||
|  |           SerialMon.println(F("fail")); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   if (!rate) { |   if (!rate) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user