Rev | Line | |
---|
[136] | 1 | /*
|
---|
| 2 |
|
---|
| 3 | This example tests to see if the modem of the
|
---|
| 4 | GSM shield is working correctly. You do not need
|
---|
| 5 | a SIM card for this example.
|
---|
| 6 |
|
---|
| 7 | Circuit:
|
---|
| 8 | * GSM shield attached
|
---|
| 9 |
|
---|
| 10 | Created 12 Jun 2012
|
---|
| 11 | by David del Peral
|
---|
| 12 | modified 21 Nov 2012
|
---|
| 13 | by Tom Igoe
|
---|
| 14 |
|
---|
| 15 | http://arduino.cc/en/Tutorial/GSMToolsTestModem
|
---|
| 16 |
|
---|
| 17 | This sample code is part of the public domain
|
---|
| 18 |
|
---|
| 19 | */
|
---|
| 20 |
|
---|
| 21 | // libraries
|
---|
| 22 | #include <GSM.h>
|
---|
| 23 |
|
---|
| 24 | // modem verification object
|
---|
| 25 | GSMModem modem;
|
---|
| 26 |
|
---|
| 27 | // IMEI variable
|
---|
| 28 | String IMEI = "";
|
---|
| 29 |
|
---|
| 30 | void setup()
|
---|
| 31 | {
|
---|
| 32 | // initialize serial communications and wait for port to open:
|
---|
| 33 | Serial.begin(9600);
|
---|
| 34 | while (!Serial) {
|
---|
| 35 | ; // wait for serial port to connect. Needed for Leonardo only
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | // start modem test (reset and check response)
|
---|
| 39 | Serial.print("Starting modem test...");
|
---|
| 40 | if (modem.begin())
|
---|
| 41 | Serial.println("modem.begin() succeeded");
|
---|
| 42 | else
|
---|
| 43 | Serial.println("ERROR, no modem answer.");
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | void loop()
|
---|
| 47 | {
|
---|
| 48 | // get modem IMEI
|
---|
| 49 | Serial.print("Checking IMEI...");
|
---|
| 50 | IMEI = modem.getIMEI();
|
---|
| 51 |
|
---|
| 52 | // check IMEI response
|
---|
| 53 | if (IMEI != NULL)
|
---|
| 54 | {
|
---|
| 55 | // show IMEI in serial monitor
|
---|
| 56 | Serial.println("Modem's IMEI: " + IMEI);
|
---|
| 57 | // reset modem to check booting:
|
---|
| 58 | Serial.print("Resetting modem...");
|
---|
| 59 | modem.begin();
|
---|
| 60 | // get and check IMEI one more time
|
---|
| 61 | if (modem.getIMEI() != NULL)
|
---|
| 62 | {
|
---|
| 63 | Serial.println("Modem is functoning properly");
|
---|
| 64 | }
|
---|
| 65 | else
|
---|
| 66 | {
|
---|
| 67 | Serial.println("Error: getIMEI() failed after modem.begin()");
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 | else
|
---|
| 71 | {
|
---|
| 72 | Serial.println("Error: Could not get IMEI");
|
---|
| 73 | }
|
---|
| 74 | // do nothing:
|
---|
| 75 | while (true);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.