Web Server example why is it not working for me?

Thanks to dannable for his link, but the web server example from the arduino website still will not work for me (I am using an arduino uno and the GSM/GPRS shield). If anyone has tried the web server example from the arduino website please let me know (particularly if a giffgaff sim card was used). Alternatively, if anyone has a different program for the same job (or similar) which I could try, please could I have it. The code in the example I used is below. Please excuse the ignorance, I am very much a beginner.

/*
GSM Web Server

A simple web server that shows the value of the analog input pins.
using a GSM shield.

Circuit:

  • GSM shield attached
  • Analog inputs attached to pins A0 through A5 (optional)

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
GPRS gprs;
GSM gsmAccess; // include a 'true' parameter for debug enabled
GSMServer server(80); // port 80 (http default)

// timeout
const unsigned long TIMEOUT = 10*1000;

void setup()
{
// initialize serial communications
Serial.begin(9600);

// connection state
boolean notConnected = true;

// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected)
{
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}

Serial.println("Connected to GPRS network");

// start server
server.begin();

//Get IP.
IPAddress LocalIP = gprs.getIPAddress();
Serial.println("Server IP address=");
Serial.println(LocalIP);
}

void loop() {

// listen for incoming clients
GSM3MobileClientService client = server.available();

if (client)
{
while (client.connected())
{
if (client.available())
{
Serial.println("Receiving request!");
bool sendResponse = false;
while(char c=client.read()) {
if (c == '\n') sendResponse = true;
}

// if you've gotten to the end of the line (received a newline
// character)
if (sendResponse)
{
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(analogRead(analogChannel));
client.println("
");
}
client.println("");
//necessary delay
delay(1000);
client.stop();
}
}
}
}
}

If you are using the examples provided with the IDE then they are for the official Arduino GSM/GPRS shield, and as distributed use pins 2 & 3 to communicate with the shield.

I don't know which shield you have but the inexpensive SIM900s use pins 7 & 8 (or 0 & 1) to communicate.

Right, thanks for that. I am using a relatively inexpensive sim900, but if the sms examples worked surely this should as well??? Maybe not, if so how do I change the pin numbers? Are they in some library somewhere or what? Thanks very much for the expert advice.

To be honest I have no idea why the examples would would for sending an SMS message.

The pin definitions are held in GSM3SoftSerial.cpp

Unfortunately I don't have a SIM900 based shield on hand this weekend to do any testing!

Could you post a link to the shield you have?

It is the shield with screw-on antenna rather than the on-board variety. I bought it from eBay see the below link.

http://www.ebay.co.uk/itm/GSM-GPRS-Shield-For-Arduino-/231142949055?_trksid=p2054897.l4275

Thanks for your professional help, I really am thick as two short planks.

Hardly professional!

I've not come across that variant before, and looking at the schematic you can select either D0 & D1 or D2 & D3 for communication, which is probably why the SendSMS sketch works.

Right, brief update. I've tried the sketch on the official shield and it shouldn't come as any surprise that it seems to work. I get as far as getting an IP address which will do for me, it proves it's connected. But that's my lot for this evening. I'm using O2 PAYG, I believe GiffGaff use their network.

How far do you get?

Right, so please could you tell me how one would select a pin to try? Is it something to do with what you told me about the pin definitions being held in GSM3SoftSerial.cpp? (and how do you alter the library?)

Sorry for the ignorance, thanks for the expert advice.

This evening I tried jumpering the Uno from last night to a Seeed SIM900 shield but I was unable to get a signal lock, I'll try again tomorrow.

Do you get either of the two connection messages? "Not connected" or "Connected to GPRS network"?

I'm assuming that the phone companies allow you to use a mobile device as a web server? I think I might have heard something to the contrary some time ago.

Many Thanks dannable, you have found the problem - giffgaff don't allow the sim to be used as a web server.

As you seem to know everything there is to know, do you have any suggestions as to what sim I could get instead? (possibly a data sim?)
Alternatively, do you have any idea what other method I could use to keep a webpage updated with sensor values?

Thanks for all your help.

I'd be tempted to use Google to see if any service providers will permit that.

Why can't you just upload the data to a web site, use a little script to insert it into a database and another script to display the data to the user? You could use the GET statement and include the parameters in the URL?

Right, will one of the sim cards on the below link work?
http://scancom.co.uk/m2m-data/data-sims-for-smart-machines.html

And then how would I commence with the first step of what you say - upload the data to a web site?
Maybe I should crowd source the code?

I really cannot thank you enough for your excellent advice!

First of all if you don't already have one you need to find yourself a hosting site. One that has mySql and supports a scripting language you know (or want to learn).

Then go to

http://www.seeedstudio.com/wiki/GPRS_Shield_V1.0 (a similar shield to the one you are using)

and do a search for

///SubmitHttpRequest()

This is a basic method of making an HTTP request - requesting a web page. Build up your URL to include any parameters you want to pass to your site (www.mysite.co.uk/whereami.php?left=7&right=2). Write a script that will parse the incoming data and write it to your mySql database. And finally write another script that reads your database and displays the data in a pretty fashion!

Just about any sim card will do for this, if you can connect to the internet it will do. (Usual caveats apply!)

OK - it all sounds rather gobeldygookish to me, but I have gone onto the seeedstudio website and found the code for making a HTTP request. I have taken out the parts to do with calls and text messages, do I leave in the pachube bit or omit this as well?

The other site you gave me doesn't seem to want to work, it keeps timing out.

Please could you explain further about building up my URL - does this mean direct the arduino to the right part of the database or what?

I am also not over confident with parsing data - I assume that this will be something on my database which takes the information from the arduino and turns it into something which the computer understands - or maybe not?

Or forget the above and give me the first simple step to take.

Sorry I am so thick, I thank the brain-box for his wonderful input!

You just want the section of code in the function SubmitHttpRequest(), from { to }.

The second link wasn't really a link, just an example of passing parameters. You would start with your basic URL in a string (not String) and then concatenate (strcat) your parameters on to it.

Script languages like Perl and php will parse the data for you quite easily and write it away to your database. However, that side of the process is outside of the scope of this forum really, so if you aren't confident with those parts take a look at www.w3schools.com - it's a reasonably good introduction to scripting languages, SQL, etc.

That's just the way I would do it.

Just wondering, is it possible to have the database on my computer, rather than on the cloud through a provider?

That's a bit beyond the remit for an Arduino forum but I suspect that you'll need a static IP address and that you're unlikely to get one as a domestic user.

Discussions about running a "server" inside a GSM system have been posted before, but I haven't seen a working solution. The posted example server code appears to possibly to not have been tried in the real world within an actual GSM system. Client code may well work, but running a server is a different situation.