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.

199 lines
4.8 KiB

  1. /**************************************************************
  2. *
  3. * TinyGSM Getting Started guide:
  4. * https://tiny.cc/tinygsm-readme
  5. *
  6. * NOTE:
  7. * Some of the functions may be unavailable for your modem.
  8. * Just comment them out.
  9. *
  10. **************************************************************/
  11. // Select your modem:
  12. //#define TINY_GSM_MODEM_SIM800
  13. // #define TINY_GSM_MODEM_SIM808
  14. // #define TINY_GSM_MODEM_SIM900
  15. #define TINY_GSM_MODEM_SIM7000
  16. // #define TINY_GSM_MODEM_UBLOX
  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. // 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, ESP32
  25. #include "HardwareSerial.h"
  26. #define SerialAT Serial2
  27. // or Software Serial on Uno, Nano
  28. //#include <SoftwareSerial.h>
  29. //SoftwareSerial SerialAT(2, 3); // RX, TX
  30. #define MODEM_PWRKEY 18
  31. //#define DUMP_AT_COMMANDS
  32. #define TINY_GSM_DEBUG SerialMon
  33. // Set phone numbers, if you want to test SMS and Calls
  34. //#define SMS_TARGET "+4366066033403"
  35. //#define CALL_TARGET "+43xxxxxx"
  36. // Your GPRS credentials
  37. // Leave empty, if missing user or pass
  38. const char apn[] = "drei.at";
  39. const char user[] = "";
  40. const char pass[] = "";
  41. #include <TinyGsmClient.h>
  42. #ifdef DUMP_AT_COMMANDS
  43. #include <StreamDebugger.h>
  44. StreamDebugger debugger(SerialAT, SerialMon);
  45. TinyGsm modem(debugger);
  46. #else
  47. TinyGsm modem(SerialAT);
  48. TinyGsmClient client(modem);
  49. #endif
  50. void setup() {
  51. // Set pwr pin 18 (ESP32) --> shield's PWRKEY
  52. pinMode(MODEM_PWRKEY, OUTPUT);
  53. powerOn(); //function for powering on SIM7000
  54. // Set console baud rate
  55. SerialMon.begin(115200);
  56. delay(1000);
  57. SerialAT.begin(9600);
  58. delay(1000);
  59. // Set GSM module baud rate
  60. //TinyGsmAutoBaud(SerialAT);
  61. }
  62. void loop() {
  63. // Restart takes quite some time
  64. // To skip it, call init() instead of restart()
  65. DBG("Initializing modem...");
  66. if (!modem.restart()) {
  67. delay(15000);
  68. return;
  69. }
  70. //String modemInfo = modem.getModemInfo();
  71. //DBG("Modem:", modemInfo);
  72. // Unlock your SIM card with a PIN
  73. //modem.simUnlock("1234");
  74. // Network modes for SIM7000 (2-Automatic),(13-GSM Only),(38-LTE Only),(51-GSM And LTE Only)
  75. String NetworkModes = modem.getNetworkModes();
  76. DBG("Network Modes:", NetworkModes);
  77. String NetworkMode = modem.setNetworkMode(0);
  78. DBG("Changed Network Mode:", NetworkMode);
  79. // Preferred LTE mode selection (1-Cat-M),(2-NB-IoT),(3-Cat-M And NB-IoT)
  80. String PreferredModes = modem.getPreferredModes();
  81. DBG("Preferred Modes:", PreferredModes);
  82. String PreferredMode = modem.setPreferredMode(3);
  83. DBG("Changed Preferred Mode:", PreferredMode);
  84. /* DBG("Waiting for network...");
  85. if (!modem.waitForNetwork()) {
  86. delay(10000);
  87. return;
  88. }
  89. if (modem.isNetworkConnected()) {
  90. DBG("Network connected");
  91. }*/
  92. /*
  93. DBG("Connecting to", apn);
  94. if (!modem.gprsConnect(apn, user, pass)) {
  95. delay(10000);
  96. return;
  97. }
  98. bool res = modem.isGprsConnected();
  99. DBG("GPRS status:", res ? "connected" : "not connected");
  100. String ccid = modem.getSimCCID();
  101. DBG("CCID:", ccid);
  102. String imei = modem.getIMEI();
  103. DBG("IMEI:", imei);
  104. String cop = modem.getOperator();
  105. DBG("Operator:", cop);
  106. IPAddress local = modem.localIP();
  107. DBG("Local IP:", local);
  108. int csq = modem.getSignalQuality();
  109. DBG("Signal quality:", csq);
  110. // This is NOT supported on M590
  111. int battLevel = modem.getBattPercent();
  112. DBG("Battery lavel:", battLevel);
  113. // This is only supported on SIMxxx series
  114. float battVoltage = modem.getBattVoltage() / 1000.0F;
  115. DBG("Battery voltage:", battVoltage);
  116. // This is only supported on SIMxxx series
  117. String gsmLoc = modem.getGsmLocation();
  118. DBG("GSM location:", gsmLoc);
  119. // This is only supported on SIMxxx series
  120. String gsmTime = modem.getGSMDateTime(DATE_TIME);
  121. DBG("GSM Time:", gsmTime);
  122. String gsmDate = modem.getGSMDateTime(DATE_DATE);
  123. DBG("GSM Date:", gsmDate);
  124. modem.enableGPS();
  125. String gps_raw = modem.getGPSraw();
  126. modem.disableGPS();
  127. DBG("GPS raw data:", gps_raw);
  128. #if defined(SMS_TARGET)
  129. res = modem.sendSMS(SMS_TARGET, String("Hello from ") + imei);
  130. DBG("SMS:", res ? "OK" : "fail");
  131. // This is only supported on SIMxxx series
  132. res = modem.sendSMS_UTF16(SMS_TARGET, u"Привіііт!", 9);
  133. DBG("UTF16 SMS:", res ? "OK" : "fail");
  134. #endif
  135. modem.gprsDisconnect();
  136. if (!modem.isGprsConnected()) {
  137. DBG("GPRS disconnected");
  138. } else {
  139. DBG("GPRS disconnect: Failed.");
  140. }
  141. */
  142. // Try to power-off (modem may decide to restart automatically)
  143. // To turn off modem completely, please use Reset/Enable pins
  144. modem.poweroff();
  145. DBG("Poweroff.");
  146. // Do nothing forevermore
  147. while (true) {
  148. modem.maintain();
  149. }
  150. }
  151. void powerOn() {
  152. digitalWrite(MODEM_PWRKEY, LOW);
  153. delay(100);
  154. digitalWrite(MODEM_PWRKEY, HIGH);
  155. }