Skip to main content
Post Closed as "Duplicate" by Majenko, Dat Ha, rebatoma, brtiberio, KIIV
added 187 characters in body
Source Link
tpm900
  • 395
  • 3
  • 10

"Found" is printed to the serial every time the page refreshes even though I have not actually pressed the submit button to submit it more than once. I've tried the temporary redirect, but the linux machine I need to use for this project already does a redirect so my redirect doesn't work. Is there a way to do this without a redirect?

"Found" is printed to the serial every time the page refreshes even though I have not actually pressed the submit button to submit it more than once.

"Found" is printed to the serial every time the page refreshes even though I have not actually pressed the submit button to submit it more than once. I've tried the temporary redirect, but the linux machine I need to use for this project already does a redirect so my redirect doesn't work. Is there a way to do this without a redirect?

Source Link
tpm900
  • 395
  • 3
  • 10

Getting data from web form

I am using an EthernetServer and EthernetClient with Arduino in order to make a simple webpage. I have a web form for a user to enter various codes that can reset data stored on the back end. However, once I enter text into the web form once, it seems to be continually being included in the HTTP header after that. I have the URL: http://192.168.1.30, which becomes (and stays at) http://192.168.1.30/?data=5935 once I enter '5935'. My code is:

void loop() {

// Listen for incoming clients 
client = server.available();
if (client) {

boolean currentLineIsBlank = true;
while (client.connected()) {
  if (client.available()) {
    char c = client.read();

    if(HTTPHeader.length() < 100) {
      HTTPHeader += 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) {
      
      // Calcuate weather parameters for serial and web
      calcWeather(); //Go calc all the various sensors
      
      // Send a standard http response header
      client.println("HTTP/1.1 200 OK");
      client.println("Content-Type: text/html");
      client.println("Connection: close");  // the connection will be closed after completion of the response
      client.println("Refresh: 5");  // refresh the page automatically every 5 sec
      client.println();
      client.println("<!DOCTYPE HTML>");
      client.println("<html>");
      
      client.println("<br>");
      client.println("<BODY BGCOLOR=powderblue>");
      client.println("<br>");
      client.println("<b>Web Server and Radio Receiver </b>");
      client.println("<br>");
      client.println("version November 14, 2016");
      client.println("<br>");
      client.println("</center>");

      client.println("<b>INSIDE</b>");
      client.println("<br>");
      client.print("<b>Temperature (F) = <b><font color=red>");
      client.println(templm34);
      client.println("</b></font><br />");

      client.println("<b>Transmission Errors: </b>");
      client.print("<b><font color=red>");
      client.print(numberReceived);
      client.println("</b></font><br />");

      client.println("<b>Transmissions Received : </b>");
      client.print("<b><font color=red>");
      client.print(numberOfErrors);
      client.println("</b></font><br />");         

      client.println("<b>Transmission Error Rate: </b>");
      client.print("<b><font color=red>");
      client.print((numberReceived==0)?(0.0):(numberOfErrors/numberReceived));
      client.println("%</b></font><br />");
      
      client.println("<br />");
      client.println("<br />");
      client.println("<br />");
      client.println("<br />");

      // Display the table of illuminance values
      client.println("<table cellpadding=5, border=1>");
      client.println("<tr>");
      client.println("<th><u>Illuminance</u></th>");
      client.println("<th><u>Real World Light Value</u></th>");
      client.println("</tr>");
      client.println("<tr>");
      client.println("<td>0</td>");
      client.println("<td>Absolute Dark</td>");
      client.println("</tr>");
      client.println("<tr>");
      client.println("<td>10</td>");
      client.println("<td>Night</td>");
      client.println("</tr>");  
      client.println("<tr>");
      client.println("<td>100</td>");
      client.println("<td>Dark Day</td>");
      client.println("</tr>");
      client.println("<tr>");
      client.println("<td>1000</td>");
      client.println("<td>Overcast</td>");
      client.println("</tr>");
      client.println("</table>");
      client.println("<br />");
    
      client.println("<br />");
      client.println("<form action='/' method=get>");
      client.println("<input type=text name=data maxlength=4>");
      client.println("<input type=submit value=Submit>");
      client.println("</form>");
      
      client.println("</body>");
      client.println("</html>");
      
      break;
      
    }
    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);
client.stop();
if (HTTPHeader.indexOf("5935") > 0) {
  resetData();
  Serial.print("Found!");
}
HTTPHeader = "";
}

"Found" is printed to the serial every time the page refreshes even though I have not actually pressed the submit button to submit it more than once.