Getting IP 0.0.0.0 when directly connecting to laptop via Ethernet cable

The code didn't "get" an IP address, it was self-assigned:

All that proves is that the processor can talk to the Ethernet controller over SPI, it says nothing about establishing a connection between the Ethernet controller and the laptop. My next debugging step (as I already suggested) would be to connect both the W5500 and the laptop to a 10/100 or a 10/100/1000 Ethernet switch rather than directly. That would eliminate any PHY-to-PHY issues as the switch PHYs will do automatic cross-connection correction. But apparently @laukejas won't cough up the $10 for a cheap Ethernet switch.

IDK if that's really the issue. They indicated that the solution would ideally be plug & play, and I can see how it's inconvenient if the device comes with an ethernet switch and wall wart tie-wrapped onto it.

It wasn't my proposed solution, rather a testing technique to get there. Right now he's just throwing crap at the wall hoping something will stick.

Also, even if the code in Post 20 did manage to connect to the Ethernet controller over SPI, it wouldn't work. First, it depends on DHCP which isn't there and second it tries to connect to http://example.com/index.html over the internet which also can't work in a point-to-point connection with the laptop.

1 Like

I'm sorry, I didn't want to make it look like I'm ignoring your advice. Locally the cheapest switch I can get is 150€. I ordered a cheap one yesterday (10€) from Ali, but it will take ~2-3 weeks before it gets here and I can use it for testing. So for now I'm just trying to make it work with what I got.

You meant the part in the git page where it says

`Setup.begin(sck, miso, mosi);`

? I did try that, but compiler doesn't recognize "Setup". I figured it must be a mistake, but after looking through the code of the library, I wasn't able to figure out what they meant here.

down a little bit more..
I saw that Setup.begin too, must be a typo..

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF };
W5500Driver driver(5, 26, 27);
SPIClass SPI1(HSPI);

void setup() {

  SPI1.begin(18, 19, 23);

  driver.setSPI(SPI1);
  driver.setSpiFreq(10);
  driver.setPhyAddress(0);

  Ethernet.init(driver);

  Ethernet.begin(mac);

~q

changing thing to use your pins..
maybe something like..

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF };
W5500Driver driver(2);
SPIClass SPI1(HSPI);

void setup() {

  SPI1.begin(14, 12, 13);

  driver.setSPI(SPI1);

  Ethernet.init(driver);

  Ethernet.begin(mac);
}

~q

Damn, I missed that one. Went looking deep into the library code, and didn't read the example. I'm sorry, and thank you for being so patient.

I think I set up it as per example now, but still not working - I think ESP32 is crashing and rebooting every 5 seconds or so with the following code.

/**
 * BasivHttpClient example from the ESP32 HTTPClient library modified for Ethernet.
 */

#include <EthernetESP32.h>
#include <HTTPClient.h>

#define USE_SERIAL Serial
/*
const char* ca = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/\n" \
"MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" \
"DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow\n" \
"SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT\n" \
"GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC\n" \
"AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF\n" \
"q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8\n" \
"SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0\n" \
"Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA\n" \
"a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj\n" \
"/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T\n" \
"AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG\n" \
"CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv\n" \
"bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k\n" \
"c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw\n" \
"VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC\n" \
"ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz\n" \
"MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu\n" \
"Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF\n" \
"AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo\n" \
"uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/\n" \
"wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu\n" \
"X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG\n" \
"PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n" \
"KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n" \
"-----END CERTIFICATE-----\n";
*/

W5500Driver driver(2);
SPIClass SPI1(HSPI);

void setup() {

  USE_SERIAL.begin(115200);
  delay(500);
  while (!USE_SERIAL);

  USE_SERIAL.println();
  Ethernet.init(driver);

  SPI1.begin(2, 12, 13);

  USE_SERIAL.println("Initialize Ethernet with DHCP:");
  if (Ethernet.begin()) {
    USE_SERIAL.print("  DHCP assigned IP ");
    USE_SERIAL.println(Ethernet.localIP());
  } else {
    USE_SERIAL.println("Failed to configure Ethernet using DHCP");
    while (true) {
      delay(1);
    }
  }
}

void loop() {

  HTTPClient http;

  USE_SERIAL.print("[HTTP] begin...\n");
  // configure traged server and url
  //http.begin("https://www.howsmyssl.com/a/check", ca); //HTTPS
  http.begin("http://example.com/index.html");  //HTTP

  USE_SERIAL.print("[HTTP] GET...\n");
  // start connection and send HTTP header
  int httpCode = http.GET();

  // httpCode will be negative on error
  if (httpCode > 0) {
    // HTTP header has been send and Server response header has been handled
    USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

    // file found at server
    if (httpCode == HTTP_CODE_OK) {
      String payload = http.getString();
      USE_SERIAL.println(payload);
    }
  } else {
    USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
  }

  http.end();

  delay(5000);
}

Can't figure out what the exception is, since there's no error catching in embedded programming. But it's not even starting the setup() (I tried placing Serial.println("test") at the very beginning of setup(), and it is not printed), so I assume it must be crashing at SPIClass SPI1(HSPI).

2 is CS that is set

try this..

~q

it usually throws a GURU Meditation error..
presents you with a call stack, there is a program to decipher this to more understandable..
thinks it esp exception decoder..
~q

Okay, tried it, this is my code:

/**
 * BasivHttpClient example from the ESP32 HTTPClient library modified for Ethernet.
 */

#include <EthernetESP32.h>
#include <HTTPClient.h>

#define USE_SERIAL Serial
/*
const char* ca = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/\n" \
"MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" \
"DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow\n" \
"SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAh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PXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo\n" \
"uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/\n" \
"wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu\n" \
"X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG\n" \
"PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n" \
"KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n" \
"-----END CERTIFICATE-----\n";
*/

W5500Driver driver(2);
SPIClass SPI1(HSPI);

void setup() {
  USE_SERIAL.begin(115200);
  delay(500);
  while (!USE_SERIAL);

  driver.setSPI(SPI1);

  USE_SERIAL.println();
  Ethernet.init(driver);

  SPI1.begin(14, 12, 13);

  USE_SERIAL.println("Initialize Ethernet with DHCP:");
  if (Ethernet.begin()) {
    USE_SERIAL.print("  DHCP assigned IP ");
    USE_SERIAL.println(Ethernet.localIP());
  } else {
    USE_SERIAL.println("Failed to configure Ethernet using DHCP");
    while (true) {
      delay(1);
    }
  }
}

void loop() {

  HTTPClient http;

  USE_SERIAL.print("[HTTP] begin...\n");
  // configure traged server and url
  //http.begin("https://www.howsmyssl.com/a/check", ca); //HTTPS
  http.begin("http://example.com/index.html");  //HTTP

  USE_SERIAL.print("[HTTP] GET...\n");
  // start connection and send HTTP header
  int httpCode = http.GET();

  // httpCode will be negative on error
  if (httpCode > 0) {
    // HTTP header has been send and Server response header has been handled
    USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

    // file found at server
    if (httpCode == HTTP_CODE_OK) {
      String payload = http.getString();
      USE_SERIAL.println(payload);
    }
  } else {
    USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
  }

  http.end();

  delay(5000);
}

ESP32 is still crashing and rebooting :confused:

move the SPI1 begin, before you assign it to the driver..
~q

Did that. Still getting the same. ESP32 crashes before it even reaches setup().

doesn't like how the spi got created??

maybe like this..

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF };
W5500Driver driver(2);

SPIClass *hspi = NULL;


void setup() {
//create and init hspi object..
hspi = new SPIClass(HSPI);
hspi->begin(14, 12, 13, 2);  
pinMode(2, OUTPUT); 

  driver.setSPI(hspi);
  Ethernet.init(driver);
  Ethernet.begin(mac);
}

~q

Still can't get it to work, with this code (hope I understood you right):

/**
 * BasivHttpClient example from the ESP32 HTTPClient library modified for Ethernet.
 */

#include <EthernetESP32.h>
#include <HTTPClient.h>

#define USE_SERIAL Serial
/*
const char* ca = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/\n" \
"MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" \
"DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow\n" \
"SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT\n" \
"GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC\n" \
"AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF\n" \
"q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8\n" \
"SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0\n" \
"Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA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6/DNFu0Qg==\n" \
"-----END CERTIFICATE-----\n";
*/

W5500Driver driver(2);
SPIClass *hspi = NULL;

void setup() {
  hspi = new SPIClass(HSPI);
  hspi->begin(14, 12, 13, 2);  
  pinMode(2, OUTPUT); 

  driver.setSPI(hspi);

  USE_SERIAL.println();
  Ethernet.init(driver);

  USE_SERIAL.println("Initialize Ethernet with DHCP:");
  if (Ethernet.begin(mac)) {
    USE_SERIAL.print("  DHCP assigned IP ");
    USE_SERIAL.println(Ethernet.localIP());
  } else {
    USE_SERIAL.println("Failed to configure Ethernet using DHCP");
    while (true) {
      delay(1);
    }
  }
}

void loop() {

  HTTPClient http;

  USE_SERIAL.print("[HTTP] begin...\n");
  // configure traged server and url
  //http.begin("https://www.howsmyssl.com/a/check", ca); //HTTPS
  http.begin("http://example.com/index.html");  //HTTP

  USE_SERIAL.print("[HTTP] GET...\n");
  // start connection and send HTTP header
  int httpCode = http.GET();

  // httpCode will be negative on error
  if (httpCode > 0) {
    // HTTP header has been send and Server response header has been handled
    USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

    // file found at server
    if (httpCode == HTTP_CODE_OK) {
      String payload = http.getString();
      USE_SERIAL.println(payload);
    }
  } else {
    USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
  }

  http.end();

  delay(5000);
}

I just get compilation error on line driver.setSPI(hspi);,

 error: invalid user-defined conversion from 'SPIClass*' to 'SPIClass&' [-fpermissive]

I confess at this point I am completely at a loss of what we're doing here, and blindly following along what you're suggesting. I really appreciate you taking the time to help me here. But I also can't help but feel we're off to the deep end, this shouldn't be so complicated, straying so far away from the examples of these libraries... Something is off here, but I can't figure out what.

agree..
i'd go back to the lib that took you assignment..
or even the first lib you tried..

but then again trying to get anything else to work on these cams which are already pretty full can be quite tricky..

don't mind poking at it but not sure how far we will get..

the new lib is looking on the wrong pins which is why it does not find the module..

~q

WOW!!! I didn't consider regionally-dependent highway robbery! I was just poking on Amazon. A 5-port 10/100 switch is is available for $9 USD. If you splurge and shell out $16 USD, you get 10/100/100. Both delivered by Monday.

What good would that do to OP? A switch isn't a router.

Again, I was only proposing it as a diagnostic test in case the direct connection to the laptop was causing a problem for some reason. While most modern PHYs handle Polarity and TX / RX reversal automatically, I'm not familiar with the components on OP's Ethernet shield. A switch would have PHYs to take care of that. They also typically have link and activity LEDs that are useful for debugging.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.