GSM LIBRARY for AVRs
This is a library used to do GSM and GPRS connections using Hayes AT commands, it was developed to be used with a Telit module.
Copyright (c) Justin Downs 12/20/10 All right reserved. for more info/tutorials visit: www.GROUNDLAB.CC **** This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. **** This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY or LIABILITY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA or by visiting the Free Software Foundation LPGL page at http://www.gnu.org/licenses/lgpl.html
Library overview:
This library encapsulates sending and receiving Hayes AT commands with a Telit module ( TELIT AT COMMAND REFERENCE CAN BE FOUND HERE → www.telit.com). The AT Hayes commands are standardized across many platforms so most functions here will work on non Telit modules as well. This allows for easy GSM text messaging and GPRS connections using a AVR microcontroller. The main library is written in C and C++ (C++used mostly for namespaces which the compiler seems to handle fine), the library can be used with the Arduino IDE as well with a few small changes to the “gsmbase” class, that is documented below. The library only needs two dependencies to work on the AVR, a timer function that returns the time since start up in millis and a serial class that implements the below described functions:
void write(T*); //can write a null terminated char* char read(); //reads back a byte from serial register uint8_t available(); //returns number of Bytes in buffer void flush(); //flushes buffer void USART_Init( uint32_t baud ); //inits serial port to 9600
Library Overview:
The library is composed of 4 main classes which handle the formatting and protocol of GSM and GPRS connections with the Telit.
CLASSES: FUNCTIONALITY:
GSMbase -> is the base class the others are derived from it handles:
1.sending data to the Telit.
2.Receiving, storing and parsing data form the Telit.
3.Basic network checking (signal quality, registration ETC...)
gsmSMS -> is used to send, receive and manage SMS text messages.
gsmGPRS -> is used to open close and manage GPRS connections.
gsmMaster -> is used to wrap the gsmSMS and gsmGPRS classes into
one main class so you can use both SMS and GPRS in
one program.
The GSMbase class is never really instantiated by itself since you only use the base functionality in conjunction with GSM or GPRS, so the classes most often instantiated are gsmSMS, gsmGPRS and gsmMaster
CLASSES: GSMbase -> is found in gsmbase.h gsmSMS -> is found in gsmSMS.h gsmGPRS -> is found in gsmGPRS.h gsmMaster -> is found in gsmMaster.h
There are also three additional supporting classes/files that the gsm library needs to function they are:
The serial class for communications between the Telit and the AVR:
SerialPort -> as found in serial.h
The timer0 class is used for timing and delays:
timer0 -> as found in timer.h ***WARNING!!!! //timer0 sets prescaler to -> clkIO/256 ****THIS MIGHT CAUSE ISSUES,IT APPLIES TO ALL CLOCKS**!!!! TCCR0B = (1<<CS02); // code line
The ioHelper file just has some macro #define'S to do port IO easier (only used in the turOn() and turnOff() functions of class gsmbase):
ioHelper -> defined in ioHelper.h
Implement your own serial and timer class:
If you want to implement your own serial class and millis function you would do it by changing the gsmbase.h header file, as shown below:
1.Change the serial typedef in the top of the gsmbase.h file to the name of your serial class, EG: //typedef SerialPort Serial; // change here to support your serial friend// typedef mySerial Serial; // change here to support your serial friend
2.When instantiating the serialbase class pass in your serial object and a pointer to your millis function,EG:
Serial myserial; uint32_t myMillis(){ return millisFromSomewhere; } //GSMbase(Serial& ,uint32_t(*FP)(), Serial* = NULL); // Call Once for best results GSMbase myBase(myserial ,myMillis, &myserial);
/*AVR SOURCE FILES FOR GSM,SERIAL FUNCTIONALITY * * Copyright (C) 2010 Justin Downs of GRounND LAB * * www.GroundLab.cc 1% * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * with this program. If not, see <http://www.gnu.org/licenses/>. * ************************************************************************/ #ifndef GSM #define GSM #include <inttypes.h> #include <stdlib.h> #include <string.h> #include "serial.h" #include "ioHelper.h" class GSMbase{ protected: typedef SerialPort Serial; // change here to support your serial friend // Serial needs a read, write, flush, available functions Serial& telitPort; // serial object Serial* DebugPort; // pointer so it can default to null uint32_t (*millis)(); // millis func pointer **NEED A FUNCTION that returns MILLIS** char* fullData; // full telit responce data, filled by catchTelitData char* parsedData; // parsed response public: inline const char* const getFullData(){return fullData;} inline const char* const getParsedData(){return parsedData;} GSMbase(Serial& ,uint32_t(*FP)(), Serial* = NULL); // Call Once for best results //Handle Telit Data ////ETC....................
CODE EXAMPLES
CLASS GSMbase
The base class is only really used in conjunction with the SMS or GPRS classes but you can instantiate it separately. The base class negotiates the sending and receiving of Telit data and basic network functionality.
#include <avr/io.h> #include <avr/interrupt.h> #include "serial.h" #include "ioHelper.h" #include "timer.h" #include "gsmbase.h" void GSMbaseTester(); // tests GSMbase member functions //*****************************************8 uint32_t millisWrapper(); uint32_t (*milP)() = &millisWrapper; //used, so you can pass &myMillis() straight in. uint32_t millisWrapper(){return Timer0.millis();} //*****************************************8 GSMbase GSMb(Serial3,milP,&Serial2); //GSMbase TELIT BASE FUNCTIONALITY int main(void){ sei(); //Enable interrupts //only these are declared, to turn on other serial ports do so in serial.h Serial3.USART_Init(9600); //Telit serial Serial2.USART_Init(9600); //debug serial GSMb.init(3); // init Telit ***ALWAYS INIT AFTER SERIAL SETUP*** while(1){ GSMbaseTester(); } } void GSMbaseTester(){ //CHECK CREG (NETWORK REGISTRATION) if (GSMb.checkCREG()) Serial2.write("REGISTERED"); else Serial2.write("NOTREGISTERED"); //CHECK COPS (NETWORK INFO) Serial2.write( GSMb.checkCOPS() ); //CHECK GSN (SERIAL NUMBER) Serial2.write( GSMb.checkGSN() ); //CHECK CSQ (signal strength) char tempTest[10]; Serial2.write(itoa( GSMb.checkCSQ(), tempTest, 10 )); //CHECK MONI (ALL SURRONDING TOWER INFORMATION) Serial2.write( GSMb.checkMONI() ); }
CLASS gsmSMS
The gsmSMS class negotiates the interactions between the AVR and Tellit when sending, receiving and managing text messages. You would use this if you want to just send receive text messages.
#include <avr/io.h> #include <avr/interrupt.h> #include "serial.h" #include "ioHelper.h" #include "timer.h" #include "gsmbase.h" #include "gsmSMS.h" //*****************************************8 //SMS derived class tester void gsmSMSTester(); // test gsmSMS member functions //*****************************************8 uint32_t millisWrapper(); uint32_t (*milP)() = &millisWrapper; //used, so with arduino you can pass &millis() straight in. uint32_t millisWrapper(){return Timer0.millis();} //*****************************************8 GSMbase GSMb(Serial3,milP,&Serial2); //GSMbase TELIT BASE FUNCTIONALITY gsmSMS GsmSMS(Serial3,milP,&Serial2); //gsmSMS TELIT SMS int main(void){ sei(); //Enable interupts //only these are declared, to turn on other serial ports do so in serial.h Serial3.USART_Init(9600); //Telit serial Serial2.USART_Init(9600); //debug serial ***ALWAYS INIT AFTER SERIAL SETUP*** //GsmSMS.init(3); // init Telit derived class calls base init() if (GsmSMS.init(3)) Serial2.write("good init"); else Serial2.write("bad init"); while(1){ gsmSMSTester(); } } void gsmSMSTester(){ //CHECK CMGD gives a numerical list of all messages which are stored seperated by ',' //Serial2.write( GsmSMS.checkCMGDList() ); //*ERASE CMGD (with arg) erases message at id(EG 1,2,3,4) arg //GsmSMS.deletMessagesCMGD("9"); //*READ CMGR read message with specified ID //GsmSMS.readMessageCMGR("4"); //SEND CMGS sends up a SMS with no save; GsmSMS.sendNoSaveCMGS("18007663537","hello Poodles!"); //1-800-POODLES uint32_t startTime=millisWrapper(); while((millisWrapper()-startTime) < 20000); // hang out //SAVE CMGW saves a message to memory and CMSS sends saved message. //GsmSMS.sendSavedMessageCMSS(GsmSMS.saveMessageCMGW("3473017780","I remember!")); //uint32_t startTime=millisWrapper(); //while((millisWrapper()-startTime) < 20000); // hang out //CHECK CPMS gets number of messages or total space availible in sim memory selected by arg. //Serial2.write( GsmSMS.getNumMesInMemCPMS(1) ); //CHECK CMGL gets and displays full info and content of all of specified type of message. //Serial2.write( GsmSMS.readAllCMGL("REC READ") ); }
CLASS gsmGPRS
The gsmGPRS class allows for GPRS connections with the Telit module, so you can do GET and POST requests to a server.
#include <avr/io.h> #include <avr/interrupt.h> #include "serial.h" #include "ioHelper.h" #include "timer.h" #include "gsmbase.h" #include "gsmGPRS.h" //*****************************************8 //GPRS derived class tester void gsmGPRSTester(); //*****************************************8 uint32_t millisWrapper(); uint32_t (*milP)() = &millisWrapper; //used, so with arduino you can pass &millis() straight in. uint32_t millisWrapper(){return Timer0.millis();} //*****************************************8 gsmGPRS GsmGPRS(Serial3,milP,&Serial2); //gsmGPRS TELIT GPRS int main(void){ sei(); //Enable interupts //only these are declared, to turn on other serial ports do so in serial.h Serial3.USART_Init(9600); //Telit serial Serial2.USART_Init(9600); //debug serial ***ALWAYS INIT AFTER SERIAL SETUP*** //GsmGPRS.init(3); // init Telit derived class calls base init() if (GsmGPRS.init(3)) Serial2.write("good init"); else Serial2.write("bad init"); while(1){ gsmGPRSTester(); } } ///////////////////////////////////////////////////////////////////////////GPRS CLASS TESTERS void gsmGPRSTester(){ ////////////////////////////////SET NETWORK CONNECTION //SETS the context number associated with a PDP protocal "IP"/"PPP" and APN number. // context "2" now has these settings (NOTE don't use "0" it is reserved for SMS) Serial2.write("CGDCONT"); GsmGPRS.setApnCGDCONT("2","IP","wap.cingular"); //SETS the TCP/IP stack // sockst conection ID 1 is now linked to context ID 2 data, with default timeouts TCP/IP Serial2.write("SCFG"); GsmGPRS.setTcpIpStackSCFG("1","2"); //REGISTERS with the network, receives IP address and network resources. // connect the specified context ID to the network. // 1 gets network resources 0 disconnects from network and frees resources. Serial2.write("SGACT"); if(GsmGPRS.setContextSGACT("2","1","[email protected]","CINGULAR1")){ //AT#SD socket dial opens a socket to remote server. //conection ID 1 being opened Serial2.write("SD"); if( GsmGPRS.socketDialSD("1","0","80","www.google.com")){ //RETURNS: CONNECT //////////////////////HERE DO A GET OR POST///////////////////////////////// //Constructs and send a get request on open socket // Serial2.write("HTTP"); // GsmGPRS.getHTTP(3000,"www.google","/","HTTP/1.1",true); // Serial2.write("\n\n\n\nOUT of HTTP"); //Constructs and sends a POST GsmGPRS.postHTTP(600,"www.google.com","/cTest/myPing.php", "MyName", "HTTP/1.1",true,"testPing=helloworld"); //////////////////////////////////////////////////////////////////////////// //Suspends listing to socket, socket can still receive data till //a SH command is issued to shut the socket GsmGPRS.suspendSocket(); } ///////*****OR DO A FTP*****//////// //////////////////////HERE DO A FTP PUT//////////////////////////////////////////////// //SEE BELOW FOR FTP STEPS //ftp(); /////////////////////////////////////////////////////////////////////////////////////// } //AT#SO you can use resumeSocket to reopen connection // resumeSocketSO(const char* const whichSocket); //AT#SS can be implemented to view the status of a socket Serial2.write("SS"); Serial2.write( GsmGPRS.socketStatusSS() ); //then you can check socket status //AT#SI can be implemented to view the status of a socket // Serial2.write(GsmGPRS.socketInfoSI("1") ); //see the bytes transfered //AT#SH closes the socket connection, no data in or out GsmGPRS.closeSocketSH("1"); Serial2.write("SGACT2"); //Give back the IP to the network GsmGPRS.setContextSGACT("2","0","[email protected]","CINGULAR1"); uint32_t startTime=millisWrapper(); while((millisWrapper()-startTime) < 20000); // hang out } //DIDN"T HAVE TIME TO TEST except basic functionality //somthing with my FTP server is messed up. void ftp(){ GsmGPRS.ftpTimeOutFTPO("1000"); //set timeout to twenty seconds if (GsmGPRS.FTPOPEN("http://www.someFTP.com", "[email protected]","","1")){ // set passive with 1 GsmGPRS.ftpDataTypeFTPTYPE("1"); //get ASCII file if( GsmGPRS.changeDirFTPCWD("/public_html/ftpTest" )){ //GsmGPRS.FTPPUT("putMe.txt", "you put me!"); //filename of data you are putting Serial2.write( GsmGPRS.FTPGET("getMe.txt",300) ); //file name and dataSize you are getting }else Serial2.write("bad CD\n"); GsmGPRS.FTPCLOSE(); }Serial2.write("bad connection\n"); }
CODE DOWNLOAD
You can download the latest version of the Library from www.github.com/GROUNDLAB/.
API
Below is a overview of the API used to manipulate the Telit using a AVR controller.
API README NOTES
The GSM Library wraps and parses the data of many Hayes AT commands. To find the correct use and what the returned data means for a below function, you can look up the base command in the AT Commands Reference Guide - Telit www.telit.com. The AT Hayes comands are standardized across many platforms so most functions here will work on non Telit modules as well.
CLASS GSMbase
This is the base class and negotiates the sending and receiving of Telit data and basic network functionality.
Class GSMbase member Functions:
////////////////////////////////////////////////////////parse Funcs //Returns most recent returned data from Telit (use after catchTelitData) inline const char* const getFullData() //Returns most recent parsed data inline const char* const getParsedData() //Constructor GSMbase(Serial& ,uint32_t(*FP)(), Serial* = NULL); //Main function which retrives data from serial buffer and puts it into //fullData, which has class scope. virtual const char* const catchTelitData (uint32_t = 180000, bool = false, uint16_t= 300, uint32_t = 60); //Parses incoming Data for subString virtual const char* const parseData (const char* const,const char* ,const char*); //Splits string according to delimiter virtual const char* const parseSplit (const char* const,const char*,uint16_t); //Returns true if it finds a string virtual bool parseFind(const char* const, const char*); ////////////////////////////////////////////////////////parse Funcs ////////////////////////////////////////////////////////Send Funcs //Sends AT command in the clear virtual void sendATCommand(const char*); //Used to send AT command and check reply for a OK reply virtual const char* const sendRecQuickATCommand (const char*); //Sends AT command gets Telit reply virtual const char* const sendRecATCommand (const char*); //Sends AT command parses reply, between _start _end virtual const char* const sendRecATCommandParse (const char*,const char* _start, const char* _end); //Sends AT command splits data according to delimiter virtual const char* const sendRecATCommandSplit (const char*,const char* _delimiters, uint16_t _field); ////////////////////////////////////////////////////////Send Funcs ////////////////////////////////////////////////////////Hardware //Used to turn on Telit (**read below for use with arduino**) virtual bool turnOn(); //Turn off Telit virtual bool turnOff(); //Used to init Telit to right settings. virtual bool init(uint16_t); //Returns Temperature of mod in C const char* const getTemperatureTEMPMON(); ////////////////////////////////////////////////////////Hardware ////////////////////////////////////////////////////////Network calls //Gets registration status bool checkCREG(); //Gets network availability and current network registration const char* const checkCOPS(); //Gets serial number of Telit const char* const checkGSN(); //Gets signal quality uint32_t checkCSQ(); //Gets info for surrounding available cell towers const char* const checkMONI(); //Gets tel number of current mod, if stored on SIM const char* const getMyNumCNUM(); ////////////////////////////////////////////////////////Network calls
Functions overview:
getFullData
inline const char* const getFullData()
getFullData returns a const char * to the most recent received data from the Telit.
Returns: a const char if there is good data, NULL pointer if not.
getParsedData
inline const char* const getParsedData();
getParseData gets the most recent parsed data.
Returns: a const char if there is good data, NULL pointer if not.
checkCREG
inline bool GSMbase::checkCREG()
Gets registration status (true REGISTERED, false NOT)
//EXAMPLE: +CREG: 0,1 OK
Returns: a const char if there is good data, NULL pointer if not.
checkCOPS
inline const char* const GSMbase::checkCOPS()
Gets network availability and current registration.
//EXAMPLE: +COPS: (2,"Cingular",,"310410"),(1,"T-Mobile",,"310260"),,(0-4),(0,2) OK
Returns: a const char if there is good data, NULL pointer if not.
checkGSN
inline const char* const GSMbase::checkGSN()
Gets Telit serial number
//EXAMPLE: 0000646714 OK
Returns: a const char if there is good data, NULL pointer if not.
checkCSQ
inline uint32_t GSMbase::checkCSQ()
Gets signal quality.
//EXAMPLE: +CSQ: 7,0 OK
Returns: a const char if there is good data, NULL pointer if not.
checkMONI
inline const char* const GSMbase::checkMONI()
MONI *TELIT ONLY* gets info for all surronding availble cell towers,AT#MONI=0 then AT#MONI gets info for the one you're connected to. Use AT#MONI?? for list of all towers. AT#MONI=7 then AT#MONI to get all towers info.
Returns: a const char if there is good data, NULL pointer if not.
getMyNumCNUM
inline const char* const GSMbase::getMyNumCNUM()
AT+CNUM returns the phone # number of the device, if stored on SIM
//EXAMPLE: +CNUM: "name","3449709999",129
Returns: a const char if there is good data, NULL pointer if not.
sendATCommand
void GSMbase::sendATCommand(const char* theMessageMelleMel)
SendATCommand sends a AT command to the Telit module(does not wait for reply)
Returns: void
sendRecQuickATCommand
const char* const GSMbase::sendRecQuickATCommand(const char* theMessageMelleMel)
sendRecQuickATCommand sends a AT command and checks Telit reply for a OK, returns true if found.
Returns: a const char* if OK is found, Null pointer if ERROR is received.
sendRecATCommand
const char* const GSMbase::sendRecATCommand(const char* theMessageMelleMel)
sendRecATCommand Sends an AT command and stores the reply, can be accessed with getFullData().
Returns: a const char* which is the complete reply from the Telit to the command.
sendRecATCommandParse
const char* const GSMbase::sendRecATCommandParse(const char* theMessageMelleMel, const char* _start,const char* _end)
sendRecATCommandParse Sends AT command parses reply, makes string from the passed in strings
EG. input string: "the quick brown blah blah" _start string: "the" _end string: "blah" returns a pointer to "quick brown"
Returns: NUll pointer if string not found, otherwise Const char* .
sendRecATCommandSplit
const char* const GSMbase::sendRecATCommandSplit(const char* theMessageMelleMel, const char* _delimiters, uint16_t _field)
Sends AT command splits data according to delimiter.
EG input string: "the, quick: brown, blah: blah," _delimiters string ",:" field: 2 returns pointer to "brown"
Returns: NULL pointer if not found, const char* of substring if found.
parseFind
bool GSMbase::parseFind(const char* const theString ,const char* objectOfDesire)
finds the objectOfDesire string in theString, if it is ! a NULL pointer
Returns: returns true if string is found, false if not found.
catchTelitData
const char* const GSMbase::catchTelitData(uint32_t _timeout, bool quickCheck,uint16_t dataSize,uint32_t baudDelay)
Main function which retrieves data from serial buffer and puts it into fullData member, which has class scope. quickCheck=true will look for a “OK” in reply and return NULL pointer if not found, the received data otherwise. dataSize is the max size of the data received from Telit. baudDelay sets the length of time between received bytes on the serial port to signal the end of a transfer.
Returns: const char* if good receive, NULL pointer if error occurs.
parseData
const char* const GSMbase::parseData(const char* const theString,const char* start, const char* end)
Sends AT command parses reply, makes string from the passed in strings
EG. input string: "the quick brown blah blah" _start string: "the" _end string: "blah" returns a pointer to "quick brown"
Returns: const char* to substring if found, NULL pointer if not.
parseSplit
const char* const GSMbase::parseSplit(const char* const theString, const char* delimiters,uint16_t field)
Splits data according to delimeter
EG (THE FIELDS 0 1 2 3 4 ) input string: "the, quick: brown, blah: blah," _delimiters string ",:" field: 2 returns pointer to "brown"
Returns: const char* to sub string if found, NULL pointer if not.
turnOn
bool GSMbase::turnOn()
This is the only function to be re written for arduino Turns the Telit on with external hardware. #define OnOffPin PA0
Returns: true if turn on success, false if not.
turnOff
bool GSMbase::turnOff()
Turns off Telit with software, not hardware dependent.
Returns: True if turn off is accomplished, false if not.
init
bool GSMbase::init(uint16_t _band)
inits Telit to the proper settings, the argument sets the GSM band.
0 - GSM 900MHz + DCS 1800MHz 1 - GSM 900MHz + PCS 1900MHz 2 - GMS 850MHz + DCS 1800MHz 3 - GMS 850MHz + PCS 1900MHz
Returns: True if good init , false if not.
CLASS gsmSMS
The gsmSMS class negotiates the interactions between the AVR and Tellit in sending receiving and managing text messages. You would use this if you want to just send receive text messages.
Class gsmSMS member Functions:
gsmSMS
gsmSMS::gsmSMS(Serial& _telit, uint32_t (*_millis)(), Serial* _debug) : GSMbase(_telit ,_millis, _debug)
constructor takes a serial object, function pointer to a millis function, a address of a serial object. It instantiates the base class GSMbase. Returns: nothing
init
bool gsmSMS::init(uint16_t _band)
inits Telit to the proper settings, the argument sets the GSM band.
0 - GSM 900MHz + DCS 1800MHz 1 - GSM 900MHz + PCS 1900MHz 2 - GMS 850MHz + DCS 1800MHz 3 - GMS 850MHz + PCS 1900MHz
Returns: True if good init , false if not.
sendNoSaveCMGS
//AT+CMGS //sends SMS without storing bool gsmSMS::sendNoSaveCMGS(const char* theNumber,const char* sendString){
sends out a text message without saving to sim card, “theNumber” is the number you want to send to in a alphanumeric string. sendString is the message you want to send as a NULL terminated array of chars.
EG. char theNumber[] = "18007663537"; //1-800-POODLES char sendString[]= "Hello poodles";
Returns: true if it sent successfully, false otherwise.
saveMessageCMGW
const char* const gsmSMS::saveMessageCMGW( const char* theNumber,const char* sendString){
Sends message to storage.
EG. char theNumber[] = "18007663537"; //1-800-POODLES char sendString[]= "Hello poodles";
Returns: +CMGW: 1 (which is address of stored message) or a NULL string with a failure.
sendSavedMessageCMSS
bool gsmSMS::sendSavedMessageCMSS(const char * const theMesNum){
Sends stored message, theMesNum is the index of the stored message. Returns: True if a good send occurs, false if not.
getNumMesInMemCPMS
const char* const gsmSMS::getNumMesInMemCPMS(uint16_t whichMemSpace)
Gets number of messages in specified mem.
whichMemspace = 1 (gives number of SMs stored into <memr>) whichMemspace = 3 (gives number of SMs stored into <memw>) whichMemspace = 5 (gives number of SMs stored into <mems>) whichMemspace = 2 (gives number of SMs allowed in <mems>) whichMemspace = 4 (gives number of SMs allowed in <mems>) whichMemspace = 6 (gives number of SMs allowed in <mems>)
Returns: a list of the messages in the memory spaces and available space, NULL if failed.
readMessageCMGR
const char* const gsmSMS::readMessageCMGR(const char* const whichMessage ){
reads the message at the index passed by whichMessage.
Returns: a const char* of the message, NULL if it fails.
const char* const gsmSMS::readAllCMGL(const char* const messageType, uint16_t dataSize)
Returns all messages with specific listing, gives full message
"REC UNREAD" - new message "REC READ" - read message "STO UNSENT" - stored message not yet sent "STO SENT" - stored message already sent "ALL" - all messages.
Returns: a const char* of all messages, NULL if it fails.
deletMessagesCMGD
bool gsmSMS::deletMessagesCMGD(const char* const whichMessages){
searches and deletes a specific message or all messages of a type
If passed 1 arg EG: "AT+CMGD=1" it erases that message. If passed 2 args EG: "AT+CMGD=1,1" the second arg chooses all messages of that kind to erase. ********************** 1 - delete all read messages from <memr> storage, leaving unread messages and stored mobile originated messages (whether sent or not) untouched 2 - delete all read messages from <memr> storage and sent mobile originated messages, leaving unread messages and unsent mobile originated messages untouched 3 - delete all read messages from <memr> storage, sent and unsent mobile originated messages, leaving unread messages untouched 4 - delete all messages from <memr> storage.
Returns: True if deleted, false otherwise.
CLASS gsmGPRS
Class gsmGPRS member Functions:
gsmGPRS
gsmGPRS::gsmGPRS(Serial& telit, uint32_t(*millis)(), Serial* debug): GSMbase(telit, millis, debug), getData(NULL)
constructor takes a serial object, function pointer to a millis function, a address of a serial object. It instantiates the base class GSMbase.
Returns: nothing
getIpAddress
inline const char* const getIpAddress()
Returns: The IP address after network registration, a NULL pointer if no address was received.
init
virtual bool gsmGPRS::init(uint16_t);
inits Telit to the proper settings, the argument sets the GSM band.
0 - GSM 900MHz + DCS 1800MHz 1 - GSM 900MHz + PCS 1900MHz 2 - GMS 850MHz + DCS 1800MHz 3 - GMS 850MHz + PCS 1900MHz
Returns: True if good init , false if not.
checkCGREG
inline bool gsmGPRS::checkCGREG()
Checks if the Telit is registered to a GPRS capable network.
Returns: (true REGISTERED, false NOT).
setApnCGDCONT
bool gsmGPRS::setApnCGDCONT(const char * const userSetContextID ,const char* const PDPtype, const char* const APN ,const char* const requestedStaticIP, const char* const dataCompression, const char* const headerCompression)
AT+CGDCONT sets up ISP information for the context
example string would be 2,"IP","wap.cingular","0.0.0.0",0,0
You would say:
setApnCGDCONT("2","IP","wap.cingular","0.0.0.0",0,0);
if static ip=0.0.0.0 dynamic assignment from gateway.
context can only be numbered 1-5, 0 is always for SMS context.
Returns: True if success, false if not.
setTcpIpStackSCFG
bool gsmGPRS::setTcpIpStackSCFG(const char * const userSetConnectionID , const char* const userSetContextID,const char* const minPacketSize , const char* const globalTimeout, const char* const connectionTimeout, const char* const txTimeout)
AT+SCFG is used to set the socket connection settings Returns: TRUE if success, false otherwise.
setContextSGACT
const char* const gsmGPRS::setContextSGACT(const char * const userSetConnectionID , const char* const statusOfConnection,const char* const username, const char* const password)
AT+SGACT activates/closes (statusOfConnection=1/0) context, gets IP from gateway Returns: IP address assigned to Telit by network or if it fails a NULL pointer.
setQualityCGQMIN
bool gsmGPRS::setQualityCGQMIN(const char * const userSetConnectionID , const char* const precedence,const char* const delay, const char* const reliability, const char* const peak, const char* const mean)
AT+CGQMIN defines a min quality of service for the telit to send. Telit recommends to always set the network default “00000”.
Returns: True if set ok, false otherwise.
requestQualityCGQREQ
bool gsmGPRS::requestQualityCGQREQ(const char * const userSetConnectionID , const char* const precedence,const char* const delay, const char* const reliability, const char* const peak, const char* const mean)
AT+CGQREQ asks for a specific quality of service from network
Returns: True if succsessful, false if not.
setSecuritySGACTAUTH
bool gsmGPRS::setSecuritySGACTAUTH(const char* const securitySetting)
AT+SGACTAUTH sets security protocal used with network
0 - no authentication 1 - PAP authentication (factory default) 2 - CHAP authentication
Returns: True if succsessful, false otherwise.
socketDialSD
bool gsmGPRS::socketDialSD(const char * const userSetConnectionID , const char* const protocol,const char* const remotePort, const char* const ipAddress)
AT#SD socket dial opens a socket to remote server.
Returns: True if succsessful, false otherwise.
suspendSocket
bool gsmGPRS::suspendSocket()
suspends listing to socket,socket can still receive data till a SH command is issued to shut the socket
Returns: True if succsessful, false otherwise.
resumeSocketSO
bool gsmGPRS::resumeSocketSO(const char* const whichSocket)
AT#SO reopens a suspended connection (eg suspended with +++ or timed out).
Returns: True if succsessful, false otherwise.
closeSocketSH
bool gsmGPRS::closeSocketSH(const char* const whichSocket)
AT#SH closes the socket connection, no data in or out.
Returns: True if succsessful, false otherwise.
const char* const gsmGPRS::socketStatusSS(){
AT#SS can be implemented to view the status of a socket
0 - Socket Closed. 1 - Socket with an active data transfer connection. 2 - Socket suspended. 3 - Socket suspended with pending data. 4 - Socket listening. 5 - Socket with an incoming connection. Waiting for the user accept or shutdown command.
Returns: Status or NULL pointer if it fails.
const char* const gsmGPRS::socketInfoSI(const char* const connectionID)
AT#SI Execution command is used to get information about socket data traffic.
Returns: the data if true, false otherwise.
socketListenSL
bool gsmGPRS::socketListenSL(const char* const connectionID, const char* const listenState, const char* const listenPort)
At#SL starts listening on a socket, you can set to automatically accept data with the <ListenAutoRsp> parameter set using AT#SCFGEXT command. Otherwise you must wait for SRING indication and use the AT#SA command to accept, AT#SH to reject.
Returns: True if succsessful, false otherwise.
socketAcceptSA
bool gsmGPRS::socketAcceptSA(const char* const connectionID)
At#SA accept the connection.
Returns: True if succsessful, false otherwise.
getHTTP
const char* const gsmGPRS::getHTTP(uint16_t dataSize, const char* const host, const char* const resource, const char* const httpVersion, bool keepAlive)
Constructs and send a GET request on opened socket.
Returns: recieved data from the get or a NULL pointer if not succsessful.
postHTTP
const char* const gsmGPRS::postHTTP(uint16_t dataSize,const char* const host, const char* const resource,const char* const secretAgent, const char* const httpVersion, bool keepAlive, const char* const reqStr)
Constructs and send a POST request on opened socket
Returns:
FTP CODE NOT FULLY TESTED
ftpTimeOutFTPO
bool gsmGPRS::ftpTimeOutFTPO(const char* const timeOut)
AT#FTPO sets FTP timeouts
Returns: True if succsessful, false otherwise.
FTPOPEN
bool gsmGPRS::FTPOPEN(const char* const serverPort, const char* const username, const char* password,const char* const mode)
AT#FTPOPEN opens a ftp connection you can leave port off and it defaults to 21, mode defaults to active Telit
Returns: True if succsessful, false otherwise.
ftpDataTypeFTPTYPE
bool gsmGPRS::ftpDataTypeFTPTYPE(const char* const binaryAscii)
AT#FTPTYPE sets ftp transfer type
1 ASCII 0 BINARY
Returns: True if succsessful, false otherwise.
FTPCLOSE
//AT#FTPCLOSE closes FTP connection bool gsmGPRS::FTPCLOSE()
AT#FTPCLOSE closes FTP connection
Returns: True if succsessful, false otherwise.
FTPPUT
bool gsmGPRS::FTPPUT(const char* const fileWriteName, const char* const data){
AT#FTPPUT uploads file into selected file name
Returns: True if succsessful, false otherwise.
FTPGET
const char* const gsmGPRS::FTPGET(const char* const fileName,uint16_t dataSize)
AT#FTPGET gets a specific file.
Returns: True if succsessful, false otherwise.
changeDirFTPCWD
bool gsmGPRS::changeDirFTPCWD(const char* const directory )
AT#FTPCWD changes directory
Returns: True if succsessful, false otherwise.
CLASS gsmMaster
The gsmMaster class wraps the gsmSMS and gsmGPRS classes, You would use this if you want to send receive text messages and do GPRS data connections.
Class gsmMaster member Functions:
gsmMASTER
gsmMASTER::gsmMASTER(Serial& _telit, uint32_t (*_millis)(), Serial* _debug) :GSMbase(_telit, _millis, _debug), gsmSMS(_telit ,_millis, _debug), gsmGPRS(_telit, _millis, _debug)
constructs a object with gsmSMS and gsmGPRS functionality, you can call nay public member function on the resulting object.
Returns: NOTHING
init
bool gsmMASTER::init(uint16_t band)
inits Telit to the proper settings, the argument sets the GSM band.
0 - GSM 900MHz + DCS 1800MHz 1 - GSM 900MHz + PCS 1900MHz 2 - GMS 850MHz + DCS 1800MHz 3 - GMS 850MHz + PCS 1900MHz
Returns: True if good init , false if not.