You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.2 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. /**************************************************************
  2. *
  3. * This script tries to auto-detect the baud rate
  4. * and allows direct AT commands access
  5. *
  6. * TinyGSM Getting Started guide:
  7. * http://tiny.cc/tiny-gsm-readme
  8. *
  9. **************************************************************/
  10. // Select your modem:
  11. #define TINY_GSM_MODEM_SIM800
  12. // #define TINY_GSM_MODEM_SIM900
  13. // #define TINY_GSM_MODEM_A6
  14. // #define TINY_GSM_MODEM_A7
  15. // #define TINY_GSM_MODEM_M590
  16. // #define TINY_GSM_MODEM_ESP8266
  17. // Set serial for debug console (to the Serial Monitor, speed 115200)
  18. #define SerialMon Serial
  19. // Set serial for AT commands (to the module)
  20. // Use Hardware Serial on Mega, Leonardo, Micro
  21. #define SerialAT Serial1
  22. // or Software Serial on Uno, Nano
  23. //#include <SoftwareSerial.h>
  24. //SoftwareSerial SerialAT(2, 3); // RX, TX
  25. #define TINY_GSM_DEBUG SerialMon
  26. #include <TinyGsmClient.h>
  27. // Module baud rate
  28. uint32_t rate = 0; // Set to 0 for Auto-Detect
  29. void setup() {
  30. // Set console baud rate
  31. SerialMon.begin(115200);
  32. delay(5000);
  33. }
  34. void loop() {
  35. if (!rate) {
  36. rate = TinyGsmAutoBaud(SerialAT);
  37. }
  38. if (!rate) {
  39. SerialMon.println(F("***********************************************************"));
  40. SerialMon.println(F(" Module does not respond!"));
  41. SerialMon.println(F(" Check your Serial wiring"));
  42. SerialMon.println(F(" Check the module is correctly powered and turned on"));
  43. SerialMon.println(F("***********************************************************"));
  44. delay(30000L);
  45. return;
  46. }
  47. SerialAT.begin(rate);
  48. // Access AT commands from Serial Monitor
  49. SerialMon.println(F("***********************************************************"));
  50. SerialMon.println(F(" You can now send AT commands"));
  51. SerialMon.println(F(" Enter \"AT\" (without quotes), and you should see \"OK\""));
  52. SerialMon.println(F(" If it doesn't work, select \"Both NL & CR\" in Serial Monitor"));
  53. SerialMon.println(F("***********************************************************"));
  54. while(true) {
  55. if (SerialAT.available()) {
  56. SerialMon.write(SerialAT.read());
  57. }
  58. if (SerialMon.available()) {
  59. SerialAT.write(SerialMon.read());
  60. }
  61. delay(0);
  62. }
  63. }