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.

88 lines
2.4 KiB

8 years ago
8 years ago
6 years ago
8 years ago
6 years ago
6 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. * https://tiny.cc/tinygsm-readme
  8. *
  9. **************************************************************/
  10. // Select your modem:
  11. #define TINY_GSM_MODEM_SIM800
  12. // #define TINY_GSM_MODEM_SIM900
  13. // #define TINY_GSM_MODEM_SIM808
  14. // #define TINY_GSM_MODEM_SIM868
  15. // #define TINY_GSM_MODEM_UBLOX
  16. // #define TINY_GSM_MODEM_M95
  17. // #define TINY_GSM_MODEM_BG96
  18. // #define TINY_GSM_MODEM_A6
  19. // #define TINY_GSM_MODEM_A7
  20. // #define TINY_GSM_MODEM_M590
  21. // #define TINY_GSM_MODEM_MC60
  22. // #define TINY_GSM_MODEM_MC60E
  23. // #define TINY_GSM_MODEM_ESP8266
  24. // #define TINY_GSM_MODEM_XBEE
  25. // Set serial for debug console (to the Serial Monitor, speed 115200)
  26. #define SerialMon Serial
  27. // Set serial for AT commands (to the module)
  28. // Use Hardware Serial on Mega, Leonardo, Micro
  29. #ifndef __AVR_ATmega328P__
  30. #define SerialAT Serial1
  31. // or Software Serial on Uno, Nano
  32. #else
  33. #include <SoftwareSerial.h>
  34. SoftwareSerial SerialAT(2, 3); // RX, TX
  35. #endif
  36. #define TINY_GSM_DEBUG SerialMon
  37. #include <TinyGsmClient.h>
  38. // Module baud rate
  39. uint32_t rate = 0; // Set to 0 for Auto-Detect
  40. void setup() {
  41. // Set console baud rate
  42. SerialMon.begin(115200);
  43. delay(6000);
  44. }
  45. void loop() {
  46. if (!rate) {
  47. rate = TinyGsmAutoBaud(SerialAT);
  48. }
  49. if (!rate) {
  50. SerialMon.println(F("***********************************************************"));
  51. SerialMon.println(F(" Module does not respond!"));
  52. SerialMon.println(F(" Check your Serial wiring"));
  53. SerialMon.println(F(" Check the module is correctly powered and turned on"));
  54. SerialMon.println(F("***********************************************************"));
  55. delay(30000L);
  56. return;
  57. }
  58. SerialAT.begin(rate);
  59. // Access AT commands from Serial Monitor
  60. SerialMon.println(F("***********************************************************"));
  61. SerialMon.println(F(" You can now send AT commands"));
  62. SerialMon.println(F(" Enter \"AT\" (without quotes), and you should see \"OK\""));
  63. SerialMon.println(F(" If it doesn't work, select \"Both NL & CR\" in Serial Monitor"));
  64. SerialMon.println(F("***********************************************************"));
  65. while(true) {
  66. if (SerialAT.available()) {
  67. SerialMon.write(SerialAT.read());
  68. }
  69. if (SerialMon.available()) {
  70. SerialAT.write(SerialMon.read());
  71. }
  72. delay(0);
  73. }
  74. }