Advertisement
pippero

Untitled

Jan 29th, 2021
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include <GSM.h>
  2.  
  3. // PIN Number
  4. #define PINNUMBER
  5. GSMScanner scannerNetworks;
  6. // initialize the library instance
  7.  
  8. GSM gsmAccess; // include a 'true' parameter to enable debugging
  9.  
  10.  
  11.  
  12. GSMModem modemTest;
  13.  
  14. // Save data variables
  15.  
  16. String IMEI = "";
  17.  
  18. // serial monitor result messages
  19.  
  20. String errortext = "ERROR";
  21.  
  22. void setup() {
  23.  
  24. // initialize serial communications and wait for port to open:
  25.  
  26. Serial.begin(9600);
  27.  
  28. while (!Serial) {
  29.  
  30. ; // wait for serial port to connect. Needed for Leonardo only
  31.  
  32. }
  33.  
  34. Serial.println("GSM networks scanner");
  35.  
  36. scannerNetworks.begin();
  37.  
  38. // connection state
  39.  
  40. bool notConnected = true;
  41.  
  42. // Start GSM shield
  43.  
  44. // If your SIM has PIN, pass it as a parameter of begin() in quotes
  45.  
  46. while (notConnected) {
  47.  
  48. if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
  49.  
  50. notConnected = false;
  51.  
  52. } else {
  53.  
  54. Serial.println("Not connected");
  55.  
  56. delay(1000);
  57.  
  58. }
  59.  
  60. }
  61.  
  62. // get modem parameters
  63.  
  64. // IMEI, modem unique identifier
  65.  
  66. Serial.print("Modem IMEI: ");
  67.  
  68. IMEI = modemTest.getIMEI();
  69.  
  70. IMEI.replace("\n", "");
  71.  
  72. if (IMEI != NULL) {
  73.  
  74. Serial.println(IMEI);
  75.  
  76. }
  77. }
  78.  
  79. void loop() {
  80.  
  81. // scan for existing networks, displays a list of networks
  82.  
  83. Serial.println("Scanning available networks. May take some seconds.");
  84.  
  85. Serial.println(scannerNetworks.readNetworks());
  86.  
  87. // currently connected carrier
  88.  
  89. Serial.print("Current carrier: ");
  90.  
  91. Serial.println(scannerNetworks.getCurrentCarrier());
  92.  
  93. // returns strength and ber
  94.  
  95. // signal strength in 0-31 scale. 31 means power > 51dBm
  96.  
  97. // BER is the Bit Error Rate. 0-7 scale. 99=not detectable
  98.  
  99. Serial.print("Signal Strength: ");
  100.  
  101. Serial.print(scannerNetworks.getSignalStrength());
  102.  
  103. Serial.println(" [0-31]");
  104. int isAccessAlive();
  105. Serial.println(gsmAccess.isAccessAlive());
  106. if (!gsmAccess.isAccessAlive())
  107. Serial.println(F("gsm access is down!"));
  108. //if (!(gprs.status() == GPRS_READY))
  109. //Serial.println(F("gprs status is not ready!"));
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement