Hardware Reference
In-Depth Information
Then, to initiate a connection, you must use attachGPRS() :
grps .attachGPRS(APN, user, password);
This function takes three parameters, all three are char arrays. The APN param-
eter is the Access Point Name, the name of the connection point between the GPRS
network and the Internet. Each GPRS network should have one; check with your
SIM card provider for more information. The user and password parameters are
optional username and password details that are sometimes required to connect
to an APN. Again, the documentation that comes with your SIM card should
give more details. Not all providers use the username and password i elds; in
which case they may be left blank. This function returns the same constants as
begin() ; it returns GPRS_READY when the connection is established.
if (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)
Serial.println("Connected to GPRS network");
When the connection to the GPRS network is established, you need to create
either a server or a client. A server waits for incoming connections, and a cli-
ent connects to external servers. A server uses the GSMServer class, and a client
uses the GSMClient class. Both work almost the same as an Ethernet connection,
with a few differences; the GSM library attempts to be as compatible as possible
with the Ethernet library.
CROSS REFERENCE
The Ethernet library was presented in Chapter 9.
To create a client, that is to say a device that will connect to another Internet
device, use the GSMClient class:
GSMClient client;
When that is done, you must connect to a server. To connect to a server, use
connect() :
result = client .connect(ip, port);
The ip parameter is a 4-byte IP address, and port is an int specifying the
port that the sketch wants to connect to. This function returns a boolean : true
if the connection is established, and false if the connection fails.
When a connection has been made, you can send and receive data. Sending
data is done with print() , println() , and write() :
result = client.print(data);
result = client.println(data);
result = client.write(databyte);
Search WWH ::




Custom Search