Author Topic: Webserver Chunked example with issue  (Read 3452 times)

Techno

  • Newbie
  • *
  • Posts: 26
Webserver Chunked example with issue
« on: March 19, 2014, 07:10:17 pm »
I used the lastest Webserver chunked example cut out the example web page with the voltage reading and inserted a dynamic webpage; one that reads senors and real time clock.  Should be a cut and paste operation... it does not load in Firefox 27 or Internet Explorer 11.

Code: [Select]
void listen(){
  // listen for incoming
  // an http request ends with a blank line
 

  if (server.available()) {
    char c = server.read();
    Serial.write(c);
    // if you've gotten to the end of the line (received a newline
    // character) and the line is blank, the http request has ended,
    // so you can send a reply
    if (c == '\n' && currentLineIsBlank) {
      // send a standard http response header
      server.println("HTTP/1.1 200 OK");
      server.println("Content-Type: text/html");
      server.println("Connection: close");  // the connection will be closed after completion of the response
      //server.println("Refresh: 5");  // refresh the page automatically every 5 sec
      server.println("Transfer-Encoding: chunked");
      server.println();
/////////////////////////////////////////////////////////////////////     
      // output dynamic webpage
        server.printChunk("<!DOCTYPE HTML>");
        server.printChunk("<html>");
        server.printChunk("<h2>Weather Observations</h2><body><br />");
        server.printChunk("Treyburn Lakes<br />");
        server.printChunk("Indianapolis, IN 46239<br />");
        server.printChunk("Date,Time:  " + String(dtStamp) + " EST<br />");
        server.printChunk("Temperature:  " + String(DHT.temperature * 9 / 5 + 32) + " Deg. F.<br />");
        server.printChunk("Humidity:  " + String(DHT.humidity) + " %<br />");
        server.printChunk("Barometric Pressure:  " + String(pressureNow / 33.8638816) + " in. Hg." + "<br />");
        server.printChunk("Barometric Pressure:  " + String(pressureNow) + " mb.<br />");
        server.printChunk("Atmosphere:  " + String(pressureNow * 0.00098692326671601) + " Atm<br />");
        server.printChunk("Altitude:  " + String(Altitude * 3.28084) + " Feet<br />");
        server.printChunk("<br /><br />");
        server.printChunk("<h2>Collected Observations</h2><br />");
        server.printChunk("<a download href='log.txt ' >Data Collection</a><br />");
        server.printChunk("</body><br />");
        server.printChunk("</html>");
        server.closeChunk();
///////////////////////////////////////////////////////////////////////
           
      currentLineIsBlank = false;
     
    }
    else if (c == '\n') {
      // you're starting a new line
      currentLineIsBlank = true;
    }
    else if (c != '\r') {
      // you've gotten a character on the current line
      currentLineIsBlank = false;
    }
  }

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

 
}

Attached complete sketch; uses level shifter, DS1307, BMP085, and DHT22.


William

Techno

  • Newbie
  • *
  • Posts: 26
Re: Webserver Chunked example with issue
« Reply #1 on: March 24, 2014, 06:15:49 pm »
Can"server.printChunk" be used with float variables?

Could someone provide some guidance on this issue, please?  I am getting nowhere trying to resolve this issue.

William

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: Webserver Chunked example with issue
« Reply #2 on: March 26, 2014, 02:47:13 am »
It does not support floats - you could add that to the library directly or you could convert to a string first (for some exmaples of how to do that: http://forum.arduino.cc/index.php/topic,37391.0.html)