Wifly Shield lost connection and IP failure [SOLVED]

Hi everyone,

I’ve been using the Wifly Shield for a couple of months now, to build a standalone control application. This requires that the Wifly is available at all times so that orders can be sent to the Arduino at any given moment.

Thing is, it will sometimes lose signal from the wifi network that is connected to. I’ve written a piece of code that detects a disconnection and tries to reconnect to said network. It basically reads the data sent from the wifly to the Arduino, which says “Disconnected” if such thing happens. It will then reboot, and autoconnect.

Problem is, after it reconnects, it will stay with the PI04 pin fast blinking green (indicating that it doesn’t have IP).

As such, I can no longer send orders to the Arduino. The only solution I can use is hard rebooting the Arduino, i.e. disconnecting it from the power and pluging it back again.

However, this is not an acceptable solution, as this installation requires to be self contained for a long period of time.

Has anyone else had this problem before? Or can someone think of something that I’m missing?

Thanks in advance :slight_smile:

Dpontes:
I’ve been using the Wifly Shield for a couple of months now, to build a standalone control application.

Are you using the WiFly library code?

Problem is, after it reconnects, it will stay with the PI04 pin fast blinking green (indicating that it doesn’t have IP).

As such, I can no longer send orders to the Arduino. The only solution I can use is hard rebooting the Arduino, i.e. disconnecting it from the power and pluging it back again.

Do you have [this revision of the board? You will be able to tell if it has a date on the left side of the underside of the board like this:

http://static.sparkfun.com/images/produ … 54-03b.jpg

If you have the above revision of the board (the latest) then it’s possible to do a reset of the WiFly module via hardware which should in theory be the same as a power on/off. The library hasn’t yet incorporated support for this but I have written code to perform the reset.

–Philip;](http://www.sparkfun.com/commerce/product_info.php?products_id=9954)

Hi Phillip, thanks for your quick answer. I’m not using your library, as I’ve started to use the Wifly shield with the tutorial provided by Sparkfun.

Also, I don’t seem to have the latest revision of the board, as mine does not have that date (or any, for that matter). Would that mean that I cannot do a hardware reset?

Still, would you have any idea as to why it will not get an IP address upon the second reboot? Seems strange, as the instructions used are the same…

Boy, if distraction paid taxes…

The Wifly IS able to reconnect and obtain IP after it loses connection to the network. My problem was that after I reconnected and got the “Associated” message, I would just carry on with the program WITHOUT doing the “exit” command… :oops:

Obviously, it wouldn’t close the CMD mode, and therefore, would not get an IP fixed.

So, problem solved :smiley:

(And here I was, looking at hardware resets, for the shield or the Arduino, when all I needed was already in the code. I should already know that the answer to the most difficult problems is usually very simple).

I’m pleased to hear you’ve solved your problem.

Dpontes:
Also, I don’t seem to have the latest revision of the board, as mine does not have that date (or any, for that matter). Would that mean that I cannot do a hardware reset?

Just to answer this, only the latest version of the board has a date (it’s the easiest way to differentiate it from the previous version). And only the latest version has hardware reset.

So, it’s good you’ve managed to solve the problem in software. :slight_smile:

Thanks for updating the thread with your success.

–Philip;

Hi Dpontes,

I’ve been have same problem to you. I am currently set another Arduino and send signal to reset pin in each 3 mins, which is not ideal solution.

Could you explain a bit more how you skip “exit”?

I haven’t set the command for exit so I’m not sure which line I should skip…

Sorry if it’s silly question but if you give me an advise, I really appreciate it.

Thanks in advance

Hi leecmo,

sorry for the late response, I only saw the notification email today.

i’m not quite sure I understood your problem. Do you mean that you’re trying to reobtain an IP address after an eventual loss of connection? I’ve come to realize that it in fact does not lose its IP address. I only issued this thread because the green LED in the Wifly wouldnt go into slow blink after I had gotten a message that it had recconected to the network. What happened was that I was forgetting to add the ‘exit’ command in the end, so that it would leav CMD mode and resume communication with the network.

Now, what I have in my code is that I detect a connection loss when there is a ‘Disconnected’ message in the SPI_Uart. In that case, it is going to try to reconnect by issueing a ‘join’ command in CMD mode. After it checks that it has been able to recconect (if thats the case) a ‘exit’ command should be issued so that the green LED flashes at a slow rythm.

do
    {
      if((SPI_Uart_ReadByte(LSR) & 0x01))
      {
        incoming_data = SPI_Uart_ReadByte(RHR);
        Serial.print(incoming_data,BYTE);
        message[k] = incoming_data;      // Message is saved in the message[] vector
      }
      k++;
    }while(k < 30);
   
    if(message[0] == 'D')                //If Wifly is disconnected from WiFi Network 
    {
      SPI_Uart_print("$$");
      delay(100);
      SPI_Uart_println("join Test");   // 'Test' is the SSID of your network
      delay(3000);
      SPI_Uart_println("show c");      // checks if there has been a connection
      if(Wait_On_Response_Char(13) != '0')
                  {
                    Serial.println("Not Connected... Retrying");
                    Flush_RX();
                  }
      else
            {
                 Serial.println("Sucess!");
                 SPI_Uart_println("exit");       // This is what I was missing before :)
                 Flush_RX();
            }

With this code it should work, although it’s not bulletproof. It’s not prepared in case it isnt able to reconnect after first try, but that seems like a good exercise in hacking :slight_smile:

I cant post my solution here because it’s meshed in the middle with the rest of the code. It works, and it makes sense in my head, but I have a hard time explaining it.

But it basically tests on every loop if there the Wifly is connected (I have a flag for that). If its not, it will run a function one line at a time (I have it in a switch case, so it can work in 'parallel processing - I cant have it blocking the rest of the program). When it tests the connection with the ‘show c’ command, it will change the connection flag, and this function wont run again until there is an eventual loss of connection once more.

This, of course, relies on the fact the you’re following the sparkfun Wifly tutorial and code, like me. Otherwise, I will have some dificulty in helping you…

Hope this has been of some help, and in case you need more help, or you didn’t understand something, feel free to ask and I’ll try to be more clear.

Cheers

Thanks, Dpontes!

Sorry for being late to reply so far. I still cannot get the actual device to try your suggestion as it’s installed and also I couldn’t manage time to tweak it so far. However, I will try and report as soon as possible, probably this week.

Thanks again.