WiFly Library : GET Problem

I’m using the WiFly library to connect my WiFly shield to our WLAN and it’s very successful.

However, attempting to connect to a local server using the library’s Client object flags up some issues. The following method attempts to connect to a Servlet that outputs a Unix timestamp that the method should read back in (along with the HTTP headers that we aren’t too interested in). The form we are expecting is T=xxx.

	Client client = Client("***", 8080);
	if(client.connect())
	{
		client.print("GET /Mordor/clock HTTP/1.0\r\n");
		delay(100);
		while(client.available())
		{
			char in = client.read();
			Serial.print(in);
		}
		Serial.println();
	}
        client.stop();
}
[CLOCK] Synchronising clock
[CLOCK] Connected...
y1 GMT
Connection%%y%%%yuZmBu
[CLOCK] Synchronising clock
[CLOCK] Connected...
=10
[CLOCK] Synchronising clock
[CLOCK] Connected...
=10
[CLOCK] Synchronising clock
[CLOCK] Connected...
=10

Any suggestions as to where we are going wrong? We have an Ethernet version running very similar code which is fine.

Bailz:
client.print(“GET /Mordor/clock HTTP/1.0\r\n”);

You are only sending one carriage and line feed “\r\n” to the http server (assuming since the port is 8080 as opposed to 80, and your using http protocol) so the server is waiting for the next header line which it never gets, so it doesnt respond (also assuming this is a standard webserver which waits for an empty line, and not a custom one that is expecting only one line) So just modify that line to:

client.print("GET /Mordor/clock HTTP/1.0\r\n\r\n");

Conker:

Bailz:
client.print(“GET /Mordor/clock HTTP/1.0\r\n”);

You are only sending one carriage and line feed “\r\n” to the http server (assuming since the port is 8080 as opposed to 80, and your using http protocol) so the server is waiting for the next header line which it never gets, so it doesnt respond (also assuming this is a standard webserver which waits for an empty line, and not a custom one that is expecting only one line) So just modify that line to:

client.print("GET /Mordor/clock HTTP/1.0\r\n\r\n");

Hi Conker, thanks for your reply.

I can see why that extra line is important (it’s a Tomcat server btw hence the port number). However, the server was actually responding to the singular return.

I’ve updated the code as follows:

Serial.println("[CLOCK] Synchronising clock");
	Client client = Client("dtp-126.sncs.abdn.ac.uk", 8080);
	if(client.connect())
	{
		Serial.println("[CLOCK] Connected...");
		client.println("GET /Mordor/clock HTTP/1.0");
		client.println();
		delay(100);
		while(client.available())
		{
			char in = client.read();
			Serial.print(in);
		}
		Serial.println();
	}
	else
	{
		Serial.println("[CLOCK] Failed to connect");
	}
	client.flush();
	client.stop();

And getting the response…

[CLOCK] Synchronising clock
[CLOCK] Connected...
tim%%%yuyyyABS*TTP/1.1 200 OK
Server: Apache-Coyote/1.1
Date: Mon, 16 Aug 2010 10:39:26 GMT
Connection: close

timestamp=[B@5aebd9

[CLOCK] Synchronising clock
[CLOCK] Connected...
=0:H9:26 GMT

Still not a great response…

Did you have any success with tracking down this issue further?

–Philip;