WiFly arduino computer power switcher

Hi Guys.
Im having some trouble with my code for the WiFly (from sparkfun).

//LED Stuff
#define ledpin 4
#define resetpin 3
#define powerpin 2

//WiFi Stuff
#include "WiFly.h" // We use this for the preinstantiated SpiSerial object.


//boolean endOfCode = true;
char msg[128];
int letterCount = 0;

Server server(80);

void setup() {
  WiFly.begin();
  
  //Define LED pin Modes
  pinMode(powerpin, OUTPUT);
  pinMode(resetpin, OUTPUT);
  pinMode(ledpin, INPUT);
  
  //set initial values for leds as low
  
  digitalWrite(powerpin, HIGH);
  digitalWrite(resetpin, HIGH);
  
  if (!WiFly.join("ssid", "pw")) {
    while (1) {
      // Hang on failure.
    }
  }

  Serial.begin(9600);
  Serial.print("IP: ");
  Serial.println(WiFly.ip());
  
  server.begin();
}

void loop() {
  Client client = server.available();
  //the flag dataFlag give a notification of where the actual post
  //is once we flag it we can begin recording the message
  //so we can do stuff with it later on
  byte dataFlag = 0;
  byte msgIsolator = 0;;
  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;

    char c;
    while (client.connected()) {
         
      if (client.available()) {
        c = client.read();
        // if we've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so we can send a reply
        if (!client.available()) {

        } else if (c == '\n') {
          // we're starting a new line
          current_line_is_blank = true;
        } else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;

        }
        //if you want to see all data comming in and going out uncomment the line below
        Serial.print(c);
       
        }


        if ((c == '\n' && current_line_is_blank && !client.available())) {
          
          //As soon as the page has been refreshed the letter count is set to zero
          letterCount = 0;
          
          //Once the page has been refreshed we are no longer on the first run through
          //off the program so we set this to false


         
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("<head>");
          //client.println("<meta http-equiv=refresh content=5;url=http://192.168.1.109>");     
          client.println("</head>");
                          
          //This basically creates what the user will see on the site. So UI. A logo input and word list.
          client.println("<html>");
          client.println("<title>Gr0p3r WiFly Server</title>");
          client.println("<h1><center>");
          client.println("</center></h1>"); 
          client.println("Power LED State:");
          client.println(digitalRead(ledpin));
          client.println("<p>");
          client.println("<a href =\"192.168.1.109\">Turn on PC</a><p>");
          client.println("<a href =\"192.168.1.109\">Press PC off</a><P>");
          client.println("<a href =\"192.168.1.109\">Reset PC</a><P>");
          client.println("<a href =\"192.168.1.109\" >Hard Power Down</a><P>");
          client.println("</html>");
          client.stop();
          //break;
          
          
         
        }
        //break;

      }

    }
  }

ive pretty much taken an example project and butchered it.

I intend to have the arduino powered by the ATX 5v standby power, hook into the power LED +ive wire (dig Pin 4), the Power(pin 2) and reset (pin3) button’s +ive wire.

Taking the reset or power pins to ground will fire up or reset the PC. it will eventually use the LED as a check to see if it alread on to prevent accidental shutdowns.

the hardware sine should be fine, it the code im struggling with. The above code displays all the correct HTML code, but i want it to refresh. It doesnt. When i put the “client.stop();” line in, it doesnt refresh, with out that line, it just keeps printing the information under the last bit it printed over and over again.

all this project needs to do is display a simple webpage, with the current status of the pc (obtained from the led) and have 3 or 4 “links” that will pull the digital pins to ground.

gr0p3r:
i want it to refresh. It doesnt.

The following statement, which would usually trigger the refresh, has been commented out. Have you tried uncommenting it?

          //client.println("<meta http-equiv=refresh content=5;url=http://192.168.1.109>");

If it doesn’t work as-is, try putting double quotes around the values. Also, you only need to set the URL if you want the page to load a different page, which you probably don’t:

          client.println("<meta http-equiv=\"refresh\" content=\"5\">");

yes, i have tried both those suggestions. Its like it that line doesnt do anything at all, but it should (from what ive googled)

I'm curious why setup() contains debug information but loop() does not.

Ild be happy to add debug information to loop() if you think it will help get it to work. And if you can give some guidance on how i would to such a thing.

Ild be happy to add debug information to loop() if you think it will help get it to work. And if you can give some guidance on how i would to such a thing.

The code does something. You want it to do something. Or, you want another computer to do something when that code sends it some data.

Clearly, what the code does, and what you want it to do (including telling the other computer to do something) are not the same thing.

The purpose of debugging information is to see where what the code does differs from what you want it to do. The first thing to see is when there is a connection to the (Arduino as) server. If that occurs when the initial page is requested, and again at the specified intervals, you've learned one thing. If not, you've learned something else.

You keep adding debug print statements farther in the code. What is the client asking for initially? On subsequent requests? Are those things what you expect? Are you generating the correct response in each case?

great, thanks, ill add more print lines like you say, and post back when ive done more testing.