works through pushing box to log data to google spreadsheet
Dependencies:
MBed_Adafruit-GPS-Library
SDFileSystem
mbed
Fork of
GPR_Interface
by DCS_TEAM
« Back to documentation index
GPRSInterface Class Reference
Interface using GPRS to connect to an IP-based network.
More...
#include <GPRSInterface.h >
Inherits GPRS .
Public Member Functions
GPRSInterface (PinName tx, PinName rx, int baudRate, const char *apn, const char *userName=NULL, const char *passWord=NULL)
Constructor.
int init ()
Initialize the interface(no connection at this point).
int connect ()
Connect to the network and get IP address.
int disconnect ()
Disconnect with the network.
char * getIPAddress ()
Get IP address.
bool join (void)
Connect the GPRS module to the network.
bool close (int socket)
Close a tcp connection.
bool connect (int socket, Protocol ptl, const char *host, int port, int timeout=DEFAULT_TIMEOUT)
Open a tcp/udp connection with the specified host on the specified port.
bool setProtocol (int socket, Protocol p)
Set the protocol (UDP or TCP)
void reset ()
Reset the GPRS module.
bool readable (void)
Check if GPRS module is readable or not.
int wait_readable (int socket, int wait_time)
Wait a few time to check if GPRS module is readable or not.
int wait_writeable (int socket, int req_size)
Wait a few time to check if GPRS module is writeable or not.
bool is_connected (int socket)
Check if a tcp link is active.
int send (int socket, const char *str, int len)
Send data to socket.
int recv (int socket, char *buf, int len)
Read data from socket.
bool gethostbyname (const char *host, uint32_t *ip)
Convert the host to ip.
bool storePhoneNumber (char *atCNumValue)
Parse the phone number from the AT command return value and store it.
bool preInit ()
Power on Modem .
Static Public Member Functions
static GPRS * getInstance ()
Get instance of GPRS class.
Protected Member Functions
char readByte (void)
read one byte from serialModem
int readBuffer (char *buffer, int count, unsigned int timeOut)
read from Modem module and save to buffer array
void cleanBuffer (char *buffer, int count)
clean Buffer
void sendCmd (const char *cmd)
send AT command to Modem module
void sendATTest (void)
send "AT" to Modem module
bool respCmp (const char *resp, unsigned int len, unsigned int timeout)
compare the response from GPRS module with a string
int waitForResp (const char *resp, unsigned int timeout, DataType type)
check Modem module response before time out
int sendCmdAndWaitForResp (const char *data, const char *resp, unsigned timeout, DataType type)
send AT command to GPRS module and wait for correct response
Detailed Description
Interface using GPRS to connect to an IP-based network.
Definition at line 32 of file GPRSInterface.h .
Constructor & Destructor Documentation
GPRSInterface
(
PinName
tx ,
PinName
rx ,
int
baudRate ,
const char *
apn ,
const char *
userName = NULL
,
const char *
passWord = NULL
)
Constructor.
Parameters:
tx mbed pin to use for tx line of Serial interface
rx mbed pin to use for rx line of Serial interface
baudRate serial communicate baud rate
apn name of the gateway for GPRS to connect to the network
userName apn's username, usually is NULL
passWord apn's password, usually is NULL
Definition at line 25 of file GPRSInterface.cpp .
Member Function Documentation
void cleanBuffer
(
char *
buffer ,
int
count
)
[protected, inherited]
clean Buffer
Parameters:
buffer buffer to clean
count number of bytes to clean
Definition at line 150 of file modem.cpp .
bool close
(
int
socket )
[inherited]
Close a tcp connection.
Returns: true if successful
Definition at line 300 of file GPRS.cpp .
Connect to the network and get IP address.
Returns: 0 on success, a negative number on failure
Definition at line 36 of file GPRSInterface.cpp .
bool connect
(
int
socket ,
Protocol
ptl ,
const char *
host ,
int
port ,
int
timeout = DEFAULT_TIMEOUT
)
[inherited]
Open a tcp/udp connection with the specified host on the specified port.
Parameters:
socket an endpoint of an inter-process communication flow of GPRS module,for SIM900 module, it is in [0,6]
ptl protocol for socket, TCP/UDP can be choosen
host host (can be either an ip address or a name. If a name is provided, a dns request will be established)
port port
timeout wait seconds till connected
Returns: true if successful
Definition at line 238 of file GPRS.cpp .
Disconnect with the network.
Returns: 0 on success, a negative number on failure
Reimplemented from GPRS .
Definition at line 41 of file GPRSInterface.cpp .
bool gethostbyname
(
const char *
host ,
uint32_t *
ip
)
[inherited]
Convert the host to ip.
Parameters:
host host ip string, ex. 10.11.12.13
ip long int ip address, ex. 0x11223344
Returns: true if successful
Definition at line 261 of file GPRS.cpp .
static GPRS * getInstance
(
)
[static, inherited]
Get instance of GPRS class.
Definition at line 57 of file GPRS.h .
Initialize the interface(no connection at this point).
Returns: 0 on success, a negative number on failure
Definition at line 30 of file GPRSInterface.cpp .
bool is_connected
(
int
socket )
[inherited]
Check if a tcp link is active.
Returns: true if successful
Definition at line 279 of file GPRS.cpp .
bool join
(
void
)
[inherited]
Connect the GPRS module to the network.
Returns: true if connected, false otherwise
Definition at line 114 of file GPRS.cpp .
bool preInit
(
)
[inherited]
bool readable
(
void
)
[inherited]
Check if GPRS module is readable or not.
Returns: true if readable
Reimplemented from Modem .
Definition at line 320 of file GPRS.cpp .
int readBuffer
(
char *
buffer ,
int
count ,
unsigned int
timeOut
)
[protected, inherited]
read from Modem module and save to buffer array
Parameters:
buffer buffer array to save what read from Modem module
count the maximal bytes number read from Modem module
timeOut time to wait for reading from Modem module
Returns: 0 on success -1 on error
Definition at line 130 of file modem.cpp .
char readByte
(
void
)
[protected, inherited]
read one byte from serialModem
Returns: one byte read from serialModem
Definition at line 120 of file modem.cpp .
int recv
(
int
socket ,
char *
buf ,
int
len
)
[inherited]
Read data from socket.
Parameters:
socket socket
buf buffer that will store the data read from socket
len string length need to read from socket
Returns: bytes that actually read
Definition at line 379 of file GPRS.cpp .
void reset
(
)
[inherited]
bool respCmp
(
const char *
resp ,
unsigned int
len ,
unsigned int
timeout
)
[protected, inherited]
compare the response from GPRS module with a string
Parameters:
resp buffer to be compared
len length that will be compared
timeout waiting seconds till timeout
Definition at line 192 of file modem.cpp .
int send
(
int
socket ,
const char *
str ,
int
len
)
[inherited]
Send data to socket.
Parameters:
socket socket
str string to be sent
len string length
Returns: return bytes that actually been send
Definition at line 358 of file GPRS.cpp .
void sendATTest
(
void
)
[protected, inherited]
void sendCmd
(
const char *
cmd )
[protected, inherited]
send AT command to Modem module
Parameters:
cmd command array which will be send to GPRS module
Definition at line 157 of file modem.cpp .
int sendCmdAndWaitForResp
(
const char *
data ,
const char *
resp ,
unsigned
timeout ,
DataType
type
)
[protected, inherited]
send AT command to GPRS module and wait for correct response
Parameters:
*cmd AT command which will be send to GPRS module
*resp correct response which GPRS module will return
*timeout waiting seconds till timeout
Returns: 0 on success -1 on error
Definition at line 246 of file modem.cpp .
bool setProtocol
(
int
socket ,
Protocol
p
)
[inherited]
Set the protocol (UDP or TCP)
Parameters:
Returns: true if successful
Definition at line 229 of file GPRS.cpp .
bool storePhoneNumber
(
char *
atCNumValue )
[inherited]
Parse the phone number from the AT command return value and store it.
Parameters:
atCNumValue the return value from the AT+CNUM AT Command
Returns: true if successful
Definition at line 418 of file GPRS.cpp .
int wait_readable
(
int
socket ,
int
wait_time
)
[inherited]
Wait a few time to check if GPRS module is readable or not.
Parameters:
socket socket
wait_time time of waiting
Definition at line 325 of file GPRS.cpp .
int wait_writeable
(
int
socket ,
int
req_size
)
[inherited]
Wait a few time to check if GPRS module is writeable or not.
Parameters:
socket socket
wait_time time of waiting
Definition at line 350 of file GPRS.cpp .
int waitForResp
(
const char *
resp ,
unsigned int
timeout ,
DataType
type
)
[protected, inherited]
check Modem module response before time out
Parameters:
*resp correct response which Modem module will return
*timeout waiting seconds till timeout
Returns: 0 on success -1 on error
Definition at line 215 of file modem.cpp .