#include <WaspGPRS.h>
Public Member Functions | |
| WaspGPRS () | |
| class constructor | |
| void | ON () |
| It opens UART1 and powers the GPRS module. | |
| void | OFF () |
| It closes UART1 and powers off the GPRS module. | |
| void | begin () |
| It opens UART and sets multiplexer properly. | |
| void | close () |
| It closes UART and sets multiplexer properly. | |
| uint8_t | setMode (uint8_t pwrMode) |
| It sets Power Mode. | |
| uint8_t | getMode () |
| It gets Power Mode. | |
| uint8_t | check () |
| It checks if GPRS is connected to the network. | |
| uint8_t | setPIN (const char *pin) |
| It sets PIN. | |
| uint8_t | setInfoIncomingCall () |
| It sets the info shown when an incoming call is received. | |
| uint8_t | setInfoIncomingSMS () |
| It sets the info shown when an incoming SMS is received. | |
| uint8_t | setTextModeSMS () |
| It sets 'text mode' for sending SMS. | |
| uint8_t | makeCall (const char *tlfNumber) |
| It makes a call to the specified number. | |
| uint8_t | makeLostCall (const char *tlfNumber, uint8_t timeCall) |
| It makes a lost call to the specified number. | |
| uint8_t | hangUp () |
| It hangs all the active calls up. | |
| uint8_t | sendSMS (const char *smsText, const char *tlfNumber) |
| It sends a SMS to the specified number. | |
| uint8_t | readCall (char *data) |
| It stores in 'tlfIN' variable the telephone number of the incoming call. | |
| uint8_t | readSMS (char *data) |
| It stores in 'tlfIN' and 'sms' variables the telephone number and the text of the incoming SMS. It stores in 'sms_index' variable the last sms received index. | |
| uint8_t | manageIncomingGSMData () |
| It manages incoming data from serial port, executing proper functions to store received data. | |
| uint8_t | configureGPRS () |
| It configures GPRS connection with login, password and some other parameters. | |
| uint8_t | createSocket (const char *ip, const char *port, uint8_t mode) |
| It creates a TCP/IP connection to the specified IP and PORT. | |
| uint8_t | readURL (const char *url) |
| It accesses to the specified URL and stores the info read in 'data_URL' variable. | |
| uint8_t | sendData (const char *data, uint8_t socket) |
| It sends 'data' to the specified 'socket'. | |
| int8_t | readData (uint8_t socket, const char *data_length) |
| It reads data of 'data_length' size from socket ID 'socket'. | |
| uint8_t | closeSocket (uint8_t socket) |
| It closes 'socket' TCP/IP connection. | |
| uint8_t | sendCommand (char *ATcommand) |
| It sends any command to the GPRS module. | |
| uint8_t | sendMail (char *from, char *to, char *subject, char *body, char *user, char *passw, char *smtp_server, uint16_t port) |
| It sends an email to the specified address. | |
| uint8_t | readMail (char *user, char *passw, char *pop3_server, uint16_t port) |
| It reads an email from the pop3 server. | |
| uint8_t | uploadFile (char *file, char *path, char *user, char *passw, char *ftp_server, uint8_t ftp_port) |
| It uploads a file to a FTP server. | |
| uint8_t | downloadFile (char *file, char *path, char *user, char *passw, char *ftp_server, uint8_t ftp_port) |
| It downloads a file from a FTP server. | |
| uint8_t | getCellInfo () |
| It gets info from the cell where the modules is connected. | |
Data Fields | |
| int | flag |
| Variable : status flag, used to see if there was an error while communicating with the module. | |
| char | tlfIN [15] |
| Variable : last call or SMS received telephone number. | |
| uint16_t | _baudRate |
| Variable : baud rate used to communicate with the GPRS module. | |
| uint8_t | _pwrMode |
| Variable : power mode. | |
| uint8_t | _uart |
| Variable : UART used by the GPRS module. | |
| char | sms [100] |
| Variable : last SMS text received. | |
| uint8_t | socket_ID |
| Variable : socket ID. | |
| char | data_URL [100] |
| Variable : data received when reading an URL. | |
| uint16_t | data_read |
| Variable : amount of data read from an URL or from a socket. | |
| char | cellID [4] |
| Variable : Cell ID number. | |
| char | RSSI [2] |
| Variable : RSSI value. | |
| char | answer_command [50] |
| Variable : Array for storing the answer to the command sent. | |
| char | sms_index [4] |
| Variable : Last sms received index. | |
| char | emailAddress [31] |
| Variable : Email address from the last email received. | |
| char | subject [31] |
| Variable : Last email received subject. | |
| char | body [101] |
| Variable : Last email received subject. | |
Private Member Functions | |
| uint8_t | setPattern (const char *pattern) |
| It sets the pattern for using in sending and receiving messages. | |
| uint8_t | setConnectionTimer () |
| It sets the GPRS connection time out. | |
| uint8_t | setConnectionProfile () |
| It sets the GPRS connection profile. | |
| uint8_t | setFlowControl () |
| It sets GPRS flow control. | |
| uint8_t | checkGPRS () |
| It checks if GPRS connection is OK. | |
| uint8_t | writeData (const char *data) |
| It writes data to send via GPRS socket. | |
| uint8_t | parse_GSM (char *data) |
| It parses GSM string and specifies if it is a call or a SMS. | |
| uint8_t | setEmailParams (char *smtp_server, uint16_t port, char *to) |
| It sets the email parameters. | |
| uint8_t | setEmailPwd (char *user, char *pwd) |
| It sets the email user and password. | |
| uint8_t | setEmailDestination (char *destination) |
| It sets the email destination. | |
| uint8_t | setEmailSubject (char *subject) |
| It sets the email subject. | |
| void | getIfReady () |
| It gets if GPRS module is ready or not. | |
| byte | sendATCommand (char *ATcommand, char *expectedAnswer) |
| It sends an AT command to the module. | |
| byte | sendATCommand (char *ATcommand, char *expectedAnswer, int sendOnce) |
| It sends an AT command to the module. | |
| byte | sendCommand (char *theText, int endOfCommand, char *expectedAnswer) |
| It sends an AT command to the module. | |
| byte | sendCommand (char *theText, int endOfCommand, char *expectedAnswer, int MAX_TIMEOUT, int sendOnce) |
| It sends an AT command to the module. | |
| byte | sendCommand (char *theText, int endOfCommand, char *expectedAnswer, int sendOnce) |
| It sends an AT command to the module. | |
| byte | sendCommand (char *theText, char endOfCommand, char *expectedAnswer) |
| It sends an AT command to the module. | |
| byte | sendCommand (char *theText, char endOfCommand, char *expectedAnswer, int MAX_TIMEOUT) |
| It sends an AT command to the module. | |
| byte | sendCommand (char *theText, char endOfCommand, char *expectedAnswer, int MAX_TIMEOUT, int sendOnce) |
| It sends an AT command to the module. | |
| byte | sendCommand (char *theText, char *endOfCommand, char *expectedAnswer) |
| It sends an AT command to the module. | |
| byte | sendCommand (char *theText, char *endOfCommand, char *expectedAnswer, int sendOnce) |
| It sends an AT command to the module. | |
| byte | sendCommand (char *theText, char *endOfCommand, char *expectedAnswer, int MAX_TIMEOUT, int sendOnce) |
| It sends an AT command to the module. | |
| byte | waitForData (char *expectedAnswer, int MAX_TIMEOUT, int timeout, int seconds) |
| It waits for data from the module. | |
| uint16_t | waitForData (char *data, char *expectedAnswer) |
| It waits for data from the module. | |
| uint8_t | sendDataFTP (char *file, char *path, uint8_t id) |
| It sends data via FTP. | |
| uint8_t | readDataFTP (char *file, char *path, uint8_t id) |
| It reads data via FTP. | |
Private Attributes | |
| uint8_t | not_ready |
| Variable : stores if the module is ready or not (1:not ready, 0:ready). | |
| char | theCommand [100] |
| Variable : array for storing part of the data to send to the module. | |
| char | theEnd [10] |
| Variable : array for storing part of the data to send to the module. | |
| char | received [100] |
| Variable : array for storing the data received from the module. | |
WaspGPRS Class defines all the variables and functions used to manage GPRS module
Definition at line 193 of file WaspGPRS.h.
| WaspGPRS::WaspGPRS | ( | ) |
| uint8_t WaspGPRS::setPattern | ( | const char * | pattern | ) | [private] |
It sets the pattern for using in sending and receiving messages.
| const | char* pattern : pattern to set |
Definition at line 50 of file WaspGPRS.cpp.
References AT_GPRS_PATTERN, AT_GPRS_PATTERN_R, flag, GPRS_ERROR_PATTERN, and sendATCommand().
Referenced by configureGPRS().
00051 { 00052 char command[25]; 00053 char aux='"'; 00054 uint8_t answer=0; 00055 00056 flag &= ~(GPRS_ERROR_PATTERN); 00057 00058 sprintf(command,"%s%c%s%c",AT_GPRS_PATTERN,aux,pattern,aux); 00059 00060 answer=sendATCommand(command,AT_GPRS_PATTERN_R); 00061 switch(answer) 00062 { 00063 case 0 : flag |= GPRS_ERROR_PATTERN; 00064 return 0; 00065 break; 00066 case 2 : flag |= GPRS_ERROR_PATTERN; 00067 return 0; 00068 break; 00069 } 00070 if(flag) return 0; 00071 return 1; 00072 }


| uint8_t WaspGPRS::setConnectionTimer | ( | ) | [private] |
It sets the GPRS connection time out.
It gets the timer from 'WaspGPRSconstants.h' file
| void |
Definition at line 82 of file WaspGPRS.cpp.
References AT_GPRS_CNX_TIMER, AT_GPRS_CNX_TIMER_R, flag, GPRS_ERROR_TIMER, and sendATCommand().
Referenced by configureGPRS().
00083 { 00084 char command[25]; 00085 char aux='"'; 00086 uint8_t answer=0; 00087 00088 flag &= ~(GPRS_ERROR_TIMER); 00089 00090 sprintf(command,"%s0,120,2,120",AT_GPRS_CNX_TIMER); 00091 00092 answer=sendATCommand(command,AT_GPRS_CNX_TIMER_R); 00093 switch(answer) 00094 { 00095 case 0 : flag |= GPRS_ERROR_TIMER; 00096 return 0; 00097 break; 00098 case 2 : flag |= GPRS_ERROR_TIMER; 00099 return 0; 00100 break; 00101 } 00102 if(flag) return 0; 00103 return 1; 00104 }


| uint8_t WaspGPRS::setConnectionProfile | ( | ) | [private] |
It sets the GPRS connection profile.
It gets the profile from 'WaspGPRSconstants.h' file
| void |
Definition at line 146 of file WaspGPRS.cpp.
References AT_GPRS_CNX_PROFILE, AT_GPRS_CNX_PROFILE_R, flag, GPRS_ERROR_PROFILE, and sendATCommand().
Referenced by configureGPRS().
00147 { 00148 char command[25]; 00149 char aux='"'; 00150 uint8_t answer=0; 00151 00152 flag &= ~(GPRS_ERROR_PROFILE); 00153 00154 answer=sendATCommand(AT_GPRS_CNX_PROFILE,AT_GPRS_CNX_PROFILE_R); 00155 switch(answer) 00156 { 00157 case 0 : flag |= GPRS_ERROR_PROFILE; 00158 return 0; 00159 break; 00160 case 2 : flag |= GPRS_ERROR_PROFILE; 00161 return 0; 00162 break; 00163 } 00164 if(flag) return 0; 00165 return 1; 00166 }


| uint8_t WaspGPRS::setFlowControl | ( | ) | [private] |
It sets GPRS flow control.
It gets the flow control from 'WaspGPRSconstants.h' file
| void |
Definition at line 176 of file WaspGPRS.cpp.
References AT_GPRS_K3, AT_GPRS_K3_R, flag, GPRS_ERROR_PROFILE, GPRS_ERROR_SMTP, and sendATCommand().
Referenced by downloadFile(), readMail(), sendMail(), and uploadFile().
00177 { 00178 char command[25]; 00179 char aux='"'; 00180 uint8_t answer=0; 00181 00182 flag &= ~(GPRS_ERROR_PROFILE); 00183 00184 answer=sendATCommand(AT_GPRS_K3,AT_GPRS_K3_R); 00185 switch(answer) 00186 { 00187 case 0 : flag |= GPRS_ERROR_SMTP; 00188 return 0; 00189 break; 00190 case 2 : flag |= GPRS_ERROR_SMTP; 00191 return 0; 00192 break; 00193 } 00194 if(flag) return 0; 00195 return 1; 00196 }


| uint8_t WaspGPRS::checkGPRS | ( | ) | [private] |
It checks if GPRS connection is OK.
| void |
Definition at line 115 of file WaspGPRS.cpp.
References AT_GPRS_CHECK, AT_GPRS_CHECK_R, flag, GPRS_ERROR_CHECK, and sendATCommand().
Referenced by configureGPRS().
00116 { 00117 char command[25]; 00118 char aux='"'; 00119 uint8_t answer=0; 00120 00121 flag &= ~(GPRS_ERROR_CHECK); 00122 00123 answer=sendATCommand(AT_GPRS_CHECK,AT_GPRS_CHECK_R); 00124 switch(answer) 00125 { 00126 case 0 : flag |= GPRS_ERROR_CHECK; 00127 return 0; 00128 break; 00129 case 2 : flag |= GPRS_ERROR_CHECK; 00130 return 0; 00131 break; 00132 } 00133 if(flag) return 0; 00134 return 1; 00135 }


| uint8_t WaspGPRS::writeData | ( | const char * | data | ) | [private] |
It writes data to send via GPRS socket.
| const | char* data : data to send via socket |
Definition at line 205 of file WaspGPRS.cpp.
References GPRS_MAX_DATA, GPRS_PATTERN, PORT_USED, and printString().
Referenced by sendData().
00206 { 00207 char command[GPRS_MAX_DATA+15]; 00208 00209 sprintf(command,"%s%c%c%s",data,'\r','\n',GPRS_PATTERN); 00210 printString(command,PORT_USED); 00211 }


| uint8_t WaspGPRS::parse_GSM | ( | char * | data | ) | [private] |
It parses GSM string and specifies if it is a call or a SMS.
| const | char* data : string to parse |
Definition at line 220 of file WaspGPRS.cpp.
Referenced by manageIncomingGSMData().
00221 { 00222 uint8_t a=0; 00223 char cmp[5]; 00224 00225 while( (data[a]!='+') && (a<=45) ){ 00226 a++; 00227 } 00228 a++; 00229 for(int b=0;b<4;b++) 00230 { 00231 cmp[b]=data[a]; 00232 a++; 00233 } 00234 cmp[4]='\0'; 00235 if(!strcmp(cmp,"CLIP")) return 0; 00236 if(!strcmp(cmp,"CMTI")) return 1; 00237 return 2; 00238 }

| uint8_t WaspGPRS::setEmailParams | ( | char * | smtp_server, | |
| uint16_t | port, | |||
| char * | to | |||
| ) | [private] |
It sets the email parameters.
| char* | smtp_server : smtp server address | |
| uint16_t | port : smtp server port | |
| char* | to : origin or user address |
Definition at line 246 of file WaspGPRS.cpp.
References AT_SMTP_PARAM, AT_SMTP_PARAM_R, flag, GPRS_ERROR_SMTP, and sendATCommand().
Referenced by sendMail().
00247 { 00248 char command[100]; 00249 char aux='"'; 00250 uint8_t answer=0; 00251 00252 sprintf(command,"%s%c%s%c,%u,%c%s%c",AT_SMTP_PARAM,aux,smtp_server,aux,port,aux,to,aux); 00253 answer=sendATCommand(command,AT_SMTP_PARAM_R); 00254 switch(answer) 00255 { 00256 case 0 : flag |= GPRS_ERROR_SMTP; 00257 return 0; 00258 break; 00259 case 2 : flag |= GPRS_ERROR_SMTP; 00260 return 0; 00261 break; 00262 } 00263 if(flag) return 0; 00264 return 1; 00265 }


| uint8_t WaspGPRS::setEmailPwd | ( | char * | user, | |
| char * | pwd | |||
| ) | [private] |
It sets the email user and password.
| char* | user : email user | |
| char* | pwd : email password |
Definition at line 273 of file WaspGPRS.cpp.
References AT_SMTP_PWD, AT_SMTP_PWD_R, flag, GPRS_ERROR_SMTP, and sendATCommand().
Referenced by sendMail().
00274 { 00275 char command[100]; 00276 char aux='"'; 00277 uint8_t answer=0; 00278 00279 sprintf(command,"%s%c%s%c,%c%s%c",AT_SMTP_PWD,aux,user,aux,aux,pwd,aux); 00280 answer=sendATCommand(command,AT_SMTP_PWD_R); 00281 switch(answer) 00282 { 00283 case 0 : flag |= GPRS_ERROR_SMTP; 00284 return 0; 00285 break; 00286 case 2 : flag |= GPRS_ERROR_SMTP; 00287 return 0; 00288 break; 00289 } 00290 if(flag) return 0; 00291 return 1; 00292 }


| uint8_t WaspGPRS::setEmailDestination | ( | char * | destination | ) | [private] |
It sets the email destination.
| char* | destination : email destination |
Definition at line 300 of file WaspGPRS.cpp.
References AT_SMTP_TO, AT_SMTP_TO_R, flag, GPRS_ERROR_SMTP, and sendATCommand().
Referenced by sendMail().
00301 { 00302 char command[50]; 00303 char aux='"'; 00304 uint8_t answer=0; 00305 00306 sprintf(command,"%s%c%s%c",AT_SMTP_TO,aux,destination,aux); 00307 answer=sendATCommand(command,AT_SMTP_TO_R); 00308 switch(answer) 00309 { 00310 case 0 : flag |= GPRS_ERROR_SMTP; 00311 return 0; 00312 break; 00313 case 2 : flag |= GPRS_ERROR_SMTP; 00314 return 0; 00315 break; 00316 } 00317 if(flag) return 0; 00318 return 1; 00319 }


| uint8_t WaspGPRS::setEmailSubject | ( | char * | subject | ) | [private] |
It sets the email subject.
| char* | subject : email subject |
Definition at line 327 of file WaspGPRS.cpp.
References AT_SMTP_SUBJECT, AT_SMTP_SUBJECT_R, flag, GPRS_ERROR_SMTP, and sendATCommand().
Referenced by sendMail().
00328 { 00329 char command[50]; 00330 char aux='"'; 00331 uint8_t answer=0; 00332 00333 sprintf(command,"%s%c%s%c",AT_SMTP_SUBJECT,aux,subject,aux); 00334 answer=sendATCommand(command,AT_SMTP_SUBJECT_R); 00335 switch(answer) 00336 { 00337 case 0 : flag |= GPRS_ERROR_SMTP; 00338 return 0; 00339 break; 00340 case 2 : flag |= GPRS_ERROR_SMTP; 00341 return 0; 00342 break; 00343 } 00344 if(flag) return 0; 00345 return 1; 00346 }


| void WaspGPRS::getIfReady | ( | ) | [private] |
It gets if GPRS module is ready or not.
Definition at line 715 of file WaspGPRS.cpp.
References AT_COMMAND, delay(), not_ready, PORT_USED, printByte(), printString(), and waitForData().
00716 { 00717 char command[20]; 00718 char aux='"'; 00719 uint8_t answer=0; 00720 long previous=0; 00721 00722 printString(AT_COMMAND,PORT_USED); 00723 printByte('\r',PORT_USED); 00724 printByte('\n',PORT_USED); 00725 /* while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<3000) );*/ 00726 delay(10); 00727 answer=waitForData("OK",2,0,0); 00728 if(answer==1) not_ready=0; 00729 else not_ready=1; 00730 }

| byte WaspGPRS::sendATCommand | ( | char * | ATcommand, | |
| char * | expectedAnswer | |||
| ) | [private] |
It sends an AT command to the module.
| char* | ATcommand : string to send to the module | |
| char* | expectedAnswer : string expected to be answered by the module |
Definition at line 351 of file WaspGPRS.cpp.
Referenced by checkGPRS(), closeSocket(), configureGPRS(), hangUp(), makeCall(), makeLostCall(), sendSMS(), setConnectionProfile(), setConnectionTimer(), setEmailDestination(), setEmailParams(), setEmailPwd(), setEmailSubject(), setFlowControl(), setInfoIncomingCall(), setInfoIncomingSMS(), setMode(), setPattern(), setPIN(), and setTextModeSMS().
00351 { 00352 return sendATCommand(ATcommand, expectedAnswer, 0); 00353 }

| byte WaspGPRS::sendATCommand | ( | char * | ATcommand, | |
| char * | expectedAnswer, | |||
| int | sendOnce | |||
| ) | [private] |
It sends an AT command to the module.
| char* | ATcommand : string to send to the module | |
| char* | expectedAnswer : string expected to be answered by the module | |
| int | sendOnce : specifies if the data is sent once |
Definition at line 355 of file WaspGPRS.cpp.
References sendCommand(), and theCommand.
00355 { 00356 // command style: +CMGS=0736584317 00357 // this means, we gotta add the "AT" 00358 00359 sprintf(theCommand, "AT%s", ATcommand); 00360 return sendCommand(theCommand, "\r\n", expectedAnswer, sendOnce); 00361 }

| byte WaspGPRS::sendCommand | ( | char * | theText, | |
| int | endOfCommand, | |||
| char * | expectedAnswer | |||
| ) | [private] |
It sends an AT command to the module.
| char* | theText : string to send to the module | |
| int | endOfCommand : integer to send to the module | |
| char* | expectedAnswer : string expected to be answered by the module |
Definition at line 363 of file WaspGPRS.cpp.
Referenced by sendATCommand(), sendCommand(), and sendSMS().
00363 { 00364 return sendCommand(theText, endOfCommand, expectedAnswer, 0); 00365 }

| byte WaspGPRS::sendCommand | ( | char * | theText, | |
| int | endOfCommand, | |||
| char * | expectedAnswer, | |||
| int | MAX_TIMEOUT, | |||
| int | sendOnce | |||
| ) | [private] |
It sends an AT command to the module.
| char* | theText : string to send to the module | |
| int | endOfCommand : integer to send to the module | |
| char* | expectedAnswer : string expected to be answered by the module | |
| int | MAX_TIMEOUT : specifies the maximum timeout | |
| int | sendOnce : specifies if the data is sent once |
Definition at line 367 of file WaspGPRS.cpp.
References sendCommand(), and theEnd.
00367 { 00368 sprintf(theEnd, "%c", endOfCommand); 00369 return sendCommand(theText, theEnd, expectedAnswer, MAX_TIMEOUT, sendOnce); 00370 }

| byte WaspGPRS::sendCommand | ( | char * | theText, | |
| int | endOfCommand, | |||
| char * | expectedAnswer, | |||
| int | sendOnce | |||
| ) | [private] |
It sends an AT command to the module.
| char* | theText : string to send to the module | |
| int | endOfCommand : integer to send to the module | |
| char* | expectedAnswer : string expected to be answered by the module | |
| int | sendOnce : specifies if the data is sent once |
Definition at line 372 of file WaspGPRS.cpp.
References sendCommand(), and theEnd.
00372 { 00373 sprintf(theEnd, "%c", endOfCommand); 00374 return sendCommand(theText, theEnd, expectedAnswer, sendOnce); 00375 }

| byte WaspGPRS::sendCommand | ( | char * | theText, | |
| char | endOfCommand, | |||
| char * | expectedAnswer | |||
| ) | [private] |
It sends an AT command to the module.
| char* | theText : string to send to the module | |
| char | endOfCommand : character to send to the module | |
| char* | expectedAnswer : string expected to be answered by the module |
Definition at line 377 of file WaspGPRS.cpp.
References sendCommand().
00377 { 00378 return sendCommand(theText, (int) endOfCommand, expectedAnswer, 0); 00379 }

| byte WaspGPRS::sendCommand | ( | char * | theText, | |
| char | endOfCommand, | |||
| char * | expectedAnswer, | |||
| int | MAX_TIMEOUT | |||
| ) | [private] |
It sends an AT command to the module.
| char* | theText : string to send to the module | |
| char | endOfCommand : character to send to the module | |
| char* | expectedAnswer : string expected to be answered by the module | |
| int | MAX_TIMEOUT : specifies the maximum timeout |
Definition at line 381 of file WaspGPRS.cpp.
References sendCommand().
00381 { 00382 return sendCommand(theText, (int) endOfCommand, expectedAnswer, MAX_TIMEOUT, 0); 00383 }

| byte WaspGPRS::sendCommand | ( | char * | theText, | |
| char | endOfCommand, | |||
| char * | expectedAnswer, | |||
| int | MAX_TIMEOUT, | |||
| int | sendOnce | |||
| ) | [private] |
It sends an AT command to the module.
| char* | theText : string to send to the module | |
| char | endOfCommand : character to send to the module | |
| char* | expectedAnswer : string expected to be answered by the module | |
| int | MAX_TIMEOUT : specifies the maximum timeout | |
| int | sendOnce : specifies if the data is sent once |
Definition at line 385 of file WaspGPRS.cpp.
References sendCommand().
00385 { 00386 return sendCommand(theText, (int) endOfCommand, expectedAnswer, MAX_TIMEOUT, sendOnce); 00387 }

| byte WaspGPRS::sendCommand | ( | char * | theText, | |
| char * | endOfCommand, | |||
| char * | expectedAnswer | |||
| ) | [private] |
It sends an AT command to the module.
| char* | theText : string to send to the module | |
| char* | endOfCommand : string to send to the module | |
| char* | expectedAnswer : string expected to be answered by the module |
Definition at line 389 of file WaspGPRS.cpp.
References DEFAULT_TIMEOUT, and sendCommand().
00389 { 00390 return sendCommand(theText, endOfCommand, expectedAnswer, DEFAULT_TIMEOUT, 0); 00391 }

| byte WaspGPRS::sendCommand | ( | char * | theText, | |
| char * | endOfCommand, | |||
| char * | expectedAnswer, | |||
| int | sendOnce | |||
| ) | [private] |
It sends an AT command to the module.
| char* | theText : string to send to the module | |
| char* | endOfCommand : string to send to the module | |
| char* | expectedAnswer : string expected to be answered by the module | |
| int | sendOnce : specifies if the data is sent once |
Definition at line 393 of file WaspGPRS.cpp.
References DEFAULT_TIMEOUT, and sendCommand().
00393 { 00394 return sendCommand(theText, endOfCommand, expectedAnswer, DEFAULT_TIMEOUT, sendOnce); 00395 }

| byte WaspGPRS::sendCommand | ( | char * | theText, | |
| char * | endOfCommand, | |||
| char * | expectedAnswer, | |||
| int | MAX_TIMEOUT, | |||
| int | sendOnce | |||
| ) | [private] |
It sends an AT command to the module.
| char* | theText : string to send to the module | |
| char* | endOfCommand : string to send to the module | |
| char* | expectedAnswer : string expected to be answered by the module | |
| int | MAX_TIMEOUT : specifies the maximum timeout | |
| int | sendOnce : specifies if the data is sent once |
Definition at line 397 of file WaspGPRS.cpp.
References delay(), DELAY_ON_SEND, PORT_USED, printString(), received, serialAvailable(), serialFlush(), theCommand, and waitForData().
00397 { 00398 int timeout = 0; 00399 00400 for (int i = 0; i < 100; i++) received[i] = ' '; 00401 00402 int length=sprintf(theCommand, "%s%s", theText,endOfCommand); 00403 00404 00405 // try sending the command 00406 // wait for serial response 00407 timeout = 0; 00408 serialFlush(PORT_USED); 00409 while(!serialAvailable(PORT_USED) && timeout < MAX_TIMEOUT) { 00410 if (!sendOnce || !timeout) { 00411 printString(theCommand,PORT_USED); 00412 } 00413 delay(DELAY_ON_SEND); 00414 timeout++; 00415 }; 00416 00417 int answer= waitForData( expectedAnswer, MAX_TIMEOUT, timeout, 0); 00418 00419 return answer; 00420 }

| byte WaspGPRS::waitForData | ( | char * | expectedAnswer, | |
| int | MAX_TIMEOUT, | |||
| int | timeout, | |||
| int | seconds | |||
| ) | [private] |
It waits for data from the module.
| char* | expectedAnswer : string expected to be answered by the module | |
| int | MAX_TIMEOUT : specifies the maximum timeout | |
| int | timeout : specifies the timeout | |
| int | seconds : specifies the number of seconds to wait before listening to the module |
Definition at line 423 of file WaspGPRS.cpp.
References delay(), PORT_USED, received, serialAvailable(), and serialRead().
Referenced by check(), createSocket(), downloadFile(), getIfReady(), readData(), readDataFTP(), readMail(), readURL(), sendCommand(), sendData(), sendDataFTP(), sendMail(), and uploadFile().
00423 { 00424 00425 for (int i = 0; i < 100; i++) received[i] = ' '; 00426 00427 char command[50]; 00428 int theLength = 0; 00429 int it=0; 00430 bool theSame=false; 00431 bool errorAnswer=false; 00432 int inbyte=0; 00433 byte countLetters = 0; 00434 char* errorCommand="ERROR"; 00435 uint8_t errorLength=5; 00436 00437 uint8_t first=1; 00438 uint8_t match=0; 00439 00440 while( expectedAnswer[theLength]!='\0' ) theLength++; 00441 00442 // if there is a heating time, then wait to see if you got 00443 // any data from the serial port 00444 while (seconds >0) { 00445 delay(1000); 00446 seconds--; 00447 } 00448 00449 while(timeout < MAX_TIMEOUT) { 00450 while(!serialAvailable(PORT_USED) && timeout < MAX_TIMEOUT) { 00451 timeout++; 00452 delay(1000); 00453 } 00454 00455 while( serialAvailable(PORT_USED) && !match ) 00456 { 00457 if( first ) 00458 { 00459 for(it=0;it<theLength;it++) 00460 { 00461 received[it]=serialRead(PORT_USED); 00462 } 00463 first=0; 00464 } 00465 it=0; 00466 00467 if( serialAvailable(PORT_USED) ) 00468 { 00469 theSame=true; 00470 for(it=0; it<theLength ; it++) 00471 { 00472 if(received[it]!=expectedAnswer[it]){ 00473 theSame= false; 00474 break; 00475 } 00476 } 00477 if( theSame ){ 00478 match=1; 00479 return 1; 00480 } 00481 else 00482 { 00483 for(it=0; it<theLength-1 ; it++) 00484 { 00485 received[it]=received[it+1]; 00486 } 00487 received[it]=serialRead(PORT_USED); 00488 } 00489 } 00490 } 00491 } 00492 if( match ) return 1; 00493 else return 0; 00494 }


| uint16_t WaspGPRS::waitForData | ( | char * | data, | |
| char * | expectedAnswer | |||
| ) | [private] |
It waits for data from the module.
| char* | data : data where the 'expectedAnswer' has to be found | |
| char* | expectedAnswer : string expected to be answered by the module |
Definition at line 496 of file WaspGPRS.cpp.
References received.
00497 { 00498 uint16_t i=0; 00499 for (i = 0; i < 100; i++) received[i] = ' '; 00500 00501 int theLength = 0; 00502 int it=0; 00503 bool theSame=false; 00504 00505 uint8_t first=1; 00506 uint8_t match=0; 00507 i=0; 00508 00509 while( expectedAnswer[theLength]!='\0' ) theLength++; 00510 00511 while( !match && data[i]!='\0' ) 00512 { 00513 if( first ) 00514 { 00515 for(it=0;it<theLength;it++) 00516 { 00517 received[it]=data[i]; 00518 i++; 00519 00520 } 00521 first=0; 00522 } 00523 it=0; 00524 theSame=true; 00525 for(it=0; it<theLength ; it++) 00526 { 00527 if(received[it]!=expectedAnswer[it]){ 00528 theSame= false; 00529 break; 00530 } 00531 } 00532 if( theSame ) match=1; 00533 else 00534 { 00535 for(it=0; it<theLength-1 ; it++) 00536 { 00537 received[it]=received[it+1]; 00538 } 00539 received[it]=data[i]; 00540 i++; 00541 } 00542 } 00543 00544 if( !match ) i=0; 00545 return i; 00546 }
| uint8_t WaspGPRS::sendDataFTP | ( | char * | file, | |
| char * | path, | |||
| uint8_t | id | |||
| ) | [private] |
It sends data via FTP.
| char* | file : file to upload | |
| char* | path : path within SD card to find the file to upload | |
| uint8_t | id : ftp session id |
Definition at line 548 of file WaspGPRS.cpp.
References WaspUtils::arguments, AT_FTP_SEND, WaspSD::begin(), WaspSD::buffer, WaspSD::cat(), WaspSD::cd(), WaspSD::close(), delay(), GPRS_PATTERN, WaspSD::init(), millis(), PORT_USED, printString(), SD, SD_OFF, SD_ON, serialAvailable(), serialFlush(), WaspSD::setMode(), WaspUtils::strExplode(), Utils, and waitForData().
Referenced by uploadFile().
00549 { 00550 char command[50]; 00551 char aux='"'; 00552 long previous=0; 00553 uint8_t answer=0; 00554 uint8_t end=0; 00555 uint32_t i,j=0; 00556 00557 sprintf(command,"AT%s%c,,%c%c,%c%s%c,0%c%c", AT_FTP_SEND, id, aux, aux, aux, file, aux, '\r', '\n'); 00558 printString(command,PORT_USED); 00559 previous=millis(); 00560 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<10000) ); 00561 delay(10); 00562 answer=waitForData("CONNECT",20,0,0); 00563 if(answer!=1) return 0; 00564 00565 serialFlush(PORT_USED); 00566 00567 SD.begin(); 00568 SD.setMode(SD_ON); 00569 SD.init(); 00570 Utils.strExplode(path,'/'); 00571 while( path[i]!='\0' ) 00572 { 00573 if( path[i]== '/' ) j++; 00574 i++; 00575 } 00576 i=0; 00577 while( j>0 ) 00578 { 00579 if(!SD.cd(Utils.arguments[i])) return 0; 00580 i++; 00581 j--; 00582 } 00583 i=0; 00584 j=0; 00585 while( !end ) 00586 { 00587 printString(SD.cat(file,250*i,250),PORT_USED); 00588 while( SD.buffer[j]!='\0' ) j++; 00589 if( j<249 ) end=1; 00590 i++; 00591 j=0; 00592 } 00593 printString(GPRS_PATTERN,PORT_USED); 00594 00595 SD.close(); 00596 SD.setMode(SD_OFF); 00597 00598 previous=millis(); 00599 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<10000) ); 00600 delay(10); 00601 answer=waitForData("OK",20,0,0); 00602 if(answer!=1) return 0; 00603 00604 return 1; 00605 }


| uint8_t WaspGPRS::readDataFTP | ( | char * | file, | |
| char * | path, | |||
| uint8_t | id | |||
| ) | [private] |
It reads data via FTP.
| char* | file : file to download | |
| char* | path : path within SD card to store the file to download | |
| uint8_t | id : ftp session id |
Definition at line 608 of file WaspGPRS.cpp.
References WaspSD::append(), WaspUtils::arguments, AT_FTP_RECV, WaspSD::begin(), WaspSD::cd(), WaspSD::close(), WaspSD::create(), delay(), GPRS_PATTERN, WaspSD::init(), WaspSD::ls(), MAX_SIZE_FTP, millis(), PORT_USED, printString(), SD, SD_OFF, SD_ON, serialAvailable(), serialRead(), WaspSD::setMode(), WaspUtils::sizeOf(), WaspUtils::strExplode(), Utils, and waitForData().
Referenced by downloadFile().
00609 { 00610 char command[50]; 00611 char aux='"'; 00612 long previous=0; 00613 uint8_t answer=0; 00614 uint8_t end=0; 00615 int i,j=0; 00616 uint8_t timeout=0; 00617 uint8_t MAX_TIMEOUT=10; 00618 char* aux2; 00619 uint16_t length=0; 00620 00621 sprintf(command,"AT%s%c,,%c%c,%c%s%c,0%c%c", AT_FTP_RECV, id, aux, aux, aux, file, aux, '\r', '\n'); 00622 printString(command,PORT_USED); 00623 previous=millis(); 00624 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<10000) ); 00625 delay(10); 00626 answer=waitForData("CONNECT",30,0,0); 00627 if(answer!=1){ 00628 free(aux2); 00629 aux2=NULL; 00630 return 0; 00631 } 00632 00633 delay(20); 00634 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<10000) ); 00635 00636 aux2 = (char*) calloc(MAX_SIZE_FTP,sizeof(char)); 00637 if( aux2==NULL ) return 0; 00638 00639 serialRead(PORT_USED); 00640 serialRead(PORT_USED); 00641 previous=millis(); 00642 i=0; 00643 while( millis()-previous<5000 ) 00644 { 00645 while( serialAvailable(PORT_USED) && i<MAX_SIZE_FTP ) 00646 { 00647 aux2[i]=serialRead(PORT_USED); 00648 i++; 00649 previous=millis(); 00650 } 00651 } 00652 if( i>=MAX_SIZE_FTP ) aux2[i-1]='\0'; 00653 else aux2[i]='\0'; 00654 00655 length=waitForData(aux2,GPRS_PATTERN); 00656 if( !length ) length=i; 00657 else 00658 { 00659 j=Utils.sizeOf(GPRS_PATTERN); 00660 length-=j; 00661 } 00662 00663 i=0; 00664 j=0; 00665 SD.begin(); 00666 SD.setMode(SD_ON); 00667 SD.init(); 00668 Utils.strExplode(path,'/'); 00669 while( path[i]!='\0' ) 00670 { 00671 if( path[i]== '/' ) j++; 00672 i++; 00673 } 00674 i=0; 00675 while( j>0 ) 00676 { 00677 if(!SD.cd(Utils.arguments[i])){ 00678 SD.close(); 00679 SD.setMode(SD_OFF); 00680 free(aux2); 00681 aux2=NULL; 00682 return 0; 00683 } 00684 i++; 00685 j--; 00686 } 00687 SD.create(Utils.arguments[i]); 00688 00689 if(!SD.append(Utils.arguments[i],aux2,length)){ 00690 SD.close(); 00691 SD.setMode(SD_OFF); 00692 free(aux2); 00693 aux2=NULL; 00694 return 0; 00695 } 00696 00697 SD.ls(); 00698 00699 SD.close(); 00700 SD.setMode(SD_OFF); 00701 00702 free(aux2); 00703 aux2=NULL; 00704 return 1; 00705 }


| void WaspGPRS::ON | ( | void | ) |
| void WaspGPRS::OFF | ( | ) |
It closes UART1 and powers off the GPRS module.
| void |
Definition at line 781 of file WaspGPRS.cpp.
References close(), GPRS_HIBERNATE, and setMode().
00782 { 00783 close(); 00784 setMode(GPRS_HIBERNATE); 00785 }

| void WaspGPRS::begin | ( | void | ) |
It opens UART and sets multiplexer properly.
| void |
Definition at line 755 of file WaspGPRS.cpp.
References _baudRate, _uart, beginSerial(), GPRS_RATE, WaspUtils::setMuxGPRS(), and Utils.
Referenced by ON().
00756 { 00757 _baudRate=GPRS_RATE; 00758 Utils.setMuxGPRS(); 00759 beginSerial(_baudRate,_uart); 00760 }


| void WaspGPRS::close | ( | void | ) |
It closes UART and sets multiplexer properly.
| void |
Definition at line 769 of file WaspGPRS.cpp.
References _uart, closeSerial(), MUX_TO_LOW, WaspUtils::setMux(), and Utils.
Referenced by OFF().
00770 { 00771 closeSerial(_uart); 00772 Utils.setMux(MUX_TO_LOW,MUX_TO_LOW); 00773 }


| uint8_t WaspGPRS::setMode | ( | uint8_t | pwrMode | ) |
It sets Power Mode.
| uint8_t | pwrMode : the desired power mode (GPRS_ON, GPRS_SLEEP or GPRS_HIBERNATE) |
Definition at line 797 of file WaspGPRS.cpp.
References _pwrMode, delay(), digitalWrite(), flag, GPRS_ERROR_POWER, GPRS_HIBERNATE, GPRS_ON, GPRS_PW, GPRS_SLEEP, HIGH, LOW, OUTPUT, pinMode(), POWER_HIBERNATE, POWER_R, POWER_SLEEP, and sendATCommand().
Referenced by OFF(), and ON().
00798 { 00799 _pwrMode=pwrMode; 00800 flag &= ~(GPRS_ERROR_POWER); 00801 uint8_t answer=0; 00802 00803 switch(_pwrMode) 00804 { 00805 case GPRS_ON : pinMode(GPRS_PW, OUTPUT); 00806 digitalWrite(GPRS_PW, HIGH); 00807 delay(2000); 00808 digitalWrite(GPRS_PW, LOW); 00809 delay(500); 00810 /* while(not_ready) getIfReady();*/ 00811 answer=1; 00812 break; 00813 00814 case GPRS_HIBERNATE : answer=sendATCommand(POWER_HIBERNATE,POWER_R); 00815 switch(answer) 00816 { 00817 case 0 : flag |= GPRS_ERROR_POWER; 00818 break; 00819 case 2 : flag |= GPRS_ERROR_POWER; 00820 break; 00821 } 00822 break; 00823 00824 case GPRS_SLEEP : answer=sendATCommand(POWER_SLEEP,POWER_R); 00825 switch(answer) 00826 { 00827 case 0 : flag |= GPRS_ERROR_POWER; 00828 break; 00829 case 2 : flag |= GPRS_ERROR_POWER; 00830 break; 00831 } 00832 break; 00833 00834 } 00835 return answer; 00836 }


| uint8_t WaspGPRS::getMode | ( | ) |
It gets Power Mode.
| void |
Definition at line 845 of file WaspGPRS.cpp.
References _pwrMode.
00846 { 00847 return _pwrMode; 00848 }
| uint8_t WaspGPRS::check | ( | void | ) |
It checks if GPRS is connected to the network.
| void |
Definition at line 860 of file WaspGPRS.cpp.
References DEFAULT_TIMEOUT, delay(), PORT_USED, printString(), and waitForData().
00861 { 00862 char byte; 00863 uint8_t timeout=DEFAULT_TIMEOUT; 00864 char command[10]; 00865 uint8_t answer=0; 00866 00867 while(timeout) 00868 { 00869 sprintf(command,"%s%c%c","AT+CREG?",'\r','\n'); 00870 printString(command,PORT_USED); 00871 answer=waitForData("+CREG: 0,1",1,0,0); 00872 switch(answer){ 00873 case 0: break; 00874 case 1: return 1; 00875 break; 00876 case 2: break; 00877 } 00878 printString(command,PORT_USED); 00879 answer=waitForData("+CREG: 0,5",1,0,0); 00880 switch(answer){ 00881 case 0: break; 00882 case 1: return 1; 00883 break; 00884 case 2: break; 00885 } 00886 delay(100); 00887 timeout--; 00888 } 00889 return 0; 00890 }

| uint8_t WaspGPRS::setPIN | ( | const char * | pin | ) |
It sets PIN.
| const | char* PIN : the SIM's PIN |
Definition at line 901 of file WaspGPRS.cpp.
References AT_PIN, AT_PIN_R, flag, GPRS_ERROR_PIN, SEND_ONCE, and sendATCommand().
00902 { 00903 char command[20]; 00904 flag &= ~(GPRS_ERROR_PIN); 00905 char aux='"'; 00906 uint8_t answer=0; 00907 00908 sprintf(command,"%s%c%s%c",AT_PIN,aux,pin,aux); 00909 answer=sendATCommand(command,AT_PIN_R,SEND_ONCE); 00910 switch(answer) 00911 { 00912 case 0 : flag |= GPRS_ERROR_PIN; 00913 break; 00914 case 2 : flag |= GPRS_ERROR_PIN; 00915 break; 00916 } 00917 if(flag) return 0; 00918 return 1; 00919 }

| uint8_t WaspGPRS::setInfoIncomingCall | ( | ) |
It sets the info shown when an incoming call is received.
| void |
Definition at line 930 of file WaspGPRS.cpp.
References AT_ID_INCALL, AT_ID_INCALL_R, flag, GPRS_ERROR_CALLINFO, SEND_ONCE, and sendATCommand().
Referenced by closeSocket().
00931 { 00932 char command[20]; 00933 flag &= ~(GPRS_ERROR_CALLINFO); 00934 uint8_t answer=0; 00935 00936 answer=sendATCommand(AT_ID_INCALL,AT_ID_INCALL_R,SEND_ONCE); 00937 switch(answer) 00938 { 00939 case 0 : flag |= GPRS_ERROR_CALLINFO; 00940 break; 00941 case 2 : flag |= GPRS_ERROR_CALLINFO; 00942 break; 00943 } 00944 if(flag) return 0; 00945 return 1; 00946 }


| uint8_t WaspGPRS::setInfoIncomingSMS | ( | ) |
It sets the info shown when an incoming SMS is received.
| void |
Definition at line 957 of file WaspGPRS.cpp.
References AT_SMS_INFO, AT_SMS_INFO_R, flag, GPRS_ERROR_CALLINFO, GPRS_ERROR_SMSINFO, SEND_ONCE, and sendATCommand().
00958 { 00959 char command[20]; 00960 flag &= ~(GPRS_ERROR_SMSINFO); 00961 uint8_t answer=0; 00962 00963 answer=sendATCommand(AT_SMS_INFO,AT_SMS_INFO_R,SEND_ONCE); 00964 switch(answer) 00965 { 00966 case 0 : flag |= GPRS_ERROR_SMSINFO; 00967 break; 00968 case 2 : flag |= GPRS_ERROR_CALLINFO; 00969 break; 00970 } 00971 if(flag) return 0; 00972 return 1; 00973 }

| uint8_t WaspGPRS::setTextModeSMS | ( | ) |
It sets 'text mode' for sending SMS.
| void |
Definition at line 984 of file WaspGPRS.cpp.
References AT_SMS_MODE, AT_SMS_MODE_R, flag, GPRS_ERROR_SMS, and sendATCommand().
00985 { 00986 char command[20]; 00987 flag &= ~(GPRS_ERROR_SMS); 00988 uint8_t answer=0; 00989 00990 answer=sendATCommand(AT_SMS_MODE,AT_SMS_MODE_R); 00991 switch(answer) 00992 { 00993 case 0 : flag |= GPRS_ERROR_SMS; 00994 return 0; 00995 break; 00996 case 2 : flag |= GPRS_ERROR_SMS; 00997 return 0; 00998 break; 00999 } 01000 if(flag) return 0; 01001 return 1; 01002 }

| uint8_t WaspGPRS::makeCall | ( | const char * | tlfNumber | ) |
It makes a call to the specified number.
| const | char* tlfNumber : telephone number to call. It must be a telephone number with 9 digits. |
Definition at line 1013 of file WaspGPRS.cpp.
References AT_CALL, AT_CALL_R, flag, GPRS_ERROR_CALL, SEND_ONCE, and sendATCommand().
01014 { 01015 char command[30]; 01016 flag &= ~(GPRS_ERROR_CALL); 01017 uint8_t answer=0; 01018 01019 sprintf(command,"%s%s;",AT_CALL,tlfNumber); 01020 answer=sendATCommand(command,AT_CALL_R,SEND_ONCE); 01021 switch(answer) 01022 { 01023 case 0 : flag |= GPRS_ERROR_CALL; 01024 break; 01025 case 2 : flag |= GPRS_ERROR_CALL; 01026 break; 01027 } 01028 if(flag) return 0; 01029 return 1; 01030 01031 }

| uint8_t WaspGPRS::makeLostCall | ( | const char * | tlfNumber, | |
| uint8_t | timeCall | |||
| ) |
It makes a lost call to the specified number.
| const | char* tlfNumber : telephone number to call. It must be a telephone number with 9 digits. | |
| uint8_t | timeCall : time the module is calling (in seconds) |
Definition at line 1043 of file WaspGPRS.cpp.
References AT_CALL, AT_CALL_R, delay(), flag, GPRS_ERROR_CALL, hangUp(), SEND_ONCE, and sendATCommand().
01044 { 01045 char command[25]; 01046 flag &= ~(GPRS_ERROR_CALL); 01047 uint8_t answer=0; 01048 01049 sprintf(command,"%s%s;",AT_CALL,tlfNumber); 01050 answer=sendATCommand(command,AT_CALL_R,SEND_ONCE); 01051 switch(answer) 01052 { 01053 case 0 : flag |= GPRS_ERROR_CALL; 01054 break; 01055 case 1 : for(int a=0; a<timeCall ; a++) delay(1000); 01056 hangUp(); 01057 break; 01058 case 2 : flag |= GPRS_ERROR_CALL; 01059 break; 01060 } 01061 if(flag) return 0; 01062 return 1; 01063 }

| uint8_t WaspGPRS::hangUp | ( | ) |
It hangs all the active calls up.
Definition at line 1074 of file WaspGPRS.cpp.
References AT_HANG, AT_HANG_R, flag, GPRS_ERROR_HANG, SEND_ONCE, and sendATCommand().
Referenced by makeLostCall().
01075 { 01076 uint8_t answer=0; 01077 flag &= ~(GPRS_ERROR_HANG); 01078 01079 answer=sendATCommand(AT_HANG,AT_HANG_R,SEND_ONCE); 01080 switch(answer) 01081 { 01082 case 0 : flag |= GPRS_ERROR_HANG; 01083 break; 01084 case 2 : flag |= GPRS_ERROR_HANG; 01085 break; 01086 } 01087 if(flag) return 0; 01088 return 1; 01089 }


| uint8_t WaspGPRS::sendSMS | ( | const char * | smsText, | |
| const char * | tlfNumber | |||
| ) |
It sends a SMS to the specified number.
| const | char* smsText : SMS text (up to 80bytes) | |
| const | char* tlfNumber : telephone number to call. It must be a telephone number with 9 digits. |
Definition at line 1100 of file WaspGPRS.cpp.
References AT_SMS, AT_SMS_R, AT_SMS_TEXT_R, flag, GPRS_ERROR_SMS, SEND_ONCE, sendATCommand(), and sendCommand().
01101 { 01102 flag &= ~(GPRS_ERROR_SMS); 01103 flag &= ~(GPRS_ERROR_SMS); 01104 char command[25]; 01105 char aux='"'; 01106 uint8_t answer=0; 01107 01108 sprintf(command,"%s%c%s%c",AT_SMS,aux,tlfNumber,aux); 01109 01110 01111 //setTextModeSMS(); 01112 answer=sendATCommand(command,AT_SMS_R); 01113 switch(answer) 01114 { 01115 case 0 : flag |= GPRS_ERROR_SMS; 01116 return 0; 01117 break; 01118 case 2 : flag |= GPRS_ERROR_SMS; 01119 return 0; 01120 break; 01121 } 01122 01123 answer=sendCommand((char*)smsText,0x1A,AT_SMS_TEXT_R,20,SEND_ONCE); 01124 switch(answer) 01125 { 01126 case 0 : flag |= GPRS_ERROR_SMS; 01127 return 0; 01128 break; 01129 case 2 : flag |= GPRS_ERROR_SMS; 01130 return 0; 01131 break; 01132 } 01133 01134 if(flag) return 0; 01135 return 1; 01136 }

| uint8_t WaspGPRS::readCall | ( | char * | data | ) |
It stores in 'tlfIN' variable the telephone number of the incoming call.
| char* | data : data returned by the module when a call is being received |
Definition at line 1149 of file WaspGPRS.cpp.
References tlfIN.
Referenced by manageIncomingGSMData().
01150 { 01151 uint8_t a=0; 01152 uint8_t b=0; 01153 01154 tlfIN[0]='\0'; 01155 while( (data[a]!='"') && (a<45) ) 01156 { 01157 a++; 01158 } 01159 a++; 01160 if(a>=45) return 0; 01161 while( (data[a]!='"') && (a<45) && (b<15) ) 01162 { 01163 tlfIN[b]=data[a]; 01164 a++; 01165 b++; 01166 } 01167 if( b>=15 ) tlfIN[b-1]='\0'; 01168 else tlfIN[b]='\0'; 01169 return 1; 01170 }

| uint8_t WaspGPRS::readSMS | ( | char * | data | ) |
It stores in 'tlfIN' and 'sms' variables the telephone number and the text of the incoming SMS. It stores in 'sms_index' variable the last sms received index.
| char* | data : data returned by the module when an SMS is received |
Definition at line 1181 of file WaspGPRS.cpp.
References AT_SMS_READ, millis(), PORT_USED, printString(), serialAvailable(), serialRead(), sms, sms_index, and tlfIN.
Referenced by manageIncomingGSMData().
01182 { 01183 uint8_t a=0,b=0,c=0; 01184 char command[30]; 01185 uint8_t byteIN[200]; 01186 long previous=0; 01187 uint8_t counter=0; 01188 01189 tlfIN[0]='\0'; 01190 sms[0]='\0'; 01191 sms_index[0]='\0'; 01192 while( (data[a]!=',') && (a<45) ) a++; 01193 a++; 01194 if(a>=45) return 0; 01195 while( data[a]!=13 ) 01196 { 01197 sms_index[b]=data[a]; 01198 a++; 01199 b++; 01200 } 01201 sms_index[b]='\0'; 01202 sprintf(command,"AT%s%s\r\n",AT_SMS_READ,sms_index); 01203 printString(command,PORT_USED); 01204 while(!serialAvailable(PORT_USED)); 01205 previous=millis(); 01206 a=0; 01207 while( (millis()-previous) < 2000 ) 01208 { 01209 while( serialAvailable(PORT_USED) && (millis()-previous) < 2000 ) 01210 { 01211 byteIN[a]=serialRead(PORT_USED); 01212 a++; 01213 } 01214 } 01215 a=0; 01216 while( counter <3 ) 01217 { 01218 while( (byteIN[a]!='"') && (a<200) ) 01219 { 01220 a++; 01221 } 01222 a++; 01223 counter++; 01224 } 01225 if(a>=200) return 0; 01226 counter=0; 01227 while( (byteIN[a]!='"') && (a<200) && (c<15) ) 01228 { 01229 tlfIN[c]=byteIN[a]; 01230 a++; 01231 c++; 01232 } 01233 if( c>=15 ) tlfIN[c-1]='\0'; 01234 else tlfIN[c]='\0'; 01235 while( counter < 5 ) 01236 { 01237 while( (byteIN[a]!='"') && (a<200) ) 01238 { 01239 a++; 01240 } 01241 a++; 01242 counter++; 01243 } 01244 if(a>=200) return 0; 01245 a++; 01246 a++; 01247 b=0; 01248 while( (byteIN[a]!=13) && (a<200) && (b<100) ) 01249 { 01250 sms[b]=byteIN[a]; 01251 b++; 01252 a++; 01253 } 01254 if(a>=200) return 0; 01255 if( b>=100 )sms[b-1]='\0'; 01256 else sms[b]='\0'; 01257 return 1; 01258 }


| uint8_t WaspGPRS::manageIncomingGSMData | ( | ) |
It manages incoming data from serial port, executing proper functions to store received data.
| void |
Definition at line 1267 of file WaspGPRS.cpp.
References millis(), parse_GSM(), PORT_USED, readCall(), readSMS(), serialAvailable(), serialFlush(), and serialRead().
01268 { 01269 char byteIN[100]; 01270 uint8_t a=0; 01271 long previous=0; 01272 uint8_t answer=0; 01273 01274 while(a<100){ 01275 byteIN[a]=0; 01276 a++; 01277 } 01278 a=0; 01279 01280 serialFlush(PORT_USED); 01281 previous=millis(); 01282 while(!serialAvailable(PORT_USED) && (millis()-previous)<20000); 01283 previous=millis(); 01284 while( (millis()-previous) < 2000 ) 01285 { 01286 while( serialAvailable(PORT_USED) && (millis()-previous) < 2000 ) 01287 { 01288 byteIN[a]=serialRead(PORT_USED); 01289 a++; 01290 } 01291 } 01292 answer=parse_GSM(byteIN); 01293 switch( answer ){ 01294 case 0: readCall(byteIN); 01295 break; 01296 case 1: readSMS(byteIN); 01297 break; 01298 } 01299 if(answer==2) return 0; 01300 return 1; 01301 }

| uint8_t WaspGPRS::configureGPRS | ( | ) |
It configures GPRS connection with login, password and some other parameters.
It takes the configuration parameters from 'WaspGPRSconstants.h' file
| void |
Definition at line 1312 of file WaspGPRS.cpp.
References AT_GPRS, AT_GPRS_APN, AT_GPRS_CONN_CFG, AT_GPRS_CONN_CFG_R, AT_GPRS_IP, AT_GPRS_LOGIN, AT_GPRS_PASSW, checkGPRS(), flag, GPRS_ERROR_CONF, GPRS_PATTERN, sendATCommand(), setConnectionProfile(), setConnectionTimer(), and setPattern().
Referenced by downloadFile(), readMail(), readURL(), sendMail(), and uploadFile().
01313 { 01314 char command[100]; 01315 char aux='"'; 01316 uint8_t answer=0; 01317 01318 flag &= ~(GPRS_ERROR_CONF); 01319 01320 sprintf(command,"%s0,%c%s%c,%c%s%c,%c%s%c,%c%s%c,%c%s%c",AT_GPRS_CONN_CFG,aux, 01321 AT_GPRS,aux,aux,AT_GPRS_APN,aux,aux,AT_GPRS_LOGIN,aux,aux,AT_GPRS_PASSW,aux,aux,AT_GPRS_IP,aux); 01322 01323 answer=sendATCommand(command,AT_GPRS_CONN_CFG_R); 01324 switch(answer) 01325 { 01326 case 0 : flag |= GPRS_ERROR_CONF; 01327 return 0; 01328 break; 01329 case 2 : flag |= GPRS_ERROR_CONF; 01330 return 0; 01331 break; 01332 } 01333 01334 if(!setConnectionTimer()) return 0; 01335 01336 if(!setConnectionProfile()) return 0; 01337 01338 if(!checkGPRS()) return 0; 01339 01340 if(!setPattern(GPRS_PATTERN)) return 0; 01341 01342 if(flag) return 0; 01343 return 1; 01344 }


| uint8_t WaspGPRS::createSocket | ( | const char * | ip, | |
| const char * | port, | |||
| uint8_t | mode | |||
| ) |
It creates a TCP/IP connection to the specified IP and PORT.
| const | char* ip : the IP to open a socket to | |
| const | char* port : the PORT to open a socket to | |
| uint8_t | mode : GPRS_CLIENT or GPRS_SERVER |
Definition at line 1357 of file WaspGPRS.cpp.
References AT_GPRS_TCP_CFG, AT_GPRS_TCP_CNX, delay(), flag, GPRS_CLIENT, GPRS_ERROR_SOCKET, GPRS_SERVER, millis(), PORT_USED, printByte(), printString(), serialAvailable(), serialFlush(), serialRead(), socket_ID, and waitForData().
Referenced by readURL().
01358 { 01359 char command[40]; 01360 char aux='"'; 01361 uint8_t answer=0; 01362 uint8_t byteIN=0; 01363 long previous=0; 01364 uint8_t counter=0; 01365 01366 flag &= ~(GPRS_ERROR_SOCKET); 01367 01368 switch(mode){ 01369 case GPRS_CLIENT: 01370 sprintf(command,"%s0,%u,%c%s%c,%s%c%c",AT_GPRS_TCP_CFG,mode,aux,ip,aux,port,'\r','\n'); 01371 break; 01372 case GPRS_SERVER: 01373 sprintf(command,"%s0,%u,%s%c%c",AT_GPRS_TCP_CFG,mode,port,'\r','\n'); 01374 break; 01375 } 01376 01377 01378 while( counter<3 ) 01379 { 01380 serialFlush(PORT_USED); 01381 printString(command,PORT_USED); 01382 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<3000) ); 01383 delay(10); 01384 answer=waitForData("+KTCPCFG:",20,0,0); 01385 if(answer==1) break; 01386 counter++; 01387 } 01388 01389 if(answer!=1) return 0; 01390 serialRead(PORT_USED); 01391 delay(30); 01392 socket_ID=serialRead(PORT_USED); 01393 delay(50); 01394 answer=0; 01395 counter=0; 01396 while( counter<3 ) 01397 { 01398 serialFlush(PORT_USED); 01399 printString(AT_GPRS_TCP_CNX,PORT_USED); 01400 printByte(socket_ID,PORT_USED); 01401 printByte('\r',PORT_USED); 01402 printByte('\n',PORT_USED); 01403 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<3000) ); 01404 delay(10); 01405 answer=waitForData("OK",20,0,10); 01406 if(answer==1) break; 01407 counter++; 01408 01409 } 01410 if(answer!=1) return 0; 01411 return 1; 01412 }


| uint8_t WaspGPRS::readURL | ( | const char * | url | ) |
It accesses to the specified URL and stores the info read in 'data_URL' variable.
It stores in 'data_URL' variable up to 100 bytes
| const | char* url : the URL to get the information from |
Definition at line 1424 of file WaspGPRS.cpp.
References closeSocket(), configureGPRS(), createSocket(), GPRS_CLIENT, GPRS_DATA_LENGTH, PORT_USED, readData(), sendData(), serialFlush(), socket_ID, and waitForData().
01425 { 01426 char command[30]; 01427 char* data=",20"; 01428 uint8_t answer=0; 01429 long previous=0; 01430 uint8_t byteIN=0; 01431 uint8_t a=0; 01432 01433 if(!configureGPRS()) return 0; 01434 01435 if(!createSocket(url,"80",GPRS_CLIENT)) return 0; 01436 01437 serialFlush(PORT_USED); 01438 sprintf(command,"%s%c%c","GET / HTTP/1.0",'\r','\n'); 01439 if(!sendData(command,socket_ID)){ 01440 closeSocket(socket_ID); 01441 return 0; 01442 } 01443 01444 waitForData("+KTCP_DATA:",20,0,0); 01445 if(readData(socket_ID,GPRS_DATA_LENGTH)<0){ 01446 closeSocket(socket_ID); 01447 return 0; 01448 } 01449 01450 while(!closeSocket(socket_ID)) closeSocket(socket_ID); 01451 01452 return 1; 01453 }

| uint8_t WaspGPRS::sendData | ( | const char * | data, | |
| uint8_t | socket | |||
| ) |
It sends 'data' to the specified 'socket'.
| const | char* data : the data to send to the socket | |
| uint8_t | socket: the socket's ID to communicate with |
Definition at line 1466 of file WaspGPRS.cpp.
References AT_GPRS_TCP_SND, delay(), millis(), PORT_USED, printString(), serialAvailable(), serialFlush(), waitForData(), and writeData().
Referenced by readURL().
01467 { 01468 char command[30]; 01469 uint8_t answer=0; 01470 long previous=0; 01471 uint8_t byteIN=0; 01472 uint8_t counter=0; 01473 01474 while(data[counter]!='\0') counter++; 01475 counter+=2; 01476 serialFlush(PORT_USED); 01477 sprintf(command,"%s%c,%u%c%c",AT_GPRS_TCP_SND,socket,counter,'\r','\n'); 01478 printString(command,PORT_USED); 01479 previous=millis(); 01480 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<3000) ); 01481 delay(10); 01482 answer=waitForData("CONNECT",20,0,0); 01483 if(answer!=1) return 0; 01484 answer=0; 01485 counter=0; 01486 while( (counter<3) && (answer!=1) ) 01487 { 01488 serialFlush(PORT_USED); 01489 delay(20); 01490 writeData(data); 01491 previous=millis(); 01492 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<3000) ); 01493 delay(10); 01494 answer=waitForData("OK",20,0,0); 01495 } 01496 if(answer!=1) return 0; 01497 return 1; 01498 }


| int8_t WaspGPRS::readData | ( | uint8_t | socket, | |
| const char * | data_length | |||
| ) |
It reads data of 'data_length' size from socket ID 'socket'.
| uint8_t | socket: the socket's ID to communicate with | |
| const | char* data_length : the data length to read from the socket |
Definition at line 1511 of file WaspGPRS.cpp.
References AT_GPRS_TCP_RCV, data_read, data_URL, delay(), GPRS_DATA_LENGTH_U, millis(), PORT_USED, printString(), serialAvailable(), serialFlush(), serialRead(), and waitForData().
Referenced by readURL().
01512 { 01513 char command[30]; 01514 uint8_t answer=0; 01515 long previous=0; 01516 uint8_t a=0; 01517 uint8_t byteIN=0; 01518 uint8_t aux[10]; 01519 01520 sprintf(command,"%s%u,%s%c%c",AT_GPRS_TCP_RCV,socket-'0',data_length,'\r','\n'); 01521 serialFlush(PORT_USED); 01522 delay(50); 01523 printString(command,PORT_USED); 01524 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<10000) ); 01525 delay(10); 01526 answer=waitForData("CONNECT",20,0,0); 01527 if(answer!=1) return -1; 01528 serialRead(PORT_USED); 01529 serialRead(PORT_USED); 01530 while(a<GPRS_DATA_LENGTH_U) 01531 { 01532 aux[0]=serialRead(PORT_USED); 01533 if(aux[0]=='E'){ 01534 aux[1]=serialRead(PORT_USED); 01535 if(aux[1]=='N'){ 01536 aux[2]=serialRead(PORT_USED); 01537 if(aux[2]=='D'){ 01538 aux[3]=serialRead(PORT_USED); 01539 if(aux[3]=='M'){ 01540 aux[4]=serialRead(PORT_USED); 01541 if(aux[4]=='E'){ 01542 aux[5]=serialRead(PORT_USED); 01543 if(aux[5]=='S'){ 01544 answer=1; 01545 break; 01546 } 01547 else{ 01548 data_URL[a]=aux[0]; 01549 data_URL[a+1]=aux[1]; 01550 data_URL[a+2]=aux[2]; 01551 data_URL[a+3]=aux[3]; 01552 data_URL[a+4]=aux[4]; 01553 data_URL[a+5]=aux[5]; 01554 a+=6; 01555 } 01556 } 01557 else{ 01558 data_URL[a]=aux[0]; 01559 data_URL[a+1]=aux[1]; 01560 data_URL[a+2]=aux[2]; 01561 data_URL[a+3]=aux[3]; 01562 data_URL[a+4]=aux[4]; 01563 a+=5; 01564 } 01565 } 01566 else{ 01567 data_URL[a]=aux[0]; 01568 data_URL[a+1]=aux[1]; 01569 data_URL[a+2]=aux[2]; 01570 data_URL[a+3]=aux[3]; 01571 a+=4; 01572 } 01573 } 01574 else{ 01575 data_URL[a]=aux[0]; 01576 data_URL[a+1]=aux[1]; 01577 data_URL[a+2]=aux[2]; 01578 a+=3; 01579 } 01580 } 01581 else{ 01582 data_URL[a]=aux[0]; 01583 data_URL[a+1]=aux[1]; 01584 a+=2; 01585 } 01586 } 01587 else{ 01588 data_URL[a]=aux[0]; 01589 a++; 01590 } 01591 } 01592 01593 01594 data_read+=a; 01595 if(answer && a<(GPRS_DATA_LENGTH_U-10)) return 1; 01596 if(answer && a>=(GPRS_DATA_LENGTH_U-10)) return 0; 01597 return -1; 01598 }


| uint8_t WaspGPRS::closeSocket | ( | uint8_t | socket | ) |
It closes 'socket' TCP/IP connection.
| uint8_t | socket: the socket's ID to close |
Definition at line 1609 of file WaspGPRS.cpp.
References AT_GPRS_TCP_CLOSE, AT_GPRS_TCP_CLOSE_R, flag, GPRS_ERROR_CLOSE, sendATCommand(), and setInfoIncomingCall().
Referenced by readURL().
01610 { 01611 char command[30]; 01612 long previous=0; 01613 uint8_t answer=0; 01614 uint8_t byteIN=0; 01615 01616 setInfoIncomingCall(); 01617 flag &= ~(GPRS_ERROR_CLOSE); 01618 sprintf(command,"%s%u,0",AT_GPRS_TCP_CLOSE,socket-'0'); 01619 01620 answer=sendATCommand(command,AT_GPRS_TCP_CLOSE_R); 01621 switch(answer) 01622 { 01623 case 0 : flag |= GPRS_ERROR_CLOSE; 01624 break; 01625 case 2 : flag |= GPRS_ERROR_CLOSE; 01626 break; 01627 } 01628 if(flag) return 0; 01629 return 1; 01630 }


| uint8_t WaspGPRS::sendCommand | ( | char * | ATcommand | ) |
It sends any command to the GPRS module.
| char* | ATcommand : the command to send to the GPRS module |
Definition at line 1703 of file WaspGPRS.cpp.
References answer_command, delay(), DELAY_ON_SEND, PORT_USED, printString(), serialAvailable(), serialFlush(), and serialRead().
01704 { 01705 char command[30]; 01706 uint8_t timeout=0; 01707 uint8_t i=0; 01708 01709 sprintf(command, "AT%s%c%c", ATcommand,'\r','\n'); 01710 01711 serialFlush(PORT_USED); 01712 while(!serialAvailable(PORT_USED)) { 01713 printString(command,PORT_USED); 01714 delay(DELAY_ON_SEND); 01715 } 01716 01717 while( timeout < 5 ) 01718 { 01719 while(!serialAvailable(PORT_USED) && timeout < 5) { 01720 timeout++; 01721 delay(1000); 01722 } 01723 while(serialAvailable(PORT_USED) && timeout < 5){ 01724 answer_command[i] = serialRead(PORT_USED); 01725 delay(20); 01726 i++; 01727 timeout=0; 01728 } 01729 } 01730 answer_command[i]='\0'; 01731 if( i<5 ) return 0; 01732 return 1; 01733 }

| uint8_t WaspGPRS::sendMail | ( | char * | from, | |
| char * | to, | |||
| char * | subject, | |||
| char * | body, | |||
| char * | user, | |||
| char * | passw, | |||
| char * | smtp_server, | |||
| uint16_t | port | |||
| ) |
It sends an email to the specified address.
| char* | from : sender address | |
| char* | to : receiver address | |
| char* | subject : email subject | |
| char* | body : text of the email | |
| char* | user : login to connect to the smtp server | |
| char* | passw : password to connect to the smtp server | |
| char* | smtp_server : smtp server | |
| uint16_t | port : smtp server port |
Definition at line 1741 of file WaspGPRS.cpp.
References AT_SMTP_SEND, configureGPRS(), delay(), millis(), PORT_USED, printByte(), printString(), serialAvailable(), serialFlush(), setEmailDestination(), setEmailParams(), setEmailPwd(), setEmailSubject(), setFlowControl(), and waitForData().
01742 { 01743 uint8_t counter=0; 01744 char command[30]; 01745 long previous=0; 01746 uint8_t answer=0; 01747 01748 if(!setFlowControl()) return 0; 01749 01750 if(!configureGPRS()) return 0; 01751 01752 if(!setEmailParams(smtp_server, port, from)) return 0; 01753 01754 if(!setEmailPwd(user, passw)) return 0; 01755 01756 if(!setEmailDestination(to)) return 0; 01757 01758 if(!setEmailSubject(subject)) return 0; 01759 01760 while( body[counter]!='\0' ) counter++; 01761 counter+=2; 01762 01763 serialFlush(PORT_USED); 01764 sprintf(command,"AT%s1,%u%c%c",AT_SMTP_SEND,counter,'\r','\n'); 01765 printString(command,PORT_USED); 01766 previous=millis(); 01767 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<10000) ); 01768 delay(10); 01769 answer=waitForData("CONNECT",20,0,0); 01770 if(answer!=1) return 0; 01771 01772 printString(body,PORT_USED); 01773 printByte('\r',PORT_USED); 01774 printByte('\n',PORT_USED); 01775 01776 previous=millis(); 01777 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<10000) ); 01778 delay(10); 01779 answer=waitForData("OK",20,0,0); 01780 if(answer!=1) return 0; 01781 01782 01783 return 1; 01784 01785 }

| uint8_t WaspGPRS::readMail | ( | char * | user, | |
| char * | passw, | |||
| char * | pop3_server, | |||
| uint16_t | port | |||
| ) |
It reads an email from the pop3 server.
| char* | user : login to connect to the smtp server | |
| char* | passw : password to connect to the smtp server | |
| char* | pop3_server : pop3 server | |
| uint16_t | port : pop3 server port |
Definition at line 1793 of file WaspGPRS.cpp.
References AT_POP3_LIST, AT_POP3_PARAM, AT_POP3_READ, body, configureGPRS(), delay(), emailAddress, GPRS_MAX_DATA, MAX_SIZE_POP3, millis(), PORT_USED, printByte(), printString(), serialAvailable(), serialFlush(), serialRead(), setFlowControl(), subject, and waitForData().
01794 { 01795 char command[70]; 01796 long previous=0; 01797 uint8_t answer=0; 01798 char aux='"'; 01799 uint16_t index=0; 01800 uint16_t i=0; 01801 uint8_t end=0; 01802 char* aux2; 01803 uint8_t j=0; 01804 01805 if(!setFlowControl()) return 0; 01806 01807 if(!configureGPRS()) return 0; 01808 01809 // Connect to POP3 Server 01810 sprintf(command,"AT%s%c%s%c,%u,%c%s%c,%c%s%c%c%c",AT_POP3_PARAM,aux,pop3_server,aux,port,aux,user,aux,aux,passw,aux,'\r','\n'); 01811 printString(command,PORT_USED); 01812 previous=millis(); 01813 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<10000) ); 01814 delay(10); 01815 answer=waitForData("OK",20,0,0); 01816 if(answer!=1) return 0; 01817 01818 01819 // Get the index 01820 printString(AT_POP3_LIST,PORT_USED); 01821 printByte('\r',PORT_USED); 01822 printByte('\n',PORT_USED); 01823 previous=millis(); 01824 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<10000) ); 01825 delay(10); 01826 answer=waitForData("+KPOPLIST:",20,0,0); 01827 if(answer!=1) return 0; 01828 i=0; 01829 while( serialRead(PORT_USED)!=':' ); 01830 serialRead(PORT_USED); 01831 index=serialRead(PORT_USED); 01832 serialFlush(PORT_USED); 01833 01834 // Read the email 01835 printString(AT_POP3_READ,PORT_USED); 01836 printByte(index,PORT_USED); 01837 printByte('\r',PORT_USED); 01838 printByte('\n',PORT_USED); 01839 previous=millis(); 01840 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<10000) ); 01841 01842 aux2 = (char*) calloc(MAX_SIZE_POP3,sizeof(char)); 01843 if( aux2==NULL ) return 0; 01844 01845 previous=millis(); 01846 i=0; 01847 while( millis()-previous<5000 ) 01848 { 01849 while( serialAvailable(PORT_USED) && i<MAX_SIZE_POP3 ) 01850 { 01851 aux2[i]=serialRead(PORT_USED); 01852 i++; 01853 previous=millis(); 01854 } 01855 } 01856 if( i>=MAX_SIZE_POP3 ) aux2[i-1]='\0'; 01857 else aux2[i]='\0'; 01858 01859 01860 i=0; 01861 j=0; 01862 i=waitForData(aux2,"Return-path: <"); 01863 01864 emailAddress[j]=aux2[i]; 01865 while( emailAddress[j]!='>' && i!=0 ) 01866 { 01867 i++; 01868 j++; 01869 emailAddress[j]=aux2[i]; 01870 if(j>=30) break; 01871 } 01872 emailAddress[j]='\0'; 01873 01874 01875 i=0; 01876 j=0; 01877 i=waitForData(aux2,"ubject: "); 01878 01879 subject[j]=aux2[i]; 01880 while( subject[j]!='\r' && i!=0 ) 01881 { 01882 i++; 01883 j++; 01884 subject[j]=aux2[i]; 01885 if(j>=30) break; 01886 } 01887 subject[j]='\0'; 01888 i=0; 01889 j=0; 01890 01891 i=waitForData(aux2,"*/*"); 01892 while( j<=GPRS_MAX_DATA && !end && i!=0 ) 01893 { 01894 body[j]=aux2[i]; 01895 if( body[j]=='*' ) 01896 { 01897 j++; 01898 i++; 01899 body[j]=aux2[i]; 01900 if( body[j]=='/' ) 01901 { 01902 j++; 01903 i++; 01904 body[j]=aux2[i]; 01905 if( body[j]=='*' ) 01906 { 01907 j++; 01908 i++; 01909 body[j]='\0'; 01910 end=1; 01911 } 01912 } 01913 } 01914 j++; 01915 i++; 01916 } 01917 body[j-1]='\0'; 01918 i=0; 01919 01920 free(aux2); 01921 aux2=NULL; 01922 return 1; 01923 }

| uint8_t WaspGPRS::uploadFile | ( | char * | file, | |
| char * | path, | |||
| char * | user, | |||
| char * | passw, | |||
| char * | ftp_server, | |||
| uint8_t | ftp_port | |||
| ) |
It uploads a file to a FTP server.
| char* | file : file to upload (the name that will have in the FTP server and the name of the file in the SD card) | |
| char* | path : path in the SD card where file is stored | |
| char* | user : login to connect to the ftp server | |
| char* | passw : password to connect to the ftp server | |
| char* | ftp_server : ftp server | |
| uint8_t | ftp_port : ftp server port |
Definition at line 1932 of file WaspGPRS.cpp.
References AT_FTP_PARAM, configureGPRS(), delay(), millis(), PORT_USED, printString(), sendDataFTP(), serialAvailable(), serialRead(), setFlowControl(), and waitForData().
01933 { 01934 char command[70]; 01935 long previous=0; 01936 uint8_t answer=0; 01937 char aux='"'; 01938 uint16_t index=0; 01939 uint16_t i=0; 01940 uint8_t end=0; 01941 char* aux2; 01942 uint8_t j=0; 01943 uint8_t id=0; 01944 01945 if(!setFlowControl()) return 0; 01946 01947 if(!configureGPRS()) return 0; 01948 01949 // Connect to FTP Server 01950 sprintf(command,"AT%s,%c%s%c,%c%s%c,%c%s%c,%u,1%c%c",AT_FTP_PARAM,aux,ftp_server,aux,aux,user,aux,aux,passw,aux,ftp_port,'\r','\n'); 01951 printString(command,PORT_USED); 01952 previous=millis(); 01953 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<10000) ); 01954 delay(10); 01955 answer=waitForData("+KFTPCFG: ",20,0,0); 01956 if(answer!=1) return 0; 01957 01958 id=serialRead(PORT_USED); 01959 01960 if( !sendDataFTP(file, path,id) ) return 0; 01961 01962 return 1; 01963 }

| uint8_t WaspGPRS::downloadFile | ( | char * | file, | |
| char * | path, | |||
| char * | user, | |||
| char * | passw, | |||
| char * | ftp_server, | |||
| uint8_t | ftp_port | |||
| ) |
It downloads a file from a FTP server.
| char* | file : file to download (the file name in the FTP server) | |
| char* | path : path in the SD card where file is going to be stored (it may have a different name from the FTP server file) | |
| char* | user : login to connect to the ftp server | |
| char* | passw : password to connect to the ftp server | |
| char* | ftp_server : ftp server | |
| uint8_t | ftp_port : ftp server port |
Definition at line 1972 of file WaspGPRS.cpp.
References AT_FTP_PARAM, configureGPRS(), delay(), millis(), PORT_USED, printString(), readDataFTP(), serialAvailable(), serialRead(), setFlowControl(), and waitForData().
01973 { 01974 char command[70]; 01975 long previous=0; 01976 uint8_t answer=0; 01977 char aux='"'; 01978 uint16_t index=0; 01979 uint16_t i=0; 01980 uint8_t end=0; 01981 char* aux2; 01982 uint8_t j=0; 01983 uint8_t id=0; 01984 01985 if(!setFlowControl()) return 0; 01986 01987 if(!configureGPRS()) return 0; 01988 01989 // Connect to FTP Server 01990 sprintf(command,"AT%s,%c%s%c,%c%s%c,%c%s%c,%u,1%c%c",AT_FTP_PARAM,aux,ftp_server,aux,aux,user,aux,aux,passw,aux,ftp_port,'\r','\n'); 01991 printString(command,PORT_USED); 01992 previous=millis(); 01993 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<10000) ); 01994 delay(10); 01995 answer=waitForData("+KFTPCFG: ",20,0,0); 01996 if(answer!=1) return 0; 01997 01998 id=serialRead(PORT_USED); 01999 02000 if( !readDataFTP(file, path, id) ) return 0; 02001 02002 return 1; 02003 }

| uint8_t WaspGPRS::getCellInfo | ( | ) |
It gets info from the cell where the modules is connected.
It stores in 'RSSI' and 'cellID' variables the RSSI and the Cell ID
Definition at line 1643 of file WaspGPRS.cpp.
References AT_GPRS_CELLID, cellID, delay(), millis(), PORT_USED, printString(), RSSI, serialAvailable(), serialFlush(), and serialRead().
01644 { 01645 char command[30]; 01646 uint8_t byteIN[200]; 01647 long previous=millis(); 01648 uint8_t counter=0; 01649 uint8_t a,b,c=0; 01650 01651 serialFlush(PORT_USED); 01652 sprintf(command,"AT%s\r\n",AT_GPRS_CELLID); 01653 printString(command,PORT_USED); 01654 while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<3000) ); 01655 previous=millis(); 01656 a=0; 01657 while( (millis()-previous) < 2000 ) 01658 { 01659 while( serialAvailable(PORT_USED) && (millis()-previous) < 2000 && (a<200) ) 01660 { 01661 byteIN[a]=serialRead(PORT_USED); 01662 a++; 01663 } 01664 } 01665 a=0; 01666 while( counter < 5 ) 01667 { 01668 while( (byteIN[a]!=',') && (a<200) ) 01669 { 01670 a++; 01671 } 01672 a++; 01673 counter++; 01674 } 01675 if(a>=200) return 0; 01676 counter=0; 01677 while( (byteIN[a]!=',') && (a<200) ) 01678 { 01679 cellID[c]=byteIN[a]; 01680 a++; 01681 c++; 01682 } 01683 a++; 01684 while( (byteIN[a]!=',') && (a<200) ) 01685 { 01686 RSSI[b]=byteIN[a]; 01687 delay(10); 01688 b++; 01689 a++; 01690 } 01691 return 1; 01692 }

uint8_t WaspGPRS::not_ready [private] |
Variable : stores if the module is ready or not (1:not ready, 0:ready).
Definition at line 293 of file WaspGPRS.h.
Referenced by getIfReady(), and WaspGPRS().
char WaspGPRS::theCommand[100] [private] |
Variable : array for storing part of the data to send to the module.
Definition at line 298 of file WaspGPRS.h.
Referenced by sendATCommand(), and sendCommand().
char WaspGPRS::theEnd[10] [private] |
Variable : array for storing part of the data to send to the module.
Definition at line 303 of file WaspGPRS.h.
Referenced by sendCommand().
char WaspGPRS::received[100] [private] |
Variable : array for storing the data received from the module.
Definition at line 308 of file WaspGPRS.h.
Referenced by sendCommand(), and waitForData().
| int WaspGPRS::flag |
Variable : status flag, used to see if there was an error while communicating with the module.
Possible values are : GPRS_ERROR_POWER, GPRS_ERROR_CALL, GPRS_ERROR_HANG, GPRS_ERROR_SMS, GPRS_ERROR_PIN, GPRS_ERROR_CALLINFO, GPRS_ERROR_SMSINFO, GPRS_ERROR_CONF, GPRS_ERROR_PATTERN, GPRS_ERROR_TIMER, GPRS_ERROR_PROFILE, GPRS_ERROR_SOCKET, GPRS_ERROR_CHECK, GPRS_ERROR_CLOSE
Definition at line 462 of file WaspGPRS.h.
Referenced by checkGPRS(), closeSocket(), configureGPRS(), createSocket(), hangUp(), makeCall(), makeLostCall(), sendSMS(), setConnectionProfile(), setConnectionTimer(), setEmailDestination(), setEmailParams(), setEmailPwd(), setEmailSubject(), setFlowControl(), setInfoIncomingCall(), setInfoIncomingSMS(), setMode(), setPattern(), setPIN(), and setTextModeSMS().
| char WaspGPRS::tlfIN[15] |
Variable : last call or SMS received telephone number.
It stores telephone numbers with country code if it appears
Definition at line 468 of file WaspGPRS.h.
Referenced by readCall(), and readSMS().
| uint16_t WaspGPRS::_baudRate |
Variable : baud rate used to communicate with the GPRS module.
By default, it is 38400bps
Definition at line 474 of file WaspGPRS.h.
Referenced by begin(), and WaspGPRS().
| uint8_t WaspGPRS::_pwrMode |
Variable : power mode.
Possible values are: GPRS_ON, GPRS_SLEEP, GPRS_HIBERNATE
Definition at line 480 of file WaspGPRS.h.
Referenced by getMode(), setMode(), and WaspGPRS().
| uint8_t WaspGPRS::_uart |
Variable : UART used by the GPRS module.
GPRS module is connected to the UART1
Definition at line 486 of file WaspGPRS.h.
Referenced by begin(), close(), and WaspGPRS().
| char WaspGPRS::sms[100] |
Variable : last SMS text received.
It stores up to 100bytes from the last SMS received
Definition at line 492 of file WaspGPRS.h.
Referenced by readSMS().
| uint8_t WaspGPRS::socket_ID |
Variable : socket ID.
It stores the ID of the last socket opened
Definition at line 498 of file WaspGPRS.h.
Referenced by createSocket(), and readURL().
| char WaspGPRS::data_URL[100] |
Variable : data received when reading an URL.
It stores up to 100 bytes from an URL
Definition at line 504 of file WaspGPRS.h.
Referenced by readData().
| uint16_t WaspGPRS::data_read |
Variable : amount of data read from an URL or from a socket.
Definition at line 509 of file WaspGPRS.h.
Referenced by readData().
| char WaspGPRS::cellID[4] |
| char WaspGPRS::RSSI[2] |
| char WaspGPRS::answer_command[50] |
Variable : Array for storing the answer to the command sent.
Definition at line 524 of file WaspGPRS.h.
Referenced by sendCommand().
| char WaspGPRS::sms_index[4] |
Variable : Last sms received index.
Definition at line 529 of file WaspGPRS.h.
Referenced by readSMS().
| char WaspGPRS::emailAddress[31] |
Variable : Email address from the last email received.
Definition at line 534 of file WaspGPRS.h.
Referenced by readMail().
| char WaspGPRS::subject[31] |
Variable : Last email received subject.
Definition at line 539 of file WaspGPRS.h.
Referenced by readMail().
| char WaspGPRS::body[101] |
Variable : Last email received subject.
Definition at line 544 of file WaspGPRS.h.
Referenced by readMail().
1.5.6