WiFly Shield : Network joined, but programm stuck

Hi everyone,

I'm currently having an odd problem. I succeeded in doing what I was trying for some weeks, this means being able to transmit data via Wifi and making the Arduino react according to these data. So I can use my Android Phone to activate a motor, for instance. I used for that the WiFly Shield library and everything workED fine. Indeed, I just came back to my house and decided to keep working on my project, so I was planning to use the WiFi Network of my house... However, I got a hard problem over there... Here's my program :

#include "WiFly.h"
#include "Servo.h"


char passphrase[] = "a269c7a7297a99669ee443af29";
char ssid[] = "Alice-dbde";

Server server(80);
Servo myservo;

void setup() {
  
  Serial.begin(9600);
  Serial.println("Setting up");
  WiFly.begin();
  Serial.println("WiFly started");
  
  
if (!WiFly.join(ssid, passphrase)) {
    while (1) {
      
      Serial.print("Error");
    }
  }

 Serial.println("Can u reach me ?");
  Serial.print("IP: ");
  Serial.println(WiFly.ip());
  myservo.attach(5);
  server.begin();
}

void loop() {
  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        
        Serial.print(c);
        
        if (c == 'a')
        {
          motor();
        }
        
        if (c == 'b')
        {
          unmotor();
        }
        
        // 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) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          
        }
        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();
  }
}

void motor()
{
  
  for(int pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
}

void unmotor()
{
  
  for(int pos = 180; pos > 0; pos -= 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
}

This worked absolutely fine at my school, but not there.

Indeed, it gets stuck here:

if (!WiFly.join(ssid, passphrase)) {
    while (1) {
      
      Serial.print("Error");
    }
  }

By stuck, I mean that the programm doesn't go after the if statement. But still does the Wifly.join or it wouldn't be able to join the network (it doesn't enter the while loop).

Moreover, I can see with the LEDS my Arduino is connected to my network ! I can even do a telnet on it (as I know its IP thanks to my DHCP configuration). So to sum up, it's stuck over there, but I does work. The problem is that as my program can't go after the WiFly.join(), I can't do anything else... I tried to connect manually, it perfectly work, but I'm bound to use this Library for this project (my teacher told me...). Would anyone have an idea about that odd problem ? O.o

Indeed, it gets stuck here:

That code says that if joining the network failed, print "Error" over and over on the serial monitor. You said nothing about seeing "Error" printed over and over again. Are we to presume, then that you didn't see "Error" printed over and over again. If not, then the code isn't stopping/blocking there.

Post all of your code, and serial monitor output.

Hi,

Thanks for ur answer. However, I focused on the fact that the programm doesn't enter the while loop, so here's the terminal output:

Setting up
WiFly Started

And then nothing...

Your grade on this assignment is 50%. That's a failing grade.

For extra credit, reread all requests for information, and respond accordingly.

This is all of my code and this is the terminal output.. I don't see what I forgot to answer..

Code:

#include "WiFly.h"
#include "Servo.h"


char passphrase[] = "a269c7a7297a99669ee443af29";
char ssid[] = "Alice-dbde";

Server server(80);
Servo myservo;

void setup() {
  
  Serial.begin(9600);
  Serial.println("Setting up");
  WiFly.begin();
  Serial.println("WiFly started");
  
  
if (!WiFly.join(ssid, passphrase)) {
    while (1) {
      
      Serial.print("Error");
    }
  }

 Serial.println("Can u reach me ?");
  Serial.print("IP: ");
  Serial.println(WiFly.ip());
  myservo.attach(5);
  server.begin();
}

void loop() {
  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        
        Serial.print(c);
        
        if (c == 'a')
        {
          motor();
        }
        
        if (c == 'b')
        {
          unmotor();
        }
        
        // 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) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          
        }
        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();
  }
}

void motor()
{
  
  for(int pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
}

void unmotor()
{
  
  for(int pos = 180; pos > 0; pos -= 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
}

Output:

Setting up
WiFly Started

This is all of my code and this is the terminal output.. I don't see what I forgot to answer..

Well, here's a clue.

Post all of your code, and serial monitor output.

Now, you get credit for this answer.

However, I focused on the fact that the programm doesn't enter the while loop

It doesn't enter the while loop because it, apparently, never returns from the WiFly.join(ssid, passphrase) call. You need to look at the WiFly library code, and see what the join() function is doing. Add Serial.print() statements, if needed.

My guess is that the ssid or passphrase that is valid at school is not valid at home. I'd certainly expect the ssid values to be different.

Thanks, it works.

I found that my network was found as WPA encrypted whereas it's WEP encrypted. As a consequence, the library sent "set wlan passphrase " instead of "set wlan key .

U saved my life ! And sorry for having been rude, I was a little bit bored about this problem.

And sorry for having been rude, I was a little bit bored about this problem.

"Bored" I don't understand. "Upset" I would understand.

Anyway, I'm glad you were able to figure out what the problem was, and what you needed to do to fix it.