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

121 lines
2.7 KiB
Arduino
Raw Normal View History

2013-03-11 12:17:08 +01:00
/*
Band Management
2013-03-11 12:17:08 +01:00
This sketch, for the Arduino GSM shield, checks the band
currently configured in the modem and allows you to change
2013-03-11 12:17:08 +01:00
it.
2013-03-11 12:17:08 +01:00
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)
2013-03-11 12:17:08 +01:00
Circuit:
* GSM shield
2013-03-11 12:17:08 +01:00
created 12 June 2012
by Javier Zorzano, Scott Fitzgerald
2013-03-11 12:17:08 +01:00
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
}
2013-03-11 12:17:08 +01:00
// Beginning the band manager restarts the modem
Serial.println("Restarting modem...");
band.begin();
Serial.println("Modem restarted.");
2013-03-11 12:17:08 +01:00
};
void loop()
{
// Get current band
2013-03-11 12:17:08 +01:00
String bandName = band.getBand(); // Get and print band name
Serial.print("Current band:");
Serial.println(bandName);
Serial.println("Want to change the band youre 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)
{
2013-03-11 12:17:08 +01:00
Serial.println("Success");
}
2013-03-11 12:17:08 +01:00
else
{
2013-03-11 12:17:08 +01:00
Serial.println("Error while changing band");
}
if (operationSuccess)
{
while (true);
}
2013-03-11 12:17:08 +01:00
}
// 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;
2013-03-11 12:17:08 +01:00
else
newBand = "GSM_MODE_UNDEFINED";
2013-03-11 12:17:08 +01:00
return newBand;
}
2013-03-11 12:17:08 +01:00