After sending a simple HTTP GET request to the server, the shield will print
any response from that server back to the serial monitor.
Using the Library: GPRS
As with SMS, an entirely different class is defined for GPRS capabilities.
These functions are preceded by a
gprs.
object identifier. (This allows us
to re-use virtual functions like
and
available
.)
Opening or Closing GPRS
Before you can use any GPRS functionality, you have to “turn it on” by
calling
gprs.open()
. This function doesn’t have any parameters, and
simply returns an error code integer.
If
open()
returns a positive number, the shield successfully connected to
GPRS. If it returns
2
, the shield failed to connect. If it returns
1
it timed
out. This function can take a while to return successfully – upwards of 30
seconds if the module is just getting warmed up, so be patient.
If you ever need to turn GPRS off, use the
gprs.close()
function. This
function has the opposite effect from
open()
and returns a similar set of
error codes.
Local and Remote IP Address Lookup
If you need to find your IP address,
gprs.localIP()
should meet your
needs. This function returns a variable of type
IPAddress
, already defined
in the Arduino core. Here’s an example usage:
IPAddress
myIPAddress;
myIPAddress
= gprs.localIP();
Serial.print("My
IP
address
is:
");
Serial.println(myIPAddress);
Given a domain name, the MG2639 supports DNS IP lookup with the
hostByName(const
char
*
domain,
IPAddress
*
ipRet)
function. Unlike
localIP()
, this function doesn’t return an IP address by value – instead it’ll
return the requested IP by reference. For example, if you want to look up
the IP address of sparkfun.com:
Page 16 of 22