This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3100 Webserver

Other Parts Discussed in Thread: CC3100, ENERGIA, UNIFLASH

I just purchased CC3100 with MS432 launchpad, I am exploring few Webserver examples and would like to find out is there simpler way to send all HTML/CSS file to client other than using "client.print" for each line. I do not see any example of this.

  • Hi,

    Not sure I understood your question. Are you referring to the http_server example (processors.wiki.ti.com/.../CC31xx_HTTP_Server) ?

    Regards,
    Gigi Joseph.
  • I was looking at examples provided with Energia for Simple Webserver and Web page is downloaded to client using client.println for every line

    which is not efficient, is there way to download big HTML file other simpler way to cc3100.

    I was hoping to design WebPage using web builder tools and then be able to download this page to CC3100 flash which will act like webserver

  • Hi Joseph,

    The best way to do this right now is to use the serial flash on the cc3100 and put the html file there. You will need to use UniFlash to load the files into the serial flash. Unfortunately that requires a CC3100EMU board that you plug the cc3100 into (https://store.ti.com/cc3100boost-cc31xxemuboost.aspx

    Below is a Sketch that sends /sys/mcuimg.bin to the browser.

    You can do the same with html files. Simply replace the file name with your file name and change "application/octet-stream" to "text/html"

    #include <SPI.h>
    #include <WiFi.h>
    #include <WiFiClient.h>
    #include <WiFiServer.h>
    
    
    // your network name also called SSID
    char ssid[] = "molly";
    // your network password
    char password[] = "malgosia";
    // your network key Index number (needed only for WEP)
    int keyIndex = 0;
    
    WiFiServer server(80);
    
    void setup() {
      Serial.begin(115200);      // initialize serial communication
      pinMode(RED_LED, OUTPUT);      // set the LED pin mode
    
      // attempt to connect to Wifi network:
      Serial.print("Attempting to connect to Network named: ");
      // print the network name (SSID);
      Serial.println(ssid); 
      // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
      WiFi.begin(ssid, password);
      while ( WiFi.status() != WL_CONNECTED) {
        // print dots while we wait to connect
        Serial.print(".");
        delay(300);
      }
      
      Serial.println("\nYou're connected to the network");
      Serial.println("Waiting for an ip address");
      
      while (WiFi.localIP() == INADDR_NONE) {
        // print dots while we wait for an ip addresss
        Serial.print(".");
        delay(300);
      }
    
      // you're connected now, so print out the status  
      printWifiStatus();
      
      Serial.println("Starting webserver on port 80");
      server.begin();                           // start the web server on port 80
      Serial.println("Webserver started!");
    
    }
    
    char *fileName = "/sys/mcuimg.bin";
    
    void loop() {
      // listen for incoming clients
      WiFiClient client = server.available();
      if (client) {
        Serial.println("new client");
        long FileHandle;
        long success = sl_FsOpen((unsigned char *)fileName, FS_MODE_OPEN_READ, NULL, &FileHandle);
        if(success < 0) {
          Serial.println("Could not open file!");
          client.stop();
          return;
        } else {
          Serial.println("File opened!");
        }
        
        client.println("HTTP/1.1 200 OK");
        client.println("Content-Type: application/octet-stream");
        client.println("Connection: close");  // the connection will be closed after completion of the response
              
        uint8_t data[512];
        
        int16_t numbytes = 1;
        uint16_t offset = 0;
        
        while(numbytes > 0) {
          // Read and send in 512 byte chunks
          numbytes = sl_FsRead(FileHandle,offset, (unsigned char *)&data, 512);
          
          if(numbytes < 0) {
            break;
          }
          
          offset += numbytes;
          Serial.print("Bytes read: ");
          Serial.print(numbytes);
          Serial.print("\t Total: ");
          Serial.println(offset);
          client.write(data, numbytes);
          delay(1);
        }
        sl_FsClose(FileHandle,0,0,NULL);
        // give the web browser time to receive the data
        delay(1);
    
        // close the connection:
        client.stop();
        Serial.println("client disonnected");
      }
    }
    
    void printWifiStatus() {
      // print the SSID of the network you're attached to:
      Serial.print("Network Name: ");
      Serial.println(WiFi.SSID());
    
      // print your WiFi shield's IP address:
      IPAddress ip = WiFi.localIP();
      Serial.print("IP Address: ");
      Serial.println(ip);
    
      // print the received signal strength:
      long rssi = WiFi.RSSI();
      Serial.print("signal strength (RSSI):");
      Serial.print(rssi);
      Serial.println(" dBm");
    }
    

    Robert @ Energia

  • Thanks for info

    I will try this approach and will post results here