Basic WiFly server returning unexpected output within web client Currently trying to implement a lightweight webserver using the WiFly shield and an Arduino UNO, this is the code I have so far:

#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();
  }
}


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

*HELLO*&lt;
&lt;
&lt;
&lt;
&lt;
&lt;
&lt;
&lt;
&lt;
&lt;
&lt;
&lt; (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("&lt;!DOCTYPE html&gt;");
client.println("&lt;HTML&gt;&lt;BODY&gt;&lt;H1&gt;Hi.....


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

*HELLO*H
C
C

&lt;
&lt;
H
C
C
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[] = "&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();


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.