Ethernet Shield can't connect to the server

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);
}

I must say that i am not using an original arduino ethernet shield, but a chinese one... do you think this is what may cause the problem ?

Why are you setting a static IP, then using DHCP to get another IP? Use one or the other.

// remove this
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP"); }

If you use your code as it was, what IP does the serial monitor show for the server?

Now that i removed that, it works, thank you very much.
If i use the code as it was the serial monitor showed the IP 192.168.1.2

esmeralda_h:
Now that i removed that, it works, thank you very much.
If i use the code as it was the serial monitor showed the IP 192.168.1.2

\In that case, you could have connected to the server using http://192.168.1.2

I tried it but it didn't work using http://192.168.1.2

If you are connecting the Ethernet shield to your router,
you don't need

IPAddress myDns (192,168,1,2);
IPAddress gateway (192,168,1,1);

I would comment it out.

Yeah, i supposed i needed them at first but now removd them
Now i am trying to connect with mysql server , I have followed the steps here Arduino: Save data to database - iCreateProject and it says in serial monitor connection failed and i don't understand why

I'm including the code below, thank you

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xDD };

IPAddress ip(192,168,1,177);

int photocellPin = 0; // Analog input pin on Arduino we connected the SIG pin from sensor
int photocellReading; // Here we will place our reading

IPAddress server(192,168,1,2);

// Initialize the Ethernet server library
EthernetClient client;

void setup() {

// Serial.begin starts the serial connection between computer and Arduino
Serial.begin(9600);

// start the Ethernet connection
Ethernet.begin(mac,ip);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

}

void loop() {

photocellReading = analogRead(photocellPin); // Fill the sensorReading with the information from sensor

// Connect to the server (your computer or web page)
if (client) {

// When a client sends a request to a webserver, that request ends with a blank line
boolean currentLineIsBlank = true;

Serial.println("OK"); }
if (client.connect(server, 80)) {
client.print("GET /write_data.php?"); // This
client.print("data="); // This
client.print(photocellReading); // And this is what we did in the testing section above. We are making a GET request just like we would from our browser but now with live data from the sensor
client.println(" HTTP/1.1"); // Part of the GET request
client.println("Host: 192.168.1.2"); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie.Host: "www.yourwebpage.com")
client.println("Connection: close"); // Part of the GET request telling the server that we are over transmitting the message
client.println(); // Empty line
client.println(); // Empty line
client.stop(); // Closing connection to server

}

else {
// If Arduino can't connect to the server (your computer or web page)
Serial.println("--> connection failed\n");
}

// Give the server some time to recieve the data and store it. I used 10 seconds here. Be advised when delaying. If u use a short delay, the server might not capture data because of Arduino transmitting new data too soon.
Serial.println(photocellReading);
delay(60000);
}

Are you sure your server is at 192.168.1.177 ?

That is actually the static ip i am setting...

esmeralda_h:
That is actually the static ip i am setting...

Can you ping it?

That is the arduino's server ip address
and 192.168.1.2 is the IPv4 which takes me to the local host

so i don't know what you mean when you say if i can ping it

esmeralda_h:
That is the arduino's server ip address
and 192.168.1.2 is the IPv4 which takes me to the local host

so i don't know what you mean when you say if i can ping it

I am guessing that your Arduino and the server are all on the same router.
Can you ping your server from your PC?