diff options
Diffstat (limited to 'libraries/GSM/examples/Tools')
6 files changed, 749 insertions, 0 deletions
diff --git a/libraries/GSM/examples/Tools/BandManagement/BandManagement.ino b/libraries/GSM/examples/Tools/BandManagement/BandManagement.ino new file mode 100644 index 0000000..84d8c71 --- /dev/null +++ b/libraries/GSM/examples/Tools/BandManagement/BandManagement.ino @@ -0,0 +1,120 @@ +/* + Band Management + + This sketch, for the Arduino GSM shield, checks the band + currently configured in the modem and allows you to change + it. + + Please check http://www.worldtimezone.com/gsm.html + Usual configurations: + Europe, Africa, Middle East: E-GSM(900)+DCS(1800) + USA, Canada, South America: GSM(850)+PCS(1900) + Mexico: PCS(1900) + Brazil: GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900) + + + Circuit: + * GSM shield + + created 12 June 2012 + by Javier Zorzano, Scott Fitzgerald + + This example is in the public domain. + */ + +// libraries +#include <GSM.h> + +// initialize the library instance +GSMBand band; + +void setup() +{ + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + // Beginning the band manager restarts the modem + Serial.println("Restarting modem..."); + band.begin(); + Serial.println("Modem restarted."); + +}; + + +void loop() +{ + // Get current band + String bandName = band.getBand(); // Get and print band name + Serial.print("Current band:"); + Serial.println(bandName); + Serial.println("Want to change the band you’re on?"); + String newBandName; + newBandName = askUser(); + // Tell the user what we are about to do… + Serial.print("\nConfiguring band "); + Serial.println(newBandName); + // Change the band + boolean operationSuccess; + operationSuccess = band.setBand(newBandName); + // Tell the user if the operation was OK + if(operationSuccess) + { + Serial.println("Success"); + } + else + { + Serial.println("Error while changing band"); + } + + if(operationSuccess) + { + while(true); + } +} + +// This function offers the user different options +// through the Serial interface +// The user selects one +String askUser() +{ + String newBand; + Serial.println("Select band:"); + // Print the different options + Serial.println("1 : E-GSM(900)"); + Serial.println("2 : DCS(1800)"); + Serial.println("3 : PCS(1900)"); + Serial.println("4 : E-GSM(900)+DCS(1800) ex: Europe"); + Serial.println("5 : GSM(850)+PCS(1900) Ex: USA, South Am."); + Serial.println("6 : GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)"); + + // Empty the incoming buffer + while(Serial.available()) + Serial.read(); + + // Wait for an answer, just look at the first character + while(!Serial.available()); + char c= Serial.read(); + if(c=='1') + newBand=GSM_MODE_EGSM; + else if(c=='2') + newBand=GSM_MODE_DCS; + else if(c=='3') + newBand=GSM_MODE_PCS; + else if(c=='4') + newBand=GSM_MODE_EGSM_DCS; + else if(c=='5') + newBand=GSM_MODE_GSM850_PCS; + else if(c=='6') + newBand=GSM_MODE_GSM850_EGSM_DCS_PCS; + else + newBand="GSM_MODE_UNDEFINED"; + return newBand; +} + + + + + diff --git a/libraries/GSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino b/libraries/GSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino new file mode 100644 index 0000000..0e442eb --- /dev/null +++ b/libraries/GSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino @@ -0,0 +1,95 @@ +/* + + GSM Scan Networks + + This example prints out the IMEI number of the modem, + then checks to see if it's connected to a carrier. If so, + it prints the phone number associated with the card. + Then it scans for nearby networks and prints out their signal strengths. + + Circuit: + * GSM shield + * SIM card + + Created 8 Mar 2012 + by Tom Igoe, implemented by Javier Carazo + Modified 4 Feb 2013 + by Scott Fitzgerald + + http://arduino.cc/en/Tutorial/GSMToolsGsmScanNetworks + + This example code is part of the public domain + */ + +// libraries +#include <GSM.h> + +// PIN Number +#define PINNUMBER "" + +// initialize the library instance +GSM gsmAccess; // include a 'true' parameter to enable debugging +GSMScanner scannerNetworks; +GSMModem modemTest; + +// Save data variables +String IMEI = ""; + +// serial monitor result messages +String errortext = "ERROR"; + +void setup() +{ + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + Serial.println("GSM networks scanner"); + scannerNetworks.begin(); + + // connection state + boolean notConnected = true; + + // Start GSM shield + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while(notConnected) + { + if(gsmAccess.begin(PINNUMBER)==GSM_READY) + notConnected = false; + else + { + Serial.println("Not connected"); + delay(1000); + } + } + + // get modem parameters + // IMEI, modem unique identifier + Serial.print("Modem IMEI: "); + IMEI = modemTest.getIMEI(); + IMEI.replace("\n",""); + if(IMEI != NULL) + Serial.println(IMEI); +} + +void loop() +{ + // scan for existing networks, displays a list of networks + Serial.println("Scanning available networks. May take some seconds."); + Serial.println(scannerNetworks.readNetworks()); + + // currently connected carrier + Serial.print("Current carrier: "); + Serial.println(scannerNetworks.getCurrentCarrier()); + + // returns strength and ber + // signal strength in 0-31 scale. 31 means power > 51dBm + // BER is the Bit Error Rate. 0-7 scale. 99=not detectable + Serial.print("Signal Strength: "); + Serial.print(scannerNetworks.getSignalStrength()); + Serial.println(" [0-31]"); + +} + diff --git a/libraries/GSM/examples/Tools/PinManagement/PinManagement.ino b/libraries/GSM/examples/Tools/PinManagement/PinManagement.ino new file mode 100644 index 0000000..654d1b8 --- /dev/null +++ b/libraries/GSM/examples/Tools/PinManagement/PinManagement.ino @@ -0,0 +1,168 @@ +/* + + This example enables you to change or remove the PIN number of + a SIM card inserted into a GSM shield. + + Circuit: + * GSM shield + * SIM card + + Created 12 Jun 2012 + by David del Peral + + This example code is part of the public domain + + http://arduino.cc/en/Tutorial/GSMToolsPinManagement + + */ + +// libraries +#include <GSM.h> + +// pin manager object +GSMPIN PINManager; + +// save input in serial by user +String user_input = ""; + +// authenticated with PIN code +boolean auth = false; + +// serial monitor result messages +String oktext = "OK"; +String errortext = "ERROR"; + +void setup() +{ + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + Serial.println("Change PIN example\n"); + PINManager.begin(); + + // check if the SIM have pin lock + while(!auth){ + int pin_query = PINManager.isPIN(); + if(pin_query == 1) + { + // if SIM is locked, enter PIN code + Serial.print("Enter PIN code: "); + user_input = readSerial(); + // check PIN code + if(PINManager.checkPIN(user_input) == 0) + { + auth = true; + PINManager.setPINUsed(true); + Serial.println(oktext); + } + else + { + // if PIN code was incorrected + Serial.println("Incorrect PIN. Remember that you have 3 opportunities."); + } + } + else if(pin_query == -1) + { + // PIN code is locked, user must enter PUK code + Serial.println("PIN locked. Enter PUK code: "); + String puk = readSerial(); + Serial.print("Now, enter a new PIN code: "); + user_input = readSerial(); + // check PUK code + if(PINManager.checkPUK(puk, user_input) == 0) + { + auth = true; + PINManager.setPINUsed(true); + Serial.println(oktext); + } + else + { + // if PUK o the new PIN are incorrect + Serial.println("Incorrect PUK or invalid new PIN. Try again!."); + } + } + else if(pin_query == -2) + { + // the worst case, PIN and PUK are locked + Serial.println("PIN & PUK locked. Use PIN2/PUK2 in a mobile phone."); + while(true); + } + else + { + // SIM does not requires authetication + Serial.println("No pin necessary."); + auth = true; + } + } + + // start GSM shield + Serial.print("Checking register in GSM network..."); + if(PINManager.checkReg() == 0) + Serial.println(oktext); + // if you are connect by roaming + else if(PINManager.checkReg() == 1) + Serial.println("ROAMING " + oktext); + else + { + // error connection + Serial.println(errortext); + while(true); + } +} + +void loop() +{ + // Function loop implements pin management user menu + // Only if you SIM use pin lock, you can change PIN code + // user_op variables save user option + + Serial.println("Choose an option:\n1 - On/Off PIN."); + if(PINManager.getPINUsed()) + Serial.println("2 - Change PIN."); + String user_op = readSerial(); + if(user_op == "1") + { + Serial.println("Enter your PIN code:"); + user_input = readSerial(); + // activate/deactivate PIN lock + PINManager.switchPIN(user_input); + } + else if(user_op == "2" & PINManager.getPINUsed()) + { + Serial.println("Enter your actual PIN code:"); + String oldPIN = readSerial(); + Serial.println("Now, enter your new PIN code:"); + String newPIN = readSerial(); + // change PIN + PINManager.changePIN(oldPIN, newPIN); + } + else + { + Serial.println("Incorrect option. Try again!."); + } + delay(1000); +} + +/* + Read input serial + */ +String readSerial() +{ + String text = ""; + while(1) + { + while (Serial.available() > 0) + { + char inChar = Serial.read(); + if (inChar == '\n') + { + return text; + } + if(inChar!='\r') + text += inChar; + } + } +} diff --git a/libraries/GSM/examples/Tools/TestGPRS/TestGPRS.ino b/libraries/GSM/examples/Tools/TestGPRS/TestGPRS.ino new file mode 100644 index 0000000..ab4a2be --- /dev/null +++ b/libraries/GSM/examples/Tools/TestGPRS/TestGPRS.ino @@ -0,0 +1,204 @@ +/* + + This sketch test the GSM shield's ability to connect to a + GPERS network. It asks for APN information through the + serial monitor and tries to connect to arduino.cc. + + Circuit: + * GSM shield attached + * SIM card with data plan + + Created 18 Jun 2012 + by David del Peral + + This example code is part of the public domain + + http://arduino.cc/en/Tutorial/GSMToolsTestGPRS + + */ + +// libraries +#include <GSM.h> + +// PIN Number +#define PINNUMBER "" + +// initialize the library instance +GSM gsmAccess; // GSM access: include a 'true' parameter for debug enabled +GPRS gprsAccess; // GPRS access +GSMClient client; // Client service for TCP connection + +// messages for serial monitor response +String oktext = "OK"; +String errortext = "ERROR"; + +// URL and path (for example: arduino.cc) +char url[] = "arduino.cc"; +char urlproxy[] = "http://arduino.cc"; +char path[] = "/"; + +// variable for save response obtained +String response = ""; + +// use a proxy +boolean use_proxy = false; + +void setup() +{ + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } +} + +void loop() +{ + use_proxy = false; + + // start GSM shield + // if your SIM has PIN, pass it as a parameter of begin() in quotes + Serial.print("Connecting GSM network..."); + if(gsmAccess.begin(PINNUMBER)!=GSM_READY) + { + Serial.println(errortext); + while(true); + } + Serial.println(oktext); + + // read APN introduced by user + char apn[50]; + Serial.print("Enter your APN: "); + readSerial(apn); + Serial.println(apn); + + // Read APN login introduced by user + char login[50]; + Serial.print("Now, enter your login: "); + readSerial(login); + Serial.println(login); + + // read APN password introduced by user + char password[20]; + Serial.print("Finally, enter your password: "); + readSerial(password); + + // attach GPRS + Serial.println("Attaching to GPRS with your APN..."); + if(gprsAccess.attachGPRS(apn, login, password)!=GPRS_READY) + { + Serial.println(errortext); + } + else{ + + Serial.println(oktext); + + // read proxy introduced by user + char proxy[100]; + Serial.print("If your carrier uses a proxy, enter it, if not press enter: "); + readSerial(proxy); + Serial.println(proxy); + + // if user introduced a proxy, asks him for proxy port + int pport; + if(proxy[0] != '\0'){ + // read proxy port introduced by user + char proxyport[10]; + Serial.print("Enter the proxy port: "); + readSerial(proxyport); + // cast proxy port introduced to integer + pport = (int) proxyport; + use_proxy = true; + Serial.println(proxyport); + } + + // connection with arduino.cc and realize HTTP request + Serial.print("Connecting and sending GET request to arduino.cc..."); + int res_connect; + + // if use a proxy, connect with it + if(use_proxy) + res_connect = client.connect(proxy, pport); + else + res_connect = client.connect(url, 80); + + if (res_connect) + { + // make a HTTP 1.0 GET request (client sends the request) + client.print("GET "); + + // if use a proxy, the path is arduino.cc URL + if(use_proxy) + client.print(urlproxy); + else + client.print(path); + + client.println(" HTTP/1.0"); + client.println(); + Serial.println(oktext); + } + else + { + // if you didn't get a connection to the server + Serial.println(errortext); + } + Serial.print("Receiving response..."); + + boolean test = true; + while(test) + { + // if there are incoming bytes available + // from the server, read and check them + if (client.available()) + { + char c = client.read(); + response += c; + + // cast response obtained from string to char array + char responsechar[response.length()+1]; + response.toCharArray(responsechar, response.length()+1); + + // if response includes a "200 OK" substring + if(strstr(responsechar, "200 OK") != NULL){ + Serial.println(oktext); + Serial.println("TEST COMPLETE!"); + test = false; + } + } + + // if the server's disconnected, stop the client: + if (!client.connected()) + { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + test = false; + } + } + } +} + +/* + Read input serial + */ +int readSerial(char result[]) +{ + int i = 0; + while(1) + { + while (Serial.available() > 0) + { + char inChar = Serial.read(); + if (inChar == '\n') + { + result[i] = '\0'; + return 0; + } + if(inChar!='\r') + { + result[i] = inChar; + i++; + } + } + } +} diff --git a/libraries/GSM/examples/Tools/TestModem/TestModem.ino b/libraries/GSM/examples/Tools/TestModem/TestModem.ino new file mode 100644 index 0000000..de61fff --- /dev/null +++ b/libraries/GSM/examples/Tools/TestModem/TestModem.ino @@ -0,0 +1,77 @@ +/* + + This example tests to see if the modem of the + GSM shield is working correctly. You do not need + a SIM card for this example. + + Circuit: + * GSM shield attached + + Created 12 Jun 2012 + by David del Peral + modified 21 Nov 2012 + by Tom Igoe + + http://arduino.cc/en/Tutorial/GSMToolsTestModem + + This sample code is part of the public domain + + */ + +// libraries +#include <GSM.h> + +// modem verification object +GSMModem modem; + +// IMEI variable +String IMEI = ""; + +void setup() +{ + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + // start modem test (reset and check response) + Serial.print("Starting modem test..."); + if(modem.begin()) + Serial.println("modem.begin() succeeded"); + else + Serial.println("ERROR, no modem answer."); +} + +void loop() +{ + // get modem IMEI + Serial.print("Checking IMEI..."); + IMEI = modem.getIMEI(); + + // check IMEI response + if(IMEI != NULL) + { + // 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) + { + Serial.println("Modem is functoning properly"); + } + else + { + Serial.println("Error: getIMEI() failed after modem.begin()"); + } + } + else + { + Serial.println("Error: Could not get IMEI"); + } + // do nothing: + while(true); +} + diff --git a/libraries/GSM/examples/Tools/TestWebServer/TestWebServer.ino b/libraries/GSM/examples/Tools/TestWebServer/TestWebServer.ino new file mode 100644 index 0000000..5cc3f8a --- /dev/null +++ b/libraries/GSM/examples/Tools/TestWebServer/TestWebServer.ino @@ -0,0 +1,85 @@ +/* + Basic Web Server + + A simple web server that replies with nothing, but prints the client's request + and the server IP address. + + Circuit: + * GSM shield attached + + created + by David Cuartielles + modified 21 Nov 2012 + by Tom Igoe + + http://arduino.cc/en/Tutorial/GSMToolsTestWebServer + + This example code is part of the public domain + */ + #include <GSM.h> + +// PIN Number +#define PINNUMBER "" + +// APN data +#define GPRS_APN "GPRS_APN" // replace your GPRS APN +#define GPRS_LOGIN "login" // replace with your GPRS login +#define GPRS_PASSWORD "password" // replace with your GPRS password + + +// initialize the library instance +GPRS gprs; +GSM gsmAccess; // include a 'true' parameter for debug enabled +GSMServer server(80); // port 80 (http default) + +// timeout +const unsigned long __TIMEOUT__ = 10*1000; + +void setup() +{ + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + Serial.println("starting,.."); + // connection state + boolean connected = true; + + // Start GSM shield + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while(!connected) + { + if((gsmAccess.begin(PINNUMBER)==GSM_READY) & + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)) + connected = true; + else + { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("Connected to GPRS network"); + + // start server + server.begin(); + + //Get IP. + IPAddress LocalIP = gprs.getIPAddress(); + Serial.println("Server IP address="); + Serial.println(LocalIP); +} + +void loop(){ + GSMClient client = server.available(); + + if (client) { + if (client.available()) { + Serial.write(client.read()); + } +} + +} + |