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