Pages: [1]   Go Down
Author Topic: WiFly Solid Green Block  (Read 260 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am having an issue with my project involving my WiFly. After a little while, the green light stops blinks and just stays on (which apparently means that it has an active TCP connection). When this happens, I have to reset the Arduino in order to perform any more communications with the WiFly. I discovered an old post (http://forum.arduino.cc/index.php?topic=50042.0), but restarting the browser doesn't help (as it did in his/her case), and he/she doesn't see fit to share the final solution.

I did find one thing that is interesting: when I open DD-WRT on my router, I find that the WiFly has an active UDP connection to 255.255.255.255 on port 55555 that has a status of 'UNREPLIED' and a renewing timeout. EDIT: However, this appears to be open even when things are working.

(Hopefully) needless to say, I have Googled the problem, but haven't found anything. Has anybody encountered this before and found the solution?

EDIT: Here's the code. I've cleaned it up a little for the post, but all the WiFly stuff is present.

Code:
#include <Roomba.h>
#include <SPI.h>
#include "WiFly.h"
#include "TwitterWiFly.h"
#include "Credentials.h"

Twitter twitter(twitter_oAuth);

Server server(80);

#define MinutesBetweenConnectionTries 5 //Time to wait between connection re-atempts, in minutes

void setup() {
  WiFly.begin(); //Initialize the WiFly
  while (!TryWiFly()) {
    delay(MinutesBetweenConnectionTries*60000); //If the connection failed, wait minutes defined and try again
  }
  randomSeed(analogRead(0)); //Make things really random
  server.begin();
  pinMode(8, OUTPUT);
}

uint8_t buf[52];
void loop(){
  bool ret = roomba.getSensors(3, buf, 10); //roomba.pollSensors(buf, 52);

  if (ret) { //ret is true when the checksum is correct

      //23,24/25,26
    battery_Current_mAh = buf[7]+256*buf[6];
    battery_Total_mAh = buf[9]+256*buf[8] | 0b00000001;
    //if (battery_Total_mAh == 0) {
    // battery_Total_mAh=1;
    //}; //Don't want to try and divide by zero.
    battery_percent = battery_Current_mAh*100/battery_Total_mAh;

  }


  CheckWebServerClients(); //Check for clients to the Webserver
  delay(10); //No need to go faster. Roomba only checks its sensors every 15ms. Going faster will only slow the Roomba down.
}
void CheckWebServerClients() { //Mostly Sample code here
  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    String requestString = String("");

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        if (requestString.length() < 30) { //read char by char HTTP request
          requestString.concat(c);
        } //store characters to string

        // 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 (c == '\n' && current_line_is_blank) {

          if (requestString.indexOf("/SeekDock") > 0) {
            roomba.coverAndDock();
          }
          if (requestString.indexOf("/BeginClean") > 0) {
            roomba.cover();
          }

          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          client.print("<a style=\"color:rgb(");
          long PercentToByte = map(battery_percent,0,100,0,255); //Fancy bit of code to fade the text color like the Roomba's power LED
          client.print(255-PercentToByte);
          client.print(",");
          client.print(PercentToByte);
          client.print(",0)\">");

          client.print("Battery mAh is ");
          client.print(battery_Current_mAh);
          client.print(" of ");
          client.print(battery_Total_mAh);
          client.print(" (");
          client.print(battery_percent);
          client.print("%)");
          //client.println("<br />");
          client.print("</a>");
          client.println("<br />");
          client.print("Charging State: ");
          client.print(ChargeTypes[chargingState]);
          client.println("<br />");

          client.println("<a href=\"/BeginClean\"> Clean </a>");
          client.println("<a href=\"/SeekDock\"> Dock </a>");
          break;
        }
        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;
        }
      }
    }
    // give the web browser time to receive the data
    delay(100);
    client.stop();
  }
}
« Last Edit: June 29, 2013, 04:27:14 pm by Matchlighter » Logged

Québec
Offline Offline
Sr. Member
****
Karma: 7
Posts: 389
When it's not human error, it's Windows going schizophrenic.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Peux-tu partager ton code?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yup, forgot to do that, sorry. See OP.
Logged

Québec
Offline Offline
Sr. Member
****
Karma: 7
Posts: 389
When it's not human error, it's Windows going schizophrenic.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Je vais passer au travers, je te redonne de new's smiley
Logged

Pages: [1]   Go Up
Jump to: