Arduino Uno, GSM module, TCP/IP

I am working on a project which requires the Arduino board to send data (like lat,long,time etc.) to a web server. After a lot of searching, I've come to know that TCP/IP is the way to go which is how data packets will be sent to a specific ip address. But I have no idea how to go about implementing it. Lets assume that the server side programming has already been handled. Please suggest me the ways to implement this communication briefly, the library to be used and also suggest further readings.

Hardware I'll be using:
-Arduino Uno
-GSM module (SIM900A)

Thank you!

Example of sketch i used to test a GSM modem (Arduino GSM Shield 2) posting a random string to an API every 1.5 secs using the core GSM libaray, not sure this will work with your SIM900A modem, but should give you some pointers.

This sketch is a combination of an example i found on the internet and the examples in the Arduino libary, sorry i cannot recall where i located the original code.

Please share you work if you improve this sketch so others can benefit.

Good luck with your project.

Web client

This sketch connects to a website through a GSM shield. Specifically,
this example downloads the URL "" and
prints it to the Serial monitor.


  • GSM shield attached to an Arduino
  • SIM card with a data plan

created 8 Mar 2012
by Tom Igoe


// libraries
#include <GSM.h>

// PIN Number
#define PINNUMBER ""

// APN data
#define GPRS_APN "GPRS_APN" // replace your GPRS APN
#define GPRS_LOGIN "login" // replace with your GPRS login
#define GPRS_PASSWORD "password" // replace with your GPRS password

// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess(false);

char server[] = "{your web server domain}"; // Example:

unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 1500L; // delay between updates, in milliseconds

// variable for save response obtained
String inData;

// Used to post a random string
const int len = 10;
char tokens[] = {'a','b','c','d','e','f','g','h','i','j','k'};
const byte keyLength = sizeof(tokens) / sizeof(tokens[0]);
char key[len+1]; //allow 1 extra for the NULL

void setup()
// initialize serial communications and wait for port to open:

Serial.println("Starting Arduino web client.");

// connection state
boolean notConnected = true;

// After starting the modem with GSM.begin()
// attach the shield to the GPRS network with the APN, login and password
while (notConnected)
Serial.println("Attempting connection...");

// Check GSM ready
if (gsmAccess.begin(PINNUMBER) == GSM_READY)

// Initialise GPRS
Serial.println("Connection established...");
notConnected = false;
notConnected = false;
Serial.println("Not connected");

void loop()
while (client.available())
char thisChar =;

if (thisChar == '\n')
inData = "";
inData += thisChar;

// if ten seconds have passed since your last connection,
// then connect again and send data:
if (millis() - lastConnectionTime > postingInterval) {

// this method makes a HTTP connection to the server:
void httpRequest()


// if there's a successful connection:
if (client.connect(server, 80))

for (int n = 0; n < len ; n++)
key[n] = tokens[random(0, keyLength)];
key[n + 1] = '\0';

// String to post to web.api
String data = "=" + (String)key;

client.println("POST http://{your web server api url} HTTP/1.0");

// add a header indicating you have content-data to send. If you set this too low, the server won't see it. If it is too high, the server may wait, or report an error.
client.print("Content-Type: application/x-www-form-urlencoded \n");
client.print("content-length: ");

// tell the server you are done with the header.

// send the posted data.

// note the time that the connection was made:
lastConnectionTime = millis();
else {
// if you couldn't make a connection:
Serial.println("connection failed");