# Wifly Shield Not Connecting

I recently asked a question about the juniper WiFi shield, and am now working with wifly from spark fun. I've been using an updated version of their experimental library, and have been attempting to set up a webserver. Unfortunately, when I attempt to connect through a web browser, I get an error saying that the page sent no data. Here's my code:

#include <SPI.h>
#include <WiFly.h>

WiFlyServer s(80);
boolean current_line_is_blank=true;
void setup() {
Serial.begin(9600);
WiFly.begin();
Serial.println("Connection Failed.");
} else {
Serial.println("Connection Succesful!");
Serial.println(WiFly.ip());
Serial.println("Receving Client Input...");
s.begin();

}
}
void loop() {
WiFlyClient c = s.available();
if(c) {
current_line_is_blank=true;
while(c.connected()) {
Serial.println("Client Connected.");
if(c.available()) {
Serial.println("Client Available for data.");
Serial.println(tmp);
if(tmp == '\n' && current_line_is_blank) {
Serial.println("Sent OK Response.");
c.println("HTTP/1.1 200 OK");
c.println("Content-Type: text/html");
c.println();
c.print("WiFly Webserver Running!");
c.println("<br />");
break;
}
if (tmp == '\n') {
// we're starting a new line
current_line_is_blank = true;
} else if (tmp != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
}
delay(2000);
c.stop();
}


I am using Arduino Uno, and the serial monitor looks like this:

Connection Succesful!
10.100.1.173
Receving Client Input...


Is there anything obviously wrong with my code?

EDIT: I now have a new shield, but I'm still working with the same problem. Is it a malfunction in the hardware? I just can't figure this out!

• I just looked up an example and your method appears correct so I have deleted my answer. I don't see any other issues though it may help to look at the example more closely. – DaemonMaker Dec 20 '12 at 4:27

I've never programmed an Arduino or used this module, but from a quick look at the code and its output, it looks like only setup() is getting run, while loop() is the source of the problem (sort of expected). Try adding a println statement before checking for c to see if the loop gets run at all.

...
void loop() {
WiFlyClient c = s.available();
Serial.println("Looping...");
if(c) {
...


Assuming the above checks out, my hunch is that the problem is in the first line of the loop:

...
WiFlyClient c = s.available();
...


Why are you initializing the client, c, with the server's availability? This seems to imply that the if statement is essentially testing for the server's availability, instead of the client's availability. What's more, you then also run c.connected(), c.available(), and c.println(), which is somewhat at odds with c's initialization.

Try checking what you need to initialize c with and then probably switch the if statement as follows:

...
if(c.available()) {
...


Just my 2c.

• The loop() and setup() functions are special in the Arduino IDE. It always executes setup() and then loop(). Think of it as main(). – Joe Baker Dec 22 '12 at 20:56
• Yeah, I assumed so. I was just implying that whereas setup() was executing correctly, loop() wasn't. – fgb Dec 26 '12 at 6:38
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.17922452092170715, "perplexity": 3650.93281303366}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-29/segments/1593655886706.29/warc/CC-MAIN-20200704201650-20200704231650-00196.warc.gz"}