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