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.

82 lines
2.3 KiB

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