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.

85 lines
2.4 KiB

8 years ago
8 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
6 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_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. #define SerialAT Serial1
  30. // or Software Serial on Uno, Nano
  31. //#include <SoftwareSerial.h>
  32. //SoftwareSerial SerialAT(2, 3); // RX, TX
  33. #define TINY_GSM_DEBUG SerialMon
  34. #include <TinyGsmClient.h>
  35. // Module baud rate
  36. uint32_t rate = 0; // Set to 0 for Auto-Detect
  37. void setup() {
  38. // Set console baud rate
  39. SerialMon.begin(115200);
  40. delay(3000);
  41. }
  42. void loop() {
  43. if (!rate) {
  44. rate = TinyGsmAutoBaud(SerialAT);
  45. }
  46. if (!rate) {
  47. SerialMon.println(F("***********************************************************"));
  48. SerialMon.println(F(" Module does not respond!"));
  49. SerialMon.println(F(" Check your Serial wiring"));
  50. SerialMon.println(F(" Check the module is correctly powered and turned on"));
  51. SerialMon.println(F("***********************************************************"));
  52. delay(30000L);
  53. return;
  54. }
  55. SerialAT.begin(rate);
  56. // Access AT commands from Serial Monitor
  57. SerialMon.println(F("***********************************************************"));
  58. SerialMon.println(F(" You can now send AT commands"));
  59. SerialMon.println(F(" Enter \"AT\" (without quotes), and you should see \"OK\""));
  60. SerialMon.println(F(" If it doesn't work, select \"Both NL & CR\" in Serial Monitor"));
  61. SerialMon.println(F("***********************************************************"));
  62. while(true) {
  63. if (SerialAT.available()) {
  64. SerialMon.write(SerialAT.read());
  65. }
  66. if (SerialMon.available()) {
  67. SerialAT.write(SerialMon.read());
  68. }
  69. delay(0);
  70. }
  71. }