I have a sketch based upon the web client example. On occasion the sketch executes the " Unable to retrieve the IP Address" code which issues a return and therefore it hangs. Pressing the reset button resolves the issue. Similarly I loose my connection and get the failure "Connection failed" followed by a return. Again, pressing the reset button resolves the problem.
What might be the programming steps to handle these two errors instead of issuing a return?
CC3000 Error Recovery
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: CC3000 Error Recovery
The code should not hang if you issue a return. It should just go back to the beginning of loop().
As for how to recover from these errors, that really depends on the logic of your sketch. Without seeing that, I can't offer much in the way of advice, except to re-try the operation that failed.
As for how to recover from these errors, that really depends on the logic of your sketch. Without seeing that, I can't offer much in the way of advice, except to re-try the operation that failed.
- mboroff
- Posts: 96
- Joined: Sat Feb 22, 2014 7:45 pm
Re: CC3000 Error Recovery
I am uploading 90 % of the code. It's a big sketch that gets the time via NTP (from your example code) and every ten minutes gets a weather update (from your webClient example).
The two areas of concern I have plugged with a reboot. They are when I can't obtain an ip address of the site
If you code a return here you end up returning the setup to main or where ever setup is called and it hangs.
The other code is when I loose the connection. Note that the disconnect is not coded at the end of receiving the data. I have tried coding subroutines to restart the card or reconnect or at the get dhcp and I have been unable to get the sketch to restart a connection.
The two areas of concern I have plugged with a reboot. They are when I can't obtain an ip address of the site
Code: Select all
/**************************************************************************/
/*!
@brief Tries to read the IP address and other connection details
*/
/**************************************************************************/
bool displayConnectionDetails(void)
{
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
{
Serial.println(F("Unable to retrieve the IP Address!\r\n"));
Serial.println("RESET!");
Serial.flush();
void(* resetFunc) (void) = 0; //declare reset function @ address 0
resetFunc(); //call reset
return false;
}
else
{
Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
Serial.println();
return true;
}
}
The other code is when I loose the connection. Note that the disconnect is not coded at the end of receiving the data. I have tried coding subroutines to restart the card or reconnect or at the get dhcp and I have been unable to get the sketch to restart a connection.
Code: Select all
/* Try connecting to the website.
Note: HTTP/1.1 protocol is used to keep the server from closing the connection before all data is read.
*/
Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 80);
if (www.connected()) {
www.fastrprint(F("GET "));
www.fastrprint(WEBPAGE2);
www.fastrprint(F(" HTTP/1.1\r\n"));
www.fastrprint(F("Host: ")); www.fastrprint(WEBSITE); www.fastrprint(F("\r\n"));
www.fastrprint(F("\r\n"));
www.println();
} else {
Serial.println(F("Connection failed"));
Serial.flush();
www.close();
cc3000.stop();
Serial.println("RESET!");
Serial.flush();
void(* resetFunc) (void) = 0; //declare reset function @ address 0
resetFunc(); //call reset
}
- Attachments
-
- test.txt
- (40.65 KiB) Downloaded 161 times
Last edited by adafruit_support_rick on Thu Oct 02, 2014 3:29 pm, edited 1 time in total.
Reason: please use code tags (</> button)when posting code
Reason: please use code tags (</> button)when posting code
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: CC3000 Error Recovery
Code: Select all
/* Display the IP address DNS, Gateway, etc. */
while (! displayConnectionDetails()) {
delay(1000);
}
Code: Select all
Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 80);
Code: Select all
if (minute() == 0 && second() < 2) {
playHourly();
donotPlay = true;
if (getWeb())
{
displayWeather();
prevDay = 99;
printDate();
if (hour() == 0 || hour() == 4 ||
hour() == 8 || hour() == 12 ||
hour() == 16 || hour() == 20 ) {
getNtp();
}
}
}
- mboroff
- Posts: 96
- Joined: Sat Feb 22, 2014 7:45 pm
Re: CC3000 Error Recovery
Ok. Thanks I will give it a try.
- mboroff
- Posts: 96
- Joined: Sat Feb 22, 2014 7:45 pm
Re: CC3000 Error Recovery
It looks like that worked. I didn't reset the ATMEGA2560 or retry until the next time it was scheduled to try for weather. Here's my Serial output:
Loaded in 144 ms
Weather retrieved in 5020 milliseconds
Web accesses 4
Music started<---------------------- Access at 4 P.M. Westminster chimes
16:0:0
Music stopped
16:0:25
Connection failed<--------------- failure returned a false
UpdateNTPTime<---------------- good access of NTP server
Current local time is:
16:1:44.58
Thursday, October 2, 2014
Day of year: 275
Time has been set to 16:1:44 10/2/2014
Weather retrieved in 4861 milliseconds<----------------- good access at 4:10 P.M.
Web accesses 7
Loading image 'Ovrc32.bmp'
File size:
3128
Image Offset: 54
Header size: 40
Bit Depth: 24
Image size: 32x32
Loaded in 144 ms
Weather retrieved in 4980 milliseconds<---------------- good access at 4:20 P.M.
Web accesses 8
Loading image 'Ovrc32.bmp'
File size:
3128
Image Offset: 54
Header size: 40
Bit Depth: 24
Image size: 32x32
Loaded in 143 ms
Weather retrieved in 4063 milliseconds<----------------- good access at 4:30 P.M.
Web accesses 9
Loaded in 144 ms
Weather retrieved in 5020 milliseconds
Web accesses 4
Music started<---------------------- Access at 4 P.M. Westminster chimes
16:0:0
Music stopped
16:0:25
Connection failed<--------------- failure returned a false
UpdateNTPTime<---------------- good access of NTP server
Current local time is:
16:1:44.58
Thursday, October 2, 2014
Day of year: 275
Time has been set to 16:1:44 10/2/2014
Weather retrieved in 4861 milliseconds<----------------- good access at 4:10 P.M.
Web accesses 7
Loading image 'Ovrc32.bmp'
File size:
3128
Image Offset: 54
Header size: 40
Bit Depth: 24
Image size: 32x32
Loaded in 144 ms
Weather retrieved in 4980 milliseconds<---------------- good access at 4:20 P.M.
Web accesses 8
Loading image 'Ovrc32.bmp'
File size:
3128
Image Offset: 54
Header size: 40
Bit Depth: 24
Image size: 32x32
Loaded in 143 ms
Weather retrieved in 4063 milliseconds<----------------- good access at 4:30 P.M.
Web accesses 9
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Please be positive and constructive with your questions and comments.