1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-15 00:23:56 +01:00
Arduino/libraries/GSM/examples/Tools/TestModem/TestModem.ino

71 lines
1.5 KiB
Arduino
Raw Normal View History

2013-03-11 12:17:08 +01:00
/*
This example tests to see if the modem of the
GSM shield is working correctly. You do not need
2013-03-11 12:17:08 +01:00
a SIM card for this example.
2013-03-11 12:17:08 +01:00
Circuit:
* GSM shield attached
2013-03-11 12:17:08 +01:00
Created 12 Jun 2012
by David del Peral
modified 21 Nov 2012
by Tom Igoe
http://www.arduino.cc/en/Tutorial/GSMToolsTestModem
2013-03-11 12:17:08 +01:00
This sample code is part of the public domain
2013-03-11 12:17:08 +01:00
*/
// libraries
#include <GSM.h>
// modem verification object
GSMModem modem;
// IMEI variable
String IMEI = "";
void setup() {
2013-03-11 12:17:08 +01:00
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
2013-03-11 12:17:08 +01:00
// start modem test (reset and check response)
Serial.print("Starting modem test...");
if (modem.begin()) {
2013-03-11 12:17:08 +01:00
Serial.println("modem.begin() succeeded");
} else {
2013-03-11 12:17:08 +01:00
Serial.println("ERROR, no modem answer.");
}
2013-03-11 12:17:08 +01:00
}
void loop() {
2013-03-11 12:17:08 +01:00
// get modem IMEI
Serial.print("Checking IMEI...");
IMEI = modem.getIMEI();
2013-03-11 12:17:08 +01:00
// check IMEI response
if (IMEI != NULL) {
2013-03-11 12:17:08 +01:00
// show IMEI in serial monitor
Serial.println("Modem's IMEI: " + IMEI);
// reset modem to check booting:
Serial.print("Resetting modem...");
modem.begin();
// get and check IMEI one more time
if (modem.getIMEI() != NULL) {
2013-03-11 12:17:08 +01:00
Serial.println("Modem is functoning properly");
} else {
2013-03-11 12:17:08 +01:00
Serial.println("Error: getIMEI() failed after modem.begin()");
}
} else {
2013-03-11 12:17:08 +01:00
Serial.println("Error: Could not get IMEI");
}
// do nothing:
while (true);
2013-03-11 12:17:08 +01:00
}