Connecting Arduino ethernet shield (ip address - 0.0.0.0)

Hi all,

I need some help to connect my arduino uno R3 and ethernet shield. I don't have a mac address with my shield so I'm using this one: byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

I have receiver module wich receives data from transmitter and I want to save it in database, but there is issue related to the connection. When I print the Ethernet.localIP i observed only 0.0.0.0.

This is the IP address of my local network - char server[] = "192.168.0.106"

You can find my code below:

 #include <Wire.h> // use Wire library for protocol i2c (A4 = SDA & A5 = SCL)
  #include <VirtualWire.h> // use Virtual library for decode signal from Rx module
  #include <SPI.h>
  #include <Ethernet.h>

  
  EthernetClient client;
  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 
  char server[] = "192.168.0.106";
  
  int humidity=0;
  int temp=0;
  int pressure=0;
  char MsgReceived[21]; 
  
 
  void setup() 
  {
     Serial.begin(115200);
	 Ethernet.begin(mac);
      
     Serial.println(Ethernet.localIP());
    
    // Bits per sec
    vw_setup(2000);
    // set pin for connect receiver module 
    vw_set_rx_pin(3);  
    // Start the receiver PLL running
    vw_rx_start();       
  
  }
  void loop()
  {    
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  //Taking the data from the control base
  if (vw_get_message(buf, &buflen)) 
  {
    int i;
    // Message with a good checksum received, dump it. 
    for (i = 0; i < buflen; i++)
    {            
      // Fill Msg Char array with corresponding 
      // chars from buffer.   
      MsgReceived[i] = char(buf[i]);
      //Serial.print(MsgReceived[i]);
    }

    sscanf(MsgReceived, "%d,%d,%d",&humidity, &temp,&pressure); // Converts a string to an array 
    lcd_display();
    memset( MsgReceived, 0, sizeof(MsgReceived));// This line is for reset the StringReceived
  
    Serial.print("Temperature = ");
    Serial.print(temp);
    Serial.println(" *C");
    Serial.print("Pressure = ");
    Serial.print(pressure);
    Serial.println(" Pa");
    Serial.print("humidity = ");
    Serial.print(humidity);
    Serial.println(" %");
     
if (client.connect(server, 80)) {
   Serial.println("CONNECTED");
   client.print( "GET /diplomna/Arduino/add_data.php?");
   client.print("temperature=");;
   client.print( temp);
   client.print("&&");
   client.print("humidity=");
// change this to a print rather than println
   client.print( humidity );
// add a leading space in this println
   client.println( " HTTP/1.1");
// add a second cr/lf here to denote end of header
   client.println();
   client.println( "Connection: close\r\n" );

   while(client.connected()) {
      while(client.available()) {
        char ch = client.read();
        Serial.write(ch);
      }
    }
   client.stop();
   Serial.println("DISCONNECTED");
   }
 else {
   // you didn't get a connection to the server:
   Serial.println("-> connection failed/n");
 }
   delay(10000);
  }
  }

You can find the serial monitor output below:

0.0.0.0
Temperature = 26 *C
Pressure = 997 Pa
humidity = 57 %
-> connection failed/n

I also tried to execute the following example code (DhcpAddressPrinter) and the results are the same - 0.0.0.0

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  // this check is only needed on the Leonardo:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for (;;)
      ;
  }
  // print your local IP address:
  printIPAddress();
}

void loop() {

  switch (Ethernet.maintain())
  {
    case 1:
      //renewed fail
      Serial.println("Error: renewed fail");
      break;

    case 2:
      //renewed success
      Serial.println("Renewed success");

      //print your local IP address:
      printIPAddress();
      break;

    case 3:
      //rebind fail
      Serial.println("Error: rebind fail");
      break;

    case 4:
      //rebind success
      Serial.println("Rebind success");

      //print your local IP address:
      printIPAddress();
      break;

    default:
      //nothing happened
      break;

  }
}

void printIPAddress()
{
  Serial.print("My IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print(".");
  }

  Serial.println();
}

Serial monitor output:
Failed to configure Ethernet using DHCP

I also tried to set the ip address of the shield to be 192.168.137.1 and made the following update:
Ethernet.begin(mac); ===> Ethernet.begin(mac,ip);
The results are the same.

Could you please help me to debug this issue.
Thanks in advance!

Regards,
SK

What is the Ethernet controller chip on your Ethernet shield (check the writing on the largest black chip on the shield?

The Ethernet library is only compatible with the W5100. If you have a W5500 then you need to use the Ethernet2 library, which is available via Library Manager. If you have an ENC28j60 then there are a couple of options, the one I'm familiar with being UIPEthernet. If you have a W5200 then there are a couple of options, one being the Seeed Ethernet v2 library.

Hi pert,

The Ethernet controller chip on my Ethernet shield is W5100.
Also I don't have SD card.

Regards,
SK

OK, then you're correct to use the Ethernet library, as you are doing in your code currently.

f you're not using one of the peripherals in your program, however, you'll need to explicitly deselect it. To do this with the SD card, set pin 4 as an output and write a high to it.

Insure the ICSP pins are seated fully and there are no bad solder joints. Insure there are no solder bridges on the w5100. For examples Google "w5100 solder bridges" and select images.

Also posted at:

If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. When you post links please always use the chain links icon on the toolbar to make them clickable.

Hi pert,

Thank you for pointing that out.

Regards,
Sk

Hi SurferTim,
Thank you for the feedback. Regarding the following comment:

SurferTim:
Insure the ICSP pins are seated fully and there are no bad solder joints. Insure there are no solder bridges on the w5100. For examples Google "w5100 solder bridges" and select images.

I have reviewed the ICSP connection and for bad solder joints and they seem good.

I have two ethernet shields so I think that my issue can be related to the configurations.

Regards,
Sk

Do you have any other hardware connected to the Uno?

I use this sketch to test the SPI connection to the w5100. If the serial monitor displays 192.168..0.2, then that part is ok. If it displays anything else, like 0.0.0.0, then you have a problem there.

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

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,2);

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

  // disable SD card if one in the slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Serial.println("Starting w5100");
  Ethernet.begin(mac,ip);

  Serial.println(Ethernet.localIP());
}

void loop() {
}