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
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