Go Down

Topic: WiFly Solid Green Block (Read 680 times) previous topic - next topic


Jun 29, 2013, 09:07 pm Last Edit: Jun 29, 2013, 11:27 pm by Matchlighter Reason: 1
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 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: [Select]
#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
  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

    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
        } //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) {
          if (requestString.indexOf("/BeginClean") > 0) {

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

          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("Battery mAh is ");
          client.print(" of ");
          client.print(" (");
          //client.println("<br />");
          client.println("<br />");
          client.print("Charging State: ");
          client.println("<br />");

          client.println("<a href=\"/BeginClean\"> Clean </a>");
          client.println("<a href=\"/SeekDock\"> Dock </a>");
        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


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

Go Up