a library to use GPRS like ethernet or wifi, which makes it possible to connect to the internet with your GPRS module

Dependencies:   BufferedSerial

Dependents:   ThinkSpeak_Test roam_v1 roam_v2 finalv3

Fork of GPRSInterface by wei zou

Embed: (wiki syntax)

« 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, 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_MS)
 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.
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 sock_send (int socket, const char *str, int len)
 send data to socket
int sock_recv (int socket, char *buf, int len)
 read data from socket
bool gethostbyname (const char *host, uint32_t *ip)
 convert the host to ip

Static Public Member Functions

static GPRS * getInstance ()
 get instance of GPRS class

Protected Member Functions

int readline (char *buf, int len, uint32_t timeout=DEFAULT_TIMEOUT_MS)
 Read a line.

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,
const char *  apn,
const char *  userName = NULL,
const char *  passWord = NULL 
)

Constructor.

Parameters:
txmbed pin to use for tx line of Serial interface
rxmbed pin to use for rx line of Serial interface
baudRateserial communicate baud rate
apnname of the gateway for GPRS to connect to the network
userNameapn's username, usually is NULL
passWordapn's password, usually is NULL

Definition at line 25 of file GPRSInterface.cpp.


Member Function Documentation

bool close ( int  socket ) [inherited]

Close a tcp connection.

Returns:
true if successful

Definition at line 176 of file GPRS.cpp.

bool connect ( int  socket,
Protocol  ptl,
const char *  host,
int  port,
int  timeout = DEFAULT_TIMEOUT_MS 
) [inherited]

Open a tcp/udp connection with the specified host on the specified port.

Parameters:
socketan endpoint of an inter-process communication flow of GPRS module,for SIM900 module, it is in [0,6]
ptlprotocol for socket, TCP/UDP can be choosen
hosthost (can be either an ip address or a name. If a name is provided, a dns request will be established)
portport
timeoutwait time (ms)
Returns:
true if successful

Definition at line 96 of file GPRS.cpp.

int connect (  )

Connect to the network and get IP address.

Returns:
0 on success, a negative number on failure

Definition at line 35 of file GPRSInterface.cpp.

int disconnect ( void   )

Disconnect with the network.

Returns:
0 on success, a negative number on failure

Definition at line 40 of file GPRSInterface.cpp.

bool gethostbyname ( const char *  host,
uint32_t *  ip 
) [inherited]

convert the host to ip

Parameters:
hosthost ip string, ex. 10.11.12.13
iplong int ip address, ex. 0x11223344
Returns:
true if successful

Definition at line 127 of file GPRS.cpp.

static GPRS* getInstance (  ) [static, inherited]

get instance of GPRS class

Definition at line 54 of file GPRS.h.

char * getIPAddress (  )

Get IP address.

Returns:
ip address

Definition at line 45 of file GPRSInterface.cpp.

int init (  )

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 146 of file GPRS.cpp.

bool join ( void   ) [inherited]

Connect the GPRS module to the network.

Returns:
true if connected, false otherwise

Definition at line 53 of file GPRS.cpp.

int readline ( char *  buf,
int  len,
uint32_t  timeout = DEFAULT_TIMEOUT_MS 
) [protected, inherited]

Read a line.

Parameters:
bufthe buffer to store a line
lensize of the buffer
timeoutwait time (ms)
Returns:
-1 if timeout, length of the line if otherwise

Definition at line 19 of file modem.cpp.

void reset (  ) [inherited]

Reset the GPRS module.

Definition at line 171 of file GPRS.cpp.

bool setProtocol ( int  socket,
Protocol  p 
) [inherited]

Set the protocol (UDP or TCP)

Parameters:
socketsocket
pprotocol
Returns:
true if successful

Definition at line 87 of file GPRS.cpp.

int sock_recv ( int  socket,
char *  buf,
int  len 
) [inherited]

read data from socket

Parameters:
socketsocket
bufbuffer that will store the data read from socket
lenstring length need to read from socket
Returns:
bytes that actually read

Definition at line 239 of file GPRS.cpp.

int sock_send ( int  socket,
const char *  str,
int  len 
) [inherited]

send data to socket

Parameters:
socketsocket
strstring to be sent
lenstring length
Returns:
return bytes that actually been send

Definition at line 187 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:
socketsocket
wait_timetime of waiting
int wait_writeable ( int  socket,
int  req_size 
) [inherited]

wait a few time to check if GPRS module is writeable or not

Parameters:
socketsocket
wait_timetime of waiting