Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Novice
960 Views

Web server rejected a connection

I want to create a web server that will update a value of analog input on a page. The problem is that when I'm refreshing the page the second or third time, the system fails and I've got this message:

Server 192.168.0.100 rejected connection.

What can cause this error? I use AJAX requests to update the value automatically.

void GetAjaxData(EthernetClient cl) {  int analog_val;  // read analog pin A0  analog_val = analogRead(0);  cl.print("Analog 0: ");  cl.print(analog_val);  cl.println(""); }  void loop() {  EthernetClient client = server.available(); // try to get client  if (client) { // got client?  boolean currentLineIsBlank = true;  while (client.connected()) {  if (client.available()) { // client data available to read  char c = client.read(); // read 1 byte (character) from client  HTTP_req += c; // save the HTTP request 1 char at a time  // last line of client request is blank and ends with \n  // respond to client only after last line received  if (c == '\n' && currentLineIsBlank) {  // send a standard http response header  client.println("HTTP/1.1 200 OK");  client.println("Content-Type: text/html");  client.println("Connection: keep-alive");  client.println();  // AJAX request for switch state  if (HTTP_req.indexOf("ajax_switch") > -1) {  // read switch state and analog input  GetAjaxData(client);  } else { // HTTP request for web page  // send web page - contains JavaScript with AJAX calls  client.println("<!DOCTYPE html>");  client.println("");  client.println("");  client.println("Arduino Web Page");  client.println("");  client.println("function GetSwitchAnalogData() {");  client.println(  "nocache = \"&nocache=\" + Math.random() * 1000000;");  client.println("var request = new XMLHttpRequest();");  client.println("request.onreadystatechange = function() {");  client.println("if (this.readyState == 4) {");  client.println("if (this.status == 200) {");  client.println("if (this.responseText != null) {");  client.println("document.getElementById(\"sw_an_data\")\.innerHTML = this.responseText;");  client.println("}}}}");  client.println(  "request.open(\"GET\", \"ajax_switch\" + nocache, true);");  client.println("request.send(null);");  client.println("setTimeout('GetSwitchAnalogData()', 200);");  client.println("}");  client.println("");  client.println("");  client.println("");  client.println("Arduino AJAX Input");  client.println("");  client.println("");  client.println("");  client.println("");  }  // display received HTTP request on serial port  Serial.print(HTTP_req);  HTTP_req = ""; // finished with request, empty string  break;  }  // every line of text received from the client ends with \r\n  if (c == '\n') {  // last character on line of received text  // starting new line with next character read  currentLineIsBlank = true;  } else if (c != '\r') {  // a text character was received from client  currentLineIsBlank = false;  }  } // end if (client.available())  } // end while (client.connected())  delay(1); // give the web browser time to receive the data  client.stop(); // close the connection  } // end if (client) }
Tags (1)
0 Kudos
3 Replies
Highlighted
Community Manager
26 Views

Hi michalt38,

 

 

Thank you for contacting Intel Customer Support.

 

Could you please give me more details about what you are trying to do?

 

 

Regards,

 

Alexandra
0 Kudos
Highlighted
Novice
26 Views

I want to enter an Edison IP address in a web browser and see a page on which will be displayed an actual value on analog input A0. This value should be updated automatically every 0,2 ms (more or less) without refreshing a page.

0 Kudos
Highlighted
Community Manager
26 Views

Hi michalt38,

 

 

It seems to be a problem with your code, we can't debug it or fix it for you.

 

 

Regards,

 

Alexandra
0 Kudos