[136] | 1 | /*
|
---|
| 2 |
|
---|
| 3 | GSM Scan Networks
|
---|
| 4 |
|
---|
| 5 | This example prints out the IMEI number of the modem,
|
---|
| 6 | then checks to see if it's connected to a carrier. If so,
|
---|
| 7 | it prints the phone number associated with the card.
|
---|
| 8 | Then it scans for nearby networks and prints out their signal strengths.
|
---|
| 9 |
|
---|
| 10 | Circuit:
|
---|
| 11 | * GSM shield
|
---|
| 12 | * SIM card
|
---|
| 13 |
|
---|
| 14 | Created 8 Mar 2012
|
---|
| 15 | by Tom Igoe, implemented by Javier Carazo
|
---|
| 16 | Modified 4 Feb 2013
|
---|
| 17 | by Scott Fitzgerald
|
---|
| 18 |
|
---|
| 19 | http://arduino.cc/en/Tutorial/GSMToolsGsmScanNetworks
|
---|
| 20 |
|
---|
| 21 | This example code is part of the public domain
|
---|
| 22 | */
|
---|
| 23 |
|
---|
| 24 | // libraries
|
---|
| 25 | #include <GSM.h>
|
---|
| 26 |
|
---|
| 27 | // PIN Number
|
---|
| 28 | #define PINNUMBER ""
|
---|
| 29 |
|
---|
| 30 | // initialize the library instance
|
---|
| 31 | GSM gsmAccess; // include a 'true' parameter to enable debugging
|
---|
| 32 | GSMScanner scannerNetworks;
|
---|
| 33 | GSMModem modemTest;
|
---|
| 34 |
|
---|
| 35 | // Save data variables
|
---|
| 36 | String IMEI = "";
|
---|
| 37 |
|
---|
| 38 | // serial monitor result messages
|
---|
| 39 | String errortext = "ERROR";
|
---|
| 40 |
|
---|
| 41 | void setup()
|
---|
| 42 | {
|
---|
| 43 | // initialize serial communications and wait for port to open:
|
---|
| 44 | Serial.begin(9600);
|
---|
| 45 | while (!Serial) {
|
---|
| 46 | ; // wait for serial port to connect. Needed for Leonardo only
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | Serial.println("GSM networks scanner");
|
---|
| 50 | scannerNetworks.begin();
|
---|
| 51 |
|
---|
| 52 | // connection state
|
---|
| 53 | boolean notConnected = true;
|
---|
| 54 |
|
---|
| 55 | // Start GSM shield
|
---|
| 56 | // If your SIM has PIN, pass it as a parameter of begin() in quotes
|
---|
| 57 | while (notConnected)
|
---|
| 58 | {
|
---|
| 59 | if (gsmAccess.begin(PINNUMBER) == GSM_READY)
|
---|
| 60 | notConnected = false;
|
---|
| 61 | else
|
---|
| 62 | {
|
---|
| 63 | Serial.println("Not connected");
|
---|
| 64 | delay(1000);
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | // get modem parameters
|
---|
| 69 | // IMEI, modem unique identifier
|
---|
| 70 | Serial.print("Modem IMEI: ");
|
---|
| 71 | IMEI = modemTest.getIMEI();
|
---|
| 72 | IMEI.replace("\n", "");
|
---|
| 73 | if (IMEI != NULL)
|
---|
| 74 | Serial.println(IMEI);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | void loop()
|
---|
| 78 | {
|
---|
| 79 | // scan for existing networks, displays a list of networks
|
---|
| 80 | Serial.println("Scanning available networks. May take some seconds.");
|
---|
| 81 | Serial.println(scannerNetworks.readNetworks());
|
---|
| 82 |
|
---|
| 83 | // currently connected carrier
|
---|
| 84 | Serial.print("Current carrier: ");
|
---|
| 85 | Serial.println(scannerNetworks.getCurrentCarrier());
|
---|
| 86 |
|
---|
| 87 | // returns strength and ber
|
---|
| 88 | // signal strength in 0-31 scale. 31 means power > 51dBm
|
---|
| 89 | // BER is the Bit Error Rate. 0-7 scale. 99=not detectable
|
---|
| 90 | Serial.print("Signal Strength: ");
|
---|
| 91 | Serial.print(scannerNetworks.getSignalStrength());
|
---|
| 92 | Serial.println(" [0-31]");
|
---|
| 93 |
|
---|
| 94 | }
|
---|
| 95 |
|
---|