Wifly Shield stops after 10 mins

Hi,

I recently bought a spark fun wifly shield (model 2.21 RN 131C).

I have had it working perfectly as a web server, to control 3 LED’s.

I am now using it along with an Adafruit motor shield (I have re routed a couple of pins on the motor shield to allow it to work with the wifly shield) and arduino uno to control a dc motor in response to tweets. It thought I had it working perfectly, but it only works for about 10 mins before it stops making http requests and the green light just stays on constantly. Sometimes the orange one flashes too but the serial monitor shows nothing, not even “association failed” as my code tells it to.

There is no obvious problem with my code or hardware as they both work perfectly for 10 mins.

Do you have any suggestions as to why it may stop working?

Here is the code i’m using:

#include "WiFly.h"

#include <AFMotor.h>

AF_DCMotor motor(2, MOTOR12_64KHZ);

String twitterUsername = "NickysLights"; //set the twitter user you'd like to get here.

char ssid[] = "";  //enter your ssid here.
char passphrase[] = ""; //enter your passphrase here.

const unsigned long requestInterval = 2000;  // delay between requests
boolean requested;                   // whether you've made a request since connecting
unsigned long lastAttemptTime = 0;            // last time you connected to the server, in milliseconds

String currentLine = "";            // string to hold the text from server
String tweet = "";                  // string to hold the tweet
boolean readingTweet = false;       // if you're currently reading the tweet


Client client("whitespacers.com", 80);

void setup() {
  currentLine.reserve(256);
  tweet.reserve(150);
  
  
  Serial.begin(9600);

  WiFly.begin();
  
  if (!WiFly.join(ssid,passphrase)) {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.
    }
  }  

  Serial.println("connecting...");

}

void loop() {
  if(client.connected()){
    if (client.available()) {
      char inChar = client.read();
      
      // add incoming byte to end of line:
      currentLine += inChar; 

      // if you get a newline, clear the line:
      if (inChar == '\n') {
        currentLine = "";
      }
      
      if ( currentLine.endsWith("<text>")) {
        // tweet is beginning. Clear the tweet string:
        readingTweet = true; 
        tweet = "";
      }
      // if you're currently reading the bytes of a tweet,
      // add them to the tweet String:
      if (readingTweet) {
        if (inChar != '<') {
          tweet += inChar;
        } 
        else {
          // if you got a "<" character,
          // you've reached the end of the tweet:
          readingTweet = false;
          Serial.println(tweet);  
         
          char tweet = Serial.read();
checkAction();
          // close the connection to the server:
          client.stop(); 
        }
    
      }
    }
  }
  else if (millis() - lastAttemptTime > requestInterval) {
    // if you're not connected, and two minutes have passed since
    // your last connection, then attempt to connect again:
  connectToServer();
  }
}

void connectToServer() {
  // attempt to connect, and wait a millisecond:
  Serial.println("connecting to server...");
  if (client.connect()) {
    Serial.println("making HTTP request...");
    // make HTTP GET request to twitter:
  
   client.println("GET /train/index.php HTTP/1.0");
    client.println("HOST: whitespacers.com");
    client.println();
  }
  // note the time of this connect attempt:
  lastAttemptTime = millis();
}   
void checkAction() {
  if (tweet == ">gofast!")
  {
    motor.setSpeed(150);
   motor.run(BACKWARD); 
    delay(4000); 
    motor.setSpeed(50);
    motor.run(BACKWARD);
    delay(1000);
    motor.run(RELEASE); 
  }
  
    else if (tweet == ">gofast")
  {
    motor.setSpeed(200);
   motor.run(BACKWARD); 
    delay(4000); 
    motor.setSpeed(50);
    motor.run(BACKWARD);
    delay(1000);
    motor.run(RELEASE); 
    
  }
      else if (tweet == ">faster")
  {
    motor.setSpeed(150);
   motor.run(BACKWARD); 
    delay(4000); 
    motor.setSpeed(50);
    motor.run(BACKWARD);
    delay(1000);
    motor.run(RELEASE); 
    
  }
   else if (tweet == ">fast")
  {
    motor.setSpeed(150);
   motor.run(BACKWARD); 
    delay(4000); 
    motor.setSpeed(50);
    motor.run(BACKWARD);
    delay(1000);
    motor.run(RELEASE); 
  }
   else if (tweet == ">fast!")
  {
    motor.setSpeed(150);
   motor.run(BACKWARD); 
    delay(4000); 
    motor.setSpeed(50);
    motor.run(BACKWARD);
    delay(1000);
    motor.run(RELEASE); 
  }
  
   else if (tweet == ">go")
  {
    motor.setSpeed(110);
   motor.run(BACKWARD); 
    delay(6000); 
    motor.setSpeed(50);
    motor.run(BACKWARD);
    delay(1000);
    motor.run(RELEASE); 
  }
  
   else if (tweet == ">go!")
  {
    motor.setSpeed(110);
   motor.run(BACKWARD); 
    delay(6000); 
    motor.setSpeed(50);
    motor.run(BACKWARD);
    delay(1000);
    motor.run(RELEASE); 
  }
  
else if (tweet == ">go slow")
  {
     motor.setSpeed(80);
   motor.run(BACKWARD); 
    delay(6000); 
    motor.run(RELEASE); 
    }
  
  else if (tweet == ">slow")
  {
    motor.setSpeed(80);
   motor.run(BACKWARD); 
    delay(6000); 
    motor.run(RELEASE); 
  }
  
   else if (tweet == ">slow down")
  {
    motor.setSpeed(80);
   motor.run(BACKWARD); 
    delay(6000); 
    motor.run(RELEASE); 
  }
  else if (tweet == ">reverse")
  {
    motor.setSpeed(80);
   motor.run(FORWARD);
    delay(4000); 
    motor.run(RELEASE); 
  }
   else if (tweet == ">reverse!")
  {
    motor.setSpeed(80);
   motor.run(FORWARD); 
    delay(4000); 
    motor.run(RELEASE); 
  }
  else if (tweet == ">backwards")
  {
    motor.setSpeed(80);
   motor.run(FORWARD); 
    delay(6000); 
    motor.run(RELEASE); 
  }  
}

I tried running the factory reset command from the wifly library and later read that this may have been a bad idea.

Any help won;d be greatly appreciated.

Thanks,

Nicola

Be sure to update the WiFly firmware to the latest version; older versions such as 2.21 are extremely buggy.

Follow the directions in the WiFly user manual, as specifically modified here: http://www.rovingnetworks.com/FAQs/I_ge … Fly_module

Hi,

Its using version 2.23, should that be ok?

Using the spiUart terminal scan command, these are the networks that show up.

<2.23>

SCAN:Found 7

Num SSID Ch RSSI Sec MAC Address Suites

1 visitspace 01 -61 WPA2PSK 20:c9:d0:a4:3c:14 AESM-AES 3104 0

2 ourspace 02 -57 WPA2PSK 30:46:9a:fc:4d:53 AESM-AES 3100 0

3 Le di-vin wine bar 06 -61 Open 00:22:3f:39:27:06 104 0

4 BTHub3-CR5C 06 -86 WPA_Mix 00:01:3b:8f:cc:e2 AES/TKIPM-TKIP 3104 0

5 2WIRE742 06 -76 WEP 00:19:e4:33:79:61 3104 0

6 BTWiFi-with-FON 06 -83 Open 12:01:3b:8f:cc:e2 2104 0

7 awesomespace 11 -74 WPA2PSK 20:c9:d0:29:44:1b AESM-AES 3104 0

I’m trying to use ourspace. Should there be any problem with that?

Upgrade. I don’t have enough experience yet to have a clear idea of how many problems remain with the latest version of the firmware (2.36), but you are definitely wasting your time with version 2.23.

Hello Nicola,

I am trying to do the same thing, i.e., use an Adafruit Motor Shield over a Wifly Shield, which is iteself over the UNO.

I was able to test the the Wifly+Uno and MotorShield+Uno successfully.

However, I am not able to get the motor shield to work when I sent it messages through the Wifly.

Did you have to make any adjustments to any of the pins/ shields to get your setup to work for the first 10 mins?

Thanks a lot!

Joe

yes you have to re route pins, see this forum post:

http://forums.adafruit.com/viewtopic.php?f=22&t=34187

and this website

http://shieldlist.org

good luck!

Hello Nicole,

Thank you very much for your reply and for the links you posted. From reading up about it from the old forum, here is what I have understood. Please let me know if this is the way to go.

  • I am using the shield for 3 DC motors(2,3,4), which leaves Pin D11 unused. Also, Pin D2 is unused.

  • Therefore I can jumper D7 to D2 and D12 to D11.

  • I will have to redefine MOTORENABLE 7 -->MOTORENABLE 2 and MOTORLATCH 12–>MOTORLATCH 11 in AFMotor.h

  • I will need to “cut” a copper trace from both D7 and D12. This means I need to scratch the electrical connection leading from the respective pins to the rest of the circuit?

^ As an alternative to that, can I just twist the legs from pins D7 and D12 that would go into the sockets of the Wifly’s D7 and D12?

Thank you very much for your time!

Joe

Hello again Nicole,

Please disregard the 4th point of my last post. I realize that didn’t make a whole lot of sense and went ahead and cut the copper trace off with a knife for pins D12 and D7, jumpered D12 to 11 and D7 to 2 respectively, and changed the code in AFMOTOR.h to reflect the changes.

However, on attempting to test the modified shield with the UNO using the MotorTest sketch, I get the motor in M3 to rotate continuously regardless of which motor I specify. I have motors connected to 2, 3, and 4.

On sandwiching the WiFly Shield in between the UNO and MotorSfield, I ave the same behavior as above happening to Motor 2.

Any ideas on what is going on?

Thanks!

Joe