Hello
I am working on a very simple project, reading data from a light sensor and show it on a web page. I have done all the steps correctly because i can see the values of the light meassured on my serial monitor, but the problem is, when i try to open the IP in the browser it says This site can’t be reached 192.168.1.177 took too long to respond. I have tried everything, even setting a bridge connection between my laptop and ethernet. I have to make this work and i don't even understand why it's not working, maybe an ip address problem
Does anyone has any idea on what should i do ?
I am also including here the code
Thank you
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);
IPAddress myDns (192,168,1,2);
IPAddress gateway (192,168,1,1);
IPAddress subnet (255, 255, 255, 0);
int photocellPin = 0; // Analog input pin on Arduino we connected the SIG pin from sensor
int photocellReading; // Here we will place our reading
EthernetServer server(80);
void setup() {
Serial.begin(9600);
Ethernet.begin(mac,ip,myDns,gateway,subnet);
server.begin();
while (!Serial) {
;
}
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP"); }
Serial.print("Arduino server IP address: ");
Serial.println(Ethernet.localIP());
}
void loop() {
photocellReading = analogRead(photocellPin); // Fill the sensorReading with the information from sensor
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 5");
client.println();
client.println("");
client.println("");
client.println("");
client.println("Arduino sensor data");
client.println("");
client.println("");
client.println("");
client.println("
");
client.println("
Light measured from the sensor is:
");client.println("");
client.println("");
client.println("");
break;
}
else {
Serial.println("connection failure");
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
client.stop();
}
Serial.println(photocellReading);
delay(5000);
}