CC3000 Web Server

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
pdh
 
Posts: 174
Joined: Wed Dec 25, 2013 12:59 pm

Re: CC3000 Web Server

Post by pdh »

Have you tried viewing the page source from Safari, to see what (if anything) the browser is receiving? I think you have to locate the Developer Tools menu in Safari to find the View Source or View Page Source option. That will show you the HTML that the browser is seeing, and it can be useful if the problem is malformed HTML.

One of the "interesting" things about this sort of exercise is that there are so many layers involved. You have the CC3000 (with its sub-layers -- hardware, firmware, libraries, etc), the router and the local network, plus HTML (the page markup language with all the <tags>, that describes the document, which is probably part of your sketch), then HTTP (the network protocol that's used for transferring web pages over the net, with headers and a blank line and the HTML -- also probably done in your sketch). When doing troubleshooting, it's crucial to be able to figure out which layer is at fault. If you know for certain that the CC3000 is basically able to communicate, and if your HTML passes a validation test, then you've ruled out a lot of potential problems.

Are you saying that you can do "telnet <yourCC3000'sIPaddress> 80" from the machine where Safari is running, and you get HTML back after typing the GET and Host: lines as input? If so, that would prove that you can communicate with the CC3000, so the problem would almost have to be with the HTTP or HTML. Can you post a copy of the telnet session, so we can see what your sketch is sending back over the wire?

User avatar
mmyers
 
Posts: 5
Joined: Mon Jul 14, 2014 11:36 am

Re: CC3000 Web Server

Post by mmyers »

Well, since that post, I found the problem. Or at least a solution to my local problem. The telnet session produced what one would expect. All the data from fastrprintln() was there, just as coded. What started to make things work was when I changed

// give the web browser time to receive the data
delay(1);

// close the connection:
client.close();

to delay(10).

As you noted, I thought, 1ms isn't much time given the processing going on. From Safari on my laptop, over the WIFI, through the AP, back to the CC3000, from the CC3000 back through the AP, and then back to Safari on the laptop. With the client.close(), one is basically pulling the rug out from under the browser before whole loop completes.

Things seem to be working so far, given that change.

A "known-good" Webserver example in the release package would still be useful though.

User avatar
jasperp
 
Posts: 50
Joined: Mon May 27, 2013 5:06 am

Re: CC3000 Web Server

Post by jasperp »

Here is my webserver Method which is run in my main loop for checking for incoming HTTP requests.

It also handles incoming GET requests and runs methods based on the 4 Submit buttons being pressed. (html forms)
This example has 4 buttons to press, each one runs a different method depending which button was pressed, in my case it triggers relays.
I will not be including the entire project because there are thousands of lines of code among other reasons....

The webserver is one small part however due to the lack of examples floating around on how to use the CC3000 as small webserver im hoping my example will be able help some people.

Adafruit, it would be great if you could use this example to build an example sketch to include in with the library which shows also how to handle form submitted data, using my posted code.

Note that I have noticed for what ever reason the webserver will stop responding after a few hours or even days. I have not worked out why just yet.

Code: Select all

void checkHTTPRequest(){
  Adafruit_CC3000_ClientRef client = wifiServer.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    boolean currentLineIsGet = true;
    int tCount = 0;
    char tBuf[96];
    char *pch;
    int loopCount = 0;

    while (client.connected()) {
      while(client.available()) {
        loopCount = 0;
        char c = client.read();
        //Serial.write(c);

        if(currentLineIsGet && tCount < 96)
        {
          tBuf[tCount] = c;
          tCount++;
          tBuf[tCount] = 0;          
        }          
        if (c == '\n' && currentLineIsBlank) {
          LCD.setFont(SmallFont);
          LCD.print("Client Connected",CENTER,280);
          //while(client.available())
          pch = strtok(tBuf,"?");

          while(pch != NULL)
          {
            //GET REQUEST STUFF HERE
            if(strncmp(pch,"trigger1=",9) == 0)
            {
              //byte trigger = atoi(pch+9);
              triggerRelayOneClose(5);         
            }

            if(strncmp(pch,"trigger2=",9) == 0)
            {
              //byte trigger = atoi(pch+9);
              triggerRelayTwoClose(5);         
            }

            if(strncmp(pch,"trigger3=",9) == 0)
            {
              //byte trigger = atoi(pch+9);
              triggerRelayThreeClose(5);         
            }

            if(strncmp(pch,"trigger4=",9) == 0)
            {
              //byte trigger = atoi(pch+9);
              triggerRelayFourClose(5);         
            }
            pch = strtok(NULL,"& ");
          }
          
          
          //WEB GUI GOES HERE
          client.println("");
          client.println(F("<html><head><meta name='viewport' content='width=device-width, user-scalable=no'/><style type='text/css'>th{font-size:37px};</style><body>"));
          client.println(F("<table align='center'><tr><th>Timer</th></tr><form>"));
          client.println(F("<tr><td><input type='submit' style='font-size:26px; width:300px; height:80px;' name='trigger1' value='TRIGGER "));
          client.println(printScheduleLabel(1));
          client.println(F("'></td></tr>"));
          client.println(F("<tr><td><input type='submit' style='font-size:26px; width:300px; height:80px;' name='trigger2' value='TRIGGER "));
          client.println(printScheduleLabel(2));
          client.println(F("'></td></tr>"));
          client.println(F("<tr><td><input type='submit' style='font-size:26px; width:300px; height:80px;' name='trigger3' value='TRIGGER "));
          client.println(printScheduleLabel(3));
          client.println(F("'></td></tr>"));
          client.println(F("<tr><td><input type='submit' style='font-size:26px; width:300px; height:80px;' name='trigger4' value='TRIGGER "));
          client.println(printScheduleLabel(4));
          client.print(F("'></td></tr>"));
          client.println(F("</form></table></body></head></html>"));
          client.close();
          //END OF WEB GUI
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
          currentLineIsGet = false;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
      loopCount++;
      // if 10000ms has passed since last packet
      if(loopCount > 10000) {
        client.close();
      }
      // give the web browser time to receive the data
      delay(100);
      Serial.println(F("client disonnected"));
    }
  }
}

User avatar
mmyers
 
Posts: 5
Joined: Mon Jul 14, 2014 11:36 am

Re: CC3000 Web Server

Post by mmyers »

Regarding the eventual lockup of the web server, you may find this long thread in a different forum interesting.

https://community.spark.io/t/bug-bounty ... h/1322/499

User avatar
martinayotte
 
Posts: 5
Joined: Sat Aug 16, 2014 10:05 am

Re: CC3000 Web Server

Post by martinayotte »

According to this other thread about lockup/hang, there is workaround, although ugly :

viewtopic.php?f=31&t=50520

This workaround is to add "#define SEND_NON_BLOCKING 1" in socket.cpp, and then add delay(5) between each client.fastrprintln() calls.
I've applied those changes to my code, and WebServer seems to running fine now, at least since 2 hours (it was hanging in less than 15 mins before)

Still, I hope that TI will fix this ugly bug very soon !!!

User avatar
martinayotte
 
Posts: 5
Joined: Sat Aug 16, 2014 10:05 am

Re: CC3000 Web Server

Post by martinayotte »

According to this other thread about lockup/hang, there is workaround, although ugly :

viewtopic.php?f=31&t=50520

This workaround is to add "#define SEND_NON_BLOCKING 1" in socket.cpp, and then add delay(5) between each client.fastrprintln() calls.
I've apply those changes to my code, and WebServer seems to running fine now, at least since 2 hours (it was hanging in less than 15 secs before)

Still, I hope that TI will fix this ugly bug very soon !!!

Update : I've to increase delay(5) to increase delay(10), then to delay(15), and now trying delay(20) to see if it last 24 hours ... :-(

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

Return to “General Project help”