user24330: Currently trying to implement a lightweight webserver using the WiFly shield and an Arduino UNO, this is the code I have so far:
#include <SPI.h> 
#include <WiFly.h>
WiFlyServer server(80);

/* Function defs */
void cmd(void)  { SpiSerial.print("$$$"); }
void dhcp(void) { SpiSerial.println("SET IP DHCP 0"); }
void pass(void) { SpiSerial.println("SET WLAN PHRASE 22222222"); }
void ssid(void) { SpiSerial.println("JOIN BTHOMEHUB"); }
void port(void) { SpiSerial.println("SET IP LOCAL 80"); }
void ip(void)   { SpiSerial.println("SET IP ADDRESS 192.168.1.123"); }
void tcp(void)  { SpiSerial.println("SET IP PROTOCOL 2"); }
void boot(void) { SpiSerial.println("REBOOT"); }

/* Pointer to a handler function */
typedef void (*Handler)(void);
Handler table[8] = { cmd, dhcp, pass, ssid, port, ip, tcp, boot };

void setup() {
  server.begin();
  Serial.begin(9600);
  SpiSerial.begin();

  for(short x = 0; x < 7; x++) {
    table[x]();
    delay(100);
  }
}

void loop() {
  WiFlyClient client = server.available();

  if(client){
    while(client.connected()) {
      if(client.available()) {
        client.println("<HTML><BODY><H1>Hi</H1><P>This is text.</P></BODY></HTML>");
      }
    }
    delay(100);
    client.flush();
    client.stop();
  }
}

This compiles well, but when hitting 192.168.1.123 in my web browser I get an ever-increasing output like: 
*HELLO*<
<
<
<
<
<
<
<
<
<
<
< (cont.)

Definitely not the expected html. I have been playing with this code for hours now and this is the most positive output I can get. If I do a Serial.write(client.read()) within if(client.available()) { I am able to print all the request information to the serial monitor, it just seems I am perhaps sending the data in an incorrect format? Any suggestions? Cheers
Edit
I have updated the codebase to include the http headers,
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println("");
client.println("<!DOCTYPE html>");
client.println("<HTML><BODY><H1>Hi.....

now I get I different (similar) output, seems like it is printing the first character of each new line
*HELLO*H
C
C

<
<
H
C
C


user11763: Your browser sent a HTTP GET request. You need to send a HTTP response in kind, in accordance with the protocol, for your browser to correctly interpret the data. Something like this should do:
  #define TIMEOUT 100
  char response[] = "<HTML><BODY><H1>Hi</H1><P>This is text.</P></BODY></HTML>";
  unsigned long lastRead;
  ...

  while (client.connected()){
    if (client.available()){
      lastRead = millis();
      while (millis() - lastRead < TIMEOUT){
        while (client.available()){
          Serial.write(client.read());
          lastRead = millis();
        }
      }
      client.println("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: closed\r\n\r\n");
      client.print(response);
      break;
    }
  }
  delay(1000);
  client.stop();

EDIT:
It turns out that the Wifly shield sends a response status as well as "HELLO" by default. You have to disable that with a few commands:
set comm remote 0
set comm open 0
set comm close 0

This will ensure that "HELLO" isnt sent each time a client connection is made, though I'm not sure if this affects the default HTTP/0.9 200 OK response status that is always sent. You can try the sketch above with and without the response header to see what you get.

24330: <p>Currently trying to implement a lightweight webserver using the WiFly shield and an Arduino UNO, this is the code I have so far:</p>

<pre><code>#include &lt;SPI.h&gt; 
#include &lt;WiFly.h&gt;
WiFlyServer server(80);

/* Function defs */
void cmd(void)  { SpiSerial.print("$$$"); }
void dhcp(void) { SpiSerial.println("SET IP DHCP 0"); }
void pass(void) { SpiSerial.println("SET WLAN PHRASE 22222222"); }
void ssid(void) { SpiSerial.println("JOIN BTHOMEHUB"); }
void port(void) { SpiSerial.println("SET IP LOCAL 80"); }
void ip(void)   { SpiSerial.println("SET IP ADDRESS 192.168.1.123"); }
void tcp(void)  { SpiSerial.println("SET IP PROTOCOL 2"); }
void boot(void) { SpiSerial.println("REBOOT"); }

/* Pointer to a handler function */
typedef void (*Handler)(void);
Handler table[8] = { cmd, dhcp, pass, ssid, port, ip, tcp, boot };

void setup() {
  server.begin();
  Serial.begin(9600);
  SpiSerial.begin();

  for(short x = 0; x &lt; 7; x++) {
    table[x]();
    delay(100);
  }
}

void loop() {
  WiFlyClient client = server.available();

  if(client){
    while(client.connected()) {
      if(client.available()) {
        client.println("&lt;HTML&gt;&lt;BODY&gt;&lt;H1&gt;Hi&lt;/H1&gt;&lt;P&gt;This is text.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;");
      }
    }
    delay(100);
    client.flush();
    client.stop();
  }
}
</code></pre>

<p>This compiles well, but when hitting <code>192.168.1.123</code> in my web browser I get an ever-increasing output like: </p>

<pre><code>*HELLO*&lt;
&lt;
&lt;
&lt;
&lt;
&lt;
&lt;
&lt;
&lt;
&lt;
&lt;
&lt; (cont.)
</code></pre>

<p>Definitely not the expected html. I have been playing with this code for hours now and this is the most positive output I can get. If I do a <code>Serial.write(client.read())</code> within <code>if(client.available()) {</code> I am able to print all the request information to the serial monitor, it just seems I am perhaps sending the data in an incorrect format? Any suggestions? Cheers</p>

<p><strong>Edit</strong></p>

<p>I have updated the codebase to include the http headers,</p>

<pre><code>client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println("");
client.println("&lt;!DOCTYPE html&gt;");
client.println("&lt;HTML&gt;&lt;BODY&gt;&lt;H1&gt;Hi.....
</code></pre>

<p>now I get I different (similar) output, seems like it is printing the first character of each new line</p>

<pre><code>*HELLO*H
C
C

&lt;
&lt;
H
C
C
</code></pre>
 11763: <p>Your browser sent a HTTP GET request. You need to send a HTTP response in kind, in accordance with the protocol, for your browser to correctly interpret the data. Something like this should do:</p>

<pre><code>  #define TIMEOUT 100
  char response[] = "&lt;HTML&gt;&lt;BODY&gt;&lt;H1&gt;Hi&lt;/H1&gt;&lt;P&gt;This is text.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;";
  unsigned long lastRead;
  ...

  while (client.connected()){
    if (client.available()){
      lastRead = millis();
      while (millis() - lastRead &lt; TIMEOUT){
        while (client.available()){
          Serial.write(client.read());
          lastRead = millis();
        }
      }
      client.println("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: closed\r\n\r\n");
      client.print(response);
      break;
    }
  }
  delay(1000);
  client.stop();
</code></pre>

<p>EDIT:</p>

<p>It turns out that the Wifly shield sends a response status as well as "HELLO" by default. You have to disable that with a few commands:</p>

<pre><code>set comm remote 0
set comm open 0
set comm close 0
</code></pre>

<p>This will ensure that "<em>HELLO</em>" isnt sent each time a client connection is made, though I'm not sure if this affects the default <code>HTTP/0.9 200 OK</code> response status that is always sent. You can try the sketch above with and without the response header to see what you get.</p>
