Can't ping Arduino with ethernet shield

Hi
I got my arduino hookt to an ethernet shield and im running an mqtt program on it which sends and receives some sensor data etc from my raspberry pi where im running node-red on. Everything is running good and there are no problem till i decided i wanted node-red to ping my arduino just to check if its running. It couldn't. The ping got timeout all the time. So i pinged it from my computer and i got something strange back The arduino is on 192.168.0.102. It usually doesn't look like this when i pin another computer. And its looks like its working if you want to belive the last line Sent = 4, Received = 4. Am i missing something in my code or has anyone been in the same situation as me and maybe fixed the problem?

Pinging 192.168.0.102 with 32 bytes of data:
Reply from 192.168.0.1: Destination host unreachable.
Reply from 192.168.0.1: Destination host unreachable.
Reply from 192.168.0.1: Destination host unreachable.
Reply from 192.168.0.1: Destination host unreachable.

Ping statistics for 192.168.0.102:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

my code.

#include <SPI.h>
#include <DHT.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#include <RemoteReceiver.h>
#include <RemoteTransmitter.h>

// DHT11 temperature and humidty sensor
#define DHTPIN 3
#define DHTTYPE DHT11 //21 or 22 also an option
DHT dht(DHTPIN, DHTTYPE);
unsigned long readTime;
unsigned long time;
// Analog 0 is the input pin
int lightPinIn = 0;

// Receiver/Transmitter pin
ActionTransmitter actionTransmitter(9);

// relays
#define RELAY1  5
#define RELAY2  6
#define RELAY3  7
#define RELAY4  8

// defines and variable for sensor/control mode
int senseMode = 0;

// Update these with values suitable for your network.
byte mac[]    = {  0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 102);
IPAddress server(192, 168, 0, 110);
char message_buff[100]; // this buffers our incoming messages so we can do something on certain commands

EthernetClient ethClient;
PubSubClient client(ethClient);


void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  int i=0;
  for (i=0;i<length;i++) {
    Serial.print((char)payload[i]);
    message_buff[i] = payload[i];
  }
  message_buff[i] = '\0';
  String msgString = String(message_buff);
  if (msgString.equals("OFF1")) {
    digitalWrite(RELAY1, HIGH);
    client.publish("openhab/himitsu/command","Relay 1 OFF");
  }
  else if(msgString.equals("ON1")){
    digitalWrite(RELAY1, LOW);
    client.publish("openhab/himitsu/command","Relay 1 ON");
  }
  if (msgString.equals("OFF2")) {
     digitalWrite(RELAY2, HIGH);
    client.publish("openhab/himitsu/command","Relay 2 OFF");
  }
  else if(msgString.equals("ON2")){
     digitalWrite(RELAY2, LOW);
    client.publish("openhab/himitsu/command","Relay 2 ON");
  }
  if (msgString.equals("OFF3")) {
     digitalWrite(RELAY3, HIGH);
    client.publish("openhab/himitsu/command","Relay 3 OFF");
  }
  else if(msgString.equals("ON3")){
     digitalWrite(RELAY3, LOW);
    client.publish("openhab/himitsu/command","Relay 3 ON");
  }
  if (msgString.equals("OFF4")) {
     digitalWrite(RELAY4, HIGH);
    client.publish("openhab/himitsu/command","Relay 4 OFF");
  }
  else if(msgString.equals("ON4")){
     digitalWrite(RELAY4, LOW);
    client.publish("openhab/himitsu/command","Relay 4 ON");
  }
    if (msgString.equals("RemoteOFF1")) {
     actionTransmitter.sendSignal(1, 'A', false);
    client.publish("openhab/himitsu/command","Remote Switch 1 OFF");
  }
  else if(msgString.equals("remoteON1")){
     actionTransmitter.sendSignal(1, 'A', true);
    client.publish("openhab/himitsu/command","Remote Switch 1 ON");
  }
    if (msgString.equals("RemoteOFF2")) {
     actionTransmitter.sendSignal(1, 'B', false);
    client.publish("openhab/himitsu/command","Remote Switch 2 OFF");
  }
  else if(msgString.equals("remoteON2")){
     actionTransmitter.sendSignal(1, 'B', true);
    client.publish("openhab/himitsu/command","Remote Switch 2 ON");
  }
    if (msgString.equals("RemoteOFF3")) {
     actionTransmitter.sendSignal(1, 'C', false);
    client.publish("openhab/himitsu/command","Remote Switch 3 OFF");
  }
  else if(msgString.equals("remoteON3")){
     actionTransmitter.sendSignal(1, 'C', true);
    client.publish("openhab/himitsu/command","Remote Switch 3 ON");
  }
  if (msgString.equals("reboot")) {
     actionTransmitter.sendSignal(1, 'C', false);
     delay(20000);   
     actionTransmitter.sendSignal(1, 'C', true);
  
  }

}


void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("arduinoClient")) {
      Serial.println("connected");
      // Once connected, publish an announcement...
      client.publish("openhab","himitsu sensor, reporting in");
      // ... and resubscribe
      client.subscribe("openhab/himitsu/command");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

void setup()
{
  Serial.begin(9600);

  client.setServer(server, 1883);
  client.setCallback(callback);

  Ethernet.begin(mac);
  
  dht.begin();
  // Allow the hardware to sort itself out
  delay(1500);
  Serial.println(Ethernet.localIP());
  readTime = 0;

  // Relay board pins
  pinMode(RELAY1, OUTPUT);
  pinMode(RELAY2, OUTPUT);
  pinMode(RELAY3, OUTPUT);
  pinMode(RELAY4, OUTPUT);

  //Relay default off
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);

}

void loop()
{
  
  if (!client.connected()) {
    reconnect();
  }
  
  client.loop();
  
  //check if 6 seconds has elapsed since the last time we read the sensors. 
  if(millis() > readTime+6000){
    sensorRead();
  }
        
  // publish light reading every 5 seconds
  if(millis() > (time + 5000)) {
    sensorReadlight();
  }

}



void sensorReadlight()
{
  time = millis();

  // read from light sensor (photocell)
  int lightRead = analogRead(lightPinIn);  
  String pubString = String(lightRead);
  pubString.toCharArray(message_buff, pubString.length()+1);
  Serial.println(message_buff);
  client.publish("openhab/himitsu/lightsensor", message_buff);
  }

void sensorRead(){
  readTime = millis();
 // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  char buffer[10];
  dtostrf(t,0, 0, buffer);
  client.publish("openhab/himitsu/temperature",buffer);
  //Serial.println(buffer);
  dtostrf(h,0, 0, buffer);
  client.publish("openhab/himitsu/humidity",buffer);
  
  //client.publish("inTopic/humidity",sprintf(buf, "%f", h));

}

Your ardunio shield doesn't look to have a network connection.

The response is actually from the gateway (Your router), the ping made it to the gateway, but the host (Ardunio) is unreachable.

Is the LED on the shield marked "LINK" lit? It should flash when it receives data, but it should remain lit when a link is active (Network connected).

  String msgString = String(message_buff);
  if (msgString.equals("OFF1")) {

Tossing away resources on the String class, just so you can avoid using strcmp() is silly. The String class does, in the equals() method.

tcowell:
Your ardunio shield doesn't look to have a network connection.

The response is actually from the gateway (Your router), the ping made it to the gateway, but the host (Ardunio) is unreachable.

Is the LED on the shield marked "LINK" lit? It should flash when it receives data, but it should remain lit when a link is active (Network connected).

Yes the LINK LED is lit. I noticed something its getting a dynamic ip 198.168.0.108 instead of having the ip i gave it 192.168.0.102. And the dynamic ip is pingable.

Then simply login to the router, set that IP as static to the Shield, then update you code with the newly acquired static IP.

qrion:
Yes the LINK LED is lit. I noticed something its getting a dynamic ip 198.168.0.108 instead of having the ip i gave it 192.168.0.102. And the dynamic ip is pingable.

some routers get testy when you assign a static IP outside of its DHCP range.

Have you tried giving your arduino a static IP within the range that your router doles out?

The code you posted is using DHCP to obtain the network settings. Are you certain the router's DHCP server is issuing 192.168.0.102?

PaulS:
Tossing away resources on the String class, just so you can avoid using strcmp() is silly. The String class does, in the equals() method.

I find this message offensive. The OP is a newbie, he/she may not have learned about strcmp() yet. String.equals() is easier to use. And the OP may be planning to a whole lot more sting manipulation in the program when the initial network problem is solved.
And anyway commenting on the use of String class has nothing whatsoever to do with the OP's question.

String.equals() is easier to use.

That is absolute nonsense.

   String crap = "Pissing away resources";
   if(crap.equals("Pissing away resources"))
   {
      Serial.println("They match");
   }

is NO easier than

   char *better = "Saving resources";
   if(strcmp(better, "Saving resources") == 0)
   {
      Serial.println("They match");
   }

Only a fool would advocate pissing away resources over spending 5 minutes googling a better way.

Feel free to feel offended again.

It's more your tone I was offended by

Tossing away resources on the String class, just so you can avoid using strcmp() is silly.

Why not "The String class wastes resources, a better way might be to use strcmp()"?
And why should someone google something like

"In C, is there a more efficient way of comparing strings than using the String class?"

when that bit of their code works fine anyway? Why would they even think of doing that?

And I still maintain that String.Equals() is easier to understand/use. It's natural language. And you don't need the '==0' at the end.

It's more your tone I was offended by

Well, that's too bad. Sometimes you have to be brutal to make a point.

And why should someone google something like

I never suggested that. You said that strcmp() was too hard to use. I suggested that googling the function would show that that assertion was silly. Whether one of the strings to compare appears before the function or not, does not make one method of comparing strings harder to use than another.

when that bit of their code works fine anyway?

When one posts here, and says "My code doesn't work", how can you KNOW that "that bit of their code works fine"? If the problem with the Arduino not responding to pings is because the code has used up all the SRAM and crashed, then any assertion that the rest of the code is fine is WRONG.

I look at places where code is obviously wasting memory in ALL code that is posted, and point that waste out.

And I still maintain that String.Equals() is easier to understand/use.

You are entitled to your opinion. No matter how wrong it is. 8)

Well i got it working a day after i wrote the post. All that was missing was ip in.

Ethernet.begin(mac, ip);

PaulS:
Well, that's too bad. Sometimes you have to be brutal to make a point.

Didn't Stalin first say that?

:-\