CC3000 HTTP server problems

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ehelseth
 
Posts: 10
Joined: Wed Feb 11, 2015 1:39 pm

CC3000 HTTP server problems

Post by ehelseth »

I have an Arduino Mega with a CC3000 WiFi Shield set up as a simple HTTP Server responding with sensor output (pressure, temp etc).
It works, but I might experience problems with “stability”, or keeping it working over time.
It seems to be the HTTP server that stops "responding", it never returns a valid client (from the available()-call), and the calling client experiencing connection timeouts.
The wifi connection seems to be ok, it is possible to ping the shield, but no response on HTTP.

Is there a way to "restart" the HTTP server?
I've tried calling begin() again, but that doesn't help.

Thanks!
-Alf

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: CC3000 HTTP server problems

Post by adafruit_support_rick »

First, you should install the latest firmware. update 1.14. Get a fresh download of the Adafruit CC3000 Library, and run the sketch driverpatch_1_14. Make sure you open Serial Monitor when you run the sketch, because you will be prompted to hit return.

https://github.com/adafruit/Adafruit_CC3000_Library

User avatar
ehelseth
 
Posts: 10
Joined: Wed Feb 11, 2015 1:39 pm

Re: CC3000 HTTP server problems

Post by ehelseth »

Thanks for the reply!

I'm already running 1.14 of the firmware, also lately upgraded to the latest version of the library (Adafruit_CC3000_Library-master-5).

The problem seems to occur after running it for some time (typically after a few hours with approx 50-60 calls per minute, but it varies alot).
As far as I have been able to find out, the shield still seems to be connected (the cc3000.getStatus() returns 3), and it's possible to ping from the Mac to the shield, also it is possible to ping the Mac from the Arduino too.
But the HTTP server seems to not respond anymore.
I've tested a few cards (Mega + CC3000) now, and they all seems to have a similar behaviour.

I also have another Mega with an Arduino WiFi shield (based on the HDG204) running a similar program (on the same network), this seems to work fine for days.
Shouldn't these two setups ideally behave similar?

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: CC3000 HTTP server problems

Post by tdicola »

One other thing to check, what version of the Arduino IDE are you using? For the CC3000 stick with the 1.0.6 version and not the newer 1.6 version or 1.5.7/1.5.8/etc. beta versions. You can grab the 1.0.6 version here: http://arduino.cc/en/Main/OldSoftwareReleases Instead of using the later version, drop back down to 1.0.6 and let me know if that helps with the reliability.

User avatar
ehelseth
 
Posts: 10
Joined: Wed Feb 11, 2015 1:39 pm

Re: CC3000 HTTP server problems

Post by ehelseth »

Thanks for tips!

I am currently running version 1.0.5 if the IDE.
I've "been through" a 1.5.x version, but switched back to 1.0.5 as I experienced some problems (that later showed up to be related to too little power provided from the USB port...).
I'll try the 1.0.6 version, but that still is based on Java 6 isn't it?

I still suspect the HTTP server, all my tests points to that as the problem. However, there is no "fixed way" of reproducing it, it typically occurs after a while with traffic.
I have tested with the library sample code HTTPServer, this also typically gets "stuck" after a while (some hours) with requests.

User avatar
ehelseth
 
Posts: 10
Joined: Wed Feb 11, 2015 1:39 pm

Re: CC3000 HTTP server problems

Post by ehelseth »

I've tested with 1.0.6 IDE now, so far it doesn't seem to make any difference.
The problem I see should be fairly easy to reproduce for others too, I run the HTTPServer sample sketch on the Arduino.

As a test client I normally use Apache JMeter (http://jmeter.apache.org) running a continuos loop with HTTP requests.
However, the problem I see is also reproduce-able with a simple loop on the command line using curl (this runs on Mac, and I guess also on Linux):

Code: Select all

while [ 1 ] ; do curl -m 2 -X GET 192.168.1.140/temp; done
After a while (typically some hours) the curl-command starts to hang/fail (on the 2 second timeout), and no response is received any more.
After that, the sketch still responds to ping request, but no more to HTTP.

I've done a small addition to the HTTPServer sample (add response number counter), this to get little better "statistics":
(This shows the loop()-function only)

Code: Select all

void loop(void)
{
    static int count;
    // Try to get a client which is connected.
    Adafruit_CC3000_ClientRef client = httpServer.available();
    if (client) {
        Serial.println(F("Client connected."));
        // Process this request until it completes or times out.
        // Note that this is explicitly limited to handling one request at a time!

        // Clear the incoming data buffer and point to the beginning of it.
        bufindex = 0;
        memset(&buffer, 0, sizeof(buffer));

        // Clear action and path strings.
        memset(&action, 0, sizeof(action));
        memset(&path,   0, sizeof(path));

        // Set a timeout for reading all the incoming data.
        unsigned long endtime = millis() + TIMEOUT_MS;

        // Read all the incoming data until it can be parsed or the timeout expires.
        bool parsed = false;
        while (!parsed && (millis() < endtime) && (bufindex < BUFFER_SIZE)) {
            if (client.available()) {
                buffer[bufindex++] = client.read();
            }
            parsed = parseRequest(buffer, bufindex, action, path);
        }

        // Handle the request if it was parsed.
        if (parsed) {
            Serial.println(F("Processing request"));
            Serial.print(F("Action: ")); 
            Serial.println(action);
            Serial.print(F("Path: ")); 
            Serial.println(path);
            // Check the action to see if it was a GET request.
            if (strcmp(action, "GET") == 0) {
                // Respond with the path that was accessed.
                // First send the success response code.
                client.fastrprintln(F("HTTP/1.1 200 OK"));
                // Then send a few headers to identify the type of data returned and that
                // the connection will not be held open.
                client.fastrprintln(F("Content-Type: text/plain"));
                client.fastrprintln(F("Connection: close"));
                client.fastrprintln(F("Server: Adafruit CC3000"));
                // Send an empty line to signal start of body.
                client.fastrprintln(F(""));
                // Now send the response data.
                client.fastrprint(F("Hello world! "));
                char buf[16];
                itoa(count++, buf, 10);
                client.fastrprintln(buf);
                client.fastrprint(F("You accessed path: ")); 
                client.fastrprintln(path);
            }
            else {
                // Unsupported action, respond with an HTTP 405 method not allowed error.
                client.fastrprintln(F("HTTP/1.1 405 Method Not Allowed"));
                client.fastrprintln(F(""));
            }
        }

        // Wait a short period to make sure the response had time to send before
        // the connection is closed (the CC3000 sends data asyncronously).
        delay(100);

        // Close the connection when done.
        Serial.println(F("Client disconnected"));
        client.close();
    }
}

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: CC3000 HTTP server problems

Post by adafruit_support_rick »

How hard are you hitting the server? How many requests/second?

User avatar
ehelseth
 
Posts: 10
Joined: Wed Feb 11, 2015 1:39 pm

Re: CC3000 HTTP server problems

Post by ehelseth »

Normally I use approx 1 call per second.
However, when I use the curl loop it runs quite a bit faster, I guess 3-5 calls per sec.
Either way, after a while it stops, thats my problem!

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: CC3000 HTTP server problems

Post by tdicola »

Ah thanks for clarifying the load, yeah with multiple requests per second it's probably eating up all the sockets available for the CC3k to accept connections. It only has 4 sockets available so it really isn't made to deal with much concurrency. Also remember it's a tiny little embedded CPU similar to the Arduino so it's tough to really push it hard without hitting limits.

One thing to be careful about, do you know if any of the connections are hanging around and not being closed? It could be that after a little while all the available sockets are used up and the CC3k firmware can't accept anything else.

Ultimately though to get more stability in your original sketch you might want to periodically reset the CC3000 to help make sure connections aren't sticking around while being open. Perhaps every 10 minutes or so do something like this to reset the CC3000:

Code: Select all

// Reboot the CC3000
cc3000.reboot();

// Now connect to the AP again and wait for DHCP just like in the setup.
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Reconnect failed!"));
    while(1);
}
while (!cc3000.checkDHCP())
{
  delay(100);
}  
Give that a shot with your original code that was locking every hour or so and let's see if that helps the stability a bit. Try resetting it every 10-15 minutes or so to start with, but you might adjust up and down a bit too.

User avatar
ehelseth
 
Posts: 10
Joined: Wed Feb 11, 2015 1:39 pm

Re: CC3000 HTTP server problems

Post by ehelseth »

I agree that it's quite a load, and I know that it is a little CPU and all, so it has its limits.
However, the total "performance" I get is around 8-10 calls per second, but that much I don't need (and normally don't use).
But I think it shouldn't be concurrency, I only do requests synchronically (one always after the previous is finished, never in parallel). I've tried to run several in parallel, that crashes the CC3k easily, but that's an ok limitation.

What I really would like is stability over time. Through my testing I don't necessarily see any connection between load and stability.
But it might well be the sockets being "consumed", is it possible to monitor that somehow? E.g. during idle time verify that all sockets are available. If not, is it possible to close them separately? I mean, the reboot approach you suggest is a bit "brutal"?

I did add some code that performed a ping (against the router), every 60 second of idle time, and added the reboot code you suggest if the ping didn't go well. However, what I find is that the ping continues to run perfectly ok, even after the HTTP server stops to respond.
Does the ping command use the 4 sockets too, or is those only for the HTTP server?

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: CC3000 HTTP server problems

Post by tdicola »

Good question about the ping behavior--I believe the CC3000 firmware actually handles that itself without consuming any sockets or need to talk to the Arduino. It might be better for your monitoring to query a URL or piece of data being served by your sketch, that way it can know if it's up or down reliably.

User avatar
ehelseth
 
Posts: 10
Joined: Wed Feb 11, 2015 1:39 pm

Re: CC3000 HTTP server problems

Post by ehelseth »

I guess I've been a little unclear here regarding the ping, I think you misunderstand the "direction"!
It's the Arduino that performs the ping action during it's idle time, not "external" monitoring! Every 60 seconds or so of the Arduino being idle it performs a ping command against my Wifi router (I use the IP address returned from the cc3000.getIPAddress()-call at startup).
That way (I hoped) the sketch "itself" can verify that it has a valid connection (and possibly do a reboot() if it drops). But it has, all the time the ping-call returns successfully, even after the HTTP server (on the Arduino) has stopped responding.

So, the situation (after a while) is that the HTTP server (running on the Arduino/CC3K) stops responding to calls from my Mac, but the sketch on the Arduino continues to do (successful) ping-calls against the router.
How can the CC3K be in such a state?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: CC3000 HTTP server problems

Post by adafruit_support_rick »

ping uses a different network protocol than TCP/UDP. Ping doesn't use sockets.

User avatar
Brewington
 
Posts: 54
Joined: Sat Sep 27, 2014 7:45 pm

Re: CC3000 HTTP server problems

Post by Brewington »

Was there ever a resolution to this problem? I am experiencing the same problem, where the arduino is acting as a server. It works fine for awhile, but somehow stops accepting client connections. The sketch continues running, but the PC client times out trying to connect.

There is only one client on the PC, and it only hits the server every 2-5 seconds so there shouldn't be a big load. Each time the PC wants to send a command it opens the connection, sends the command, reads a response, then closes the connection. The connection is not left open over time.

I would be interested in whatever resolution the original poster came up with:)

User avatar
ehelseth
 
Posts: 10
Joined: Wed Feb 11, 2015 1:39 pm

Re: CC3000 HTTP server problems

Post by ehelseth »

Hi @Brewington, from what you write I assume you touch into the same problem that I had.
I never got any solution to my problem, so I ended up ditching the CC3K, and switched to the ESP8266 module instead.

It is quite different than the CC3K as such (UART communication, AT-commands etc), but seems to be very stable.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”