I am using an Uno with an ethernet shield piggy backed. Have loaded the standard webserver sketch with the IP address 192.168.1.177 for the uno. If I connect the Uno to my laptop directly using an RJ45 cable and open a web browser on the laptop, type in the IP address, the webserver displays the expected output showing the 6 analog channels.
While this is connected I get the following repeated output via the serial monitor-
server is at 192.168.1.177
gateway is at 192.168.1.1
subnet mask is 255.255.255.0
dns server is at 192.168.1.1
client disconnected
new client
GET /favicon.ico HTTP/1.1
Host: 192.168.1.177
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
Accept: /
Referer: http://192.168.1.177/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
If I now connect the Laptop to say DSL router port 1 and the Uno to DSL router port 2 and open a web browser typing in the 192.168.1.177 address again, I get site unreachable.
The serial output is
server is at 192.168.1.177
gateway is at 192.168.1.1
subnet mask is 255.255.255.0
dns server is at 192.168.1.1
Im using -
192.168.1.177 for the Uno
192.168.1.1 for the gateway (DSL router- TP link TD-W8901G 4 port)
192.168.1.1 for the DNSserver
and subnet mask 255.255.255.0
Most forums and articles dont mention connection via a switch or router just "connect it and it will display"
Any help appreciated.
thanks
sketch below
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at "); Serial.println(Ethernet.localIP());
Serial.print("gateway is at "); Serial.println(Ethernet.gatewayIP());
Serial.print("subnet mask is "); Serial.println(Ethernet.subnetMask());
Serial.print("dns server is at "); Serial.println(Ethernet.dnsServerIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.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
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>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("
");
}
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);
// close the connection:
client.stop();
Serial.println("client disconnected");
Ethernet.maintain();
}
}