-
Notifications
You must be signed in to change notification settings - Fork 11
Can't connect (self-assigns IP after 5') #17
Comments
I just tried your sketch and obtained an IP address:
I also tried with the UDP sketch from the other issue and it works:
with this sketch which is a mix of the Udp demo and your sketch: #include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <W5500lwIP.h>
// Using GPIO16 as CS
Wiznet5500lwIP eth(16);
WiFiUDP Udp;
unsigned int localPort = 8888; // local port to listen on
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE + 1]; //buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged\r\n"; // a string to send back
void setup ()
{
Serial.begin(115200);
Serial.println("");
// WiFi.mode(WIFI_OFF);
SPI.begin();
// SPI.setBitOrder(MSBFIRST);
// SPI.setDataMode(SPI_MODE0);
// Slow down because long (~20cm) wires and breadboard
SPI.setFrequency(10000000); // Works up to 80M
eth.setDefault(); // use ethernet for default route
bool r=eth.begin(); // default mtu & mac address
if(!r) {
Serial.println("Error initializing eth");
while(true) delay(1000);
}
// This loop is odd, do not refer to it as a good example.
// Better example will be provided,
// why: `delay()` requires changes like in
// https://github.com/esp8266/Arduino/pull/6212
// to use the usual loop waiting for dhcp response
while (!eth.connected())
{
Serial.print(".");
for (int i = 0; i < 500; i++)
if (eth.connected())
break;
else
delay(1);
}
Serial.print("My IP address: ");
Serial.println(eth.localIP());
Udp.begin(localPort);
}
void loop ()
{
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize) {
Serial.printf("Received packet of size %d from %s:%d\n (to %s:%d, free heap = %d B)\n",
packetSize,
Udp.remoteIP().toString().c_str(), Udp.remotePort(),
Udp.destinationIP().toString().c_str(), Udp.localPort(),
ESP.getFreeHeap());
// read the packet into packetBufffer
int n = Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
packetBuffer[n] = 0;
Serial.println("Contents:");
Serial.println(packetBuffer);
// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
}
/*
test (shell/netcat):
--------------------
nc -u 192.168.esp.address 8888
*/ @NdK73 |
Your sketch seems to work (partially) after changing CS from GPIO2 to GPIO16. Tks.
Then a lot of "read error?" messages. But at least this time I saw the DHCP request (tcpdump from my PC) and the IP gets assigned. UDP rx seems to work:
I'll have to test multicast too (my domotic protocol uses it) as soon as I understand what was wrong in my sketch and fix the "read error?" messages. PS: thanks for the fast answer and all the work you're doing! |
It stops working (does not get address, but W5500 is recognized by begin() ) if I change CS pin. Tried with GPIO2 and GPIO0 with no luck. |
About read error message, Serial.println("read error len=%d tot_len=%d?\r\n",(int)len,(int)tot_len); (look for |
Done (printf instead of println). It now prints:
|
I have three eth modules (w5100, w5500, enc28j60). Every one is heating a lot while working. |
You can try to replace this line by
Filtering will be anyway done by lwIP. If this removes the issue for you, then I'll check the other drivers. |
My module is not heating abnormally. I only connected 5V line, not the 3v3 one. And it's from the same USB that's powering the D1mini. With line 389 replaced as given the messages are gone. |
No hope for 2.7.2. It will be 3.0.0 or git head after 2.7.2 is out. |
Then I'll keep gamma installed :) |
Problem confirmed: after 3h it's not answering pings any more. Seems unrelated to DHCP renew, since it's set to 10 days. Tks again. |
I would need to be able to reproduce. What is the running sketch ? |
The one you posted above. Only change: the SPI speed (boosted to 40MHz... Going to try down to 10). |
Already offline at 10MHz :( 2h or less. |
Ah. I have another one - a multiinterface mDNS test - up and running for several hours. Can you compile with every debug option enabled, and add a loop that prints hello every sec or so,
|
I just completed a test: I left the sketch running, pinging it from the reset.
Re: your test, it just started (w/ a slight mod: I'm printing lastTime value before "hearbeat"):
That "wifi evt: 7" makes me think... Could it be that it's connecting BOTH via eth and WiFi? Once it ends I'll try re-enabling Wifi.mode(WIFI_OFF)... |
If WiFi is not turned off, dhcp might stop at some point and put interfaces down. It shouldn't put eth down anyway. I should try and reproduce with that. Yes trying to disable WiFi like you propose is interesting. Mac address is copied then slightly modified for the ethernet case. edit: I'm open for any proposal for the mac update given that we can have more that one external interface. |
I'd combine your method with the masking I suggested, so it's clear it's not an official (IEEE-assigned) address. Anyway ESP8266 doesn't have enough free pins to handle many interfaces, unless it's somehow possible to use the flash SPI bus (that would free 3 more pins) like display "overlay" mode. The currently running test just passed 1024th ping with no issues (up to 1324). So it's quite probably wifi-related. Or a race condition with wifi code. |
Argh. Nope. Died at ping 2096 :( |
miso, mosi and clock are shared, then an additional CS per spi device is needed.
Can you think of a valid mac address based on the STA one and a non zero number (between 1 and 8) ?
Anything relevant on console ? |
Yup. But the other pins are already overloaded: RX/TX for serial, 4/5 for I2C, 0/2/15 should be usable with some tricks, 16 is OK if you don't need deep sleep. An alternative could be to use an I2C expander, but it gets really slow :)
Just add
after
Nothing at all on console: hb messages continue but the network is completely not responsive (does not receive UDP packets). |
Thanks, added I restarted my run to watch heap:
I currently have
|
I don't have periodicFastMs, but changed the hb loop to use that printf every 5s. |
Sorry this is missing:
...
edit later:
played with mDNS and ethernet or AP ("heap" is maxBlock)
|
Now it ran overnight w/o problems. ARGH! Just changing a printf lets it run??? But, returning to original issue, if I just change CS line to GPIO2 or GPIO0, it stops working. How can it be? |
GPIO0 and 2 must have pullups in order the esp can boot. Do you think they can interfere with a CS output pin ? |
No. I'm using a D1mini that already have the needed pullup. And there's another pullup on the W5500 board (that's the reason a buffer transistor is needed when using GPIO15 as CS: it requires to be low at boot). Having two pullups in parallel just makes it a stronger pullup, but the line can still be pulled low w/o problems (I often have 2 or even 3 10k pullups on I2C busses, especially for longer ones). |
I can't say much about hardware issues. I am also using a d1 mini. I shall try to use these gpio as CS. |
Do not overload regulators! Both boards have their own. Just connect the 5V on the W5500, not the 3v3. This way it's powered directly from the USB and D1's regulator won't overheat. |
That's not what I did but you're right (my W5500 5v is not connected, I use the d1mini's 3.3v for both). Do you think it is worth testing CS due to parallel pullups ? |
That way you're probably overloading it, or at least you're very near the limits.
I just tested it, and pulses on GPIO0 are quite good: from 3.1V down to 0.25V with a bit of overshoot towards 0V. Clean fronts. I'd expect no issues HW-wise. And actually W5500 gets recognized (no error at begin() ). |
Another data point: I've let it run (w/ self-assigned IP) for quite some time (2737 minutes), then reset it and it got an address! CS currently on GPIO0. |
I added a "pinger" that, after 5 failed pings, tries to reset the w5500.
The resetter is like the setup() code, plus eth.end():
IIUC the WDT triggers inside eth.end(). |
This commit adds W5500 W5100 and ENC28j60 drivers from @njh with credits They are available in libraries/ An example is added in W5500 examples directory plus: * Extract dhcp server from lwip2 and add it to the core as a class. It must always be present, it is linked and can be called by fw on boot. So it cannot be stored in a library. * ethernet: static or dhcp works * PPPServer: example * bring WiFi.config() to the lwIP generic interface (argument reorder common function) * move hostname() from WiFI-STA to generic interface * remove non readable characters from dhcp-server comments * dhcp-server: magic_cookie is part of bootp rfc * fixes from d-a-v/W5500lwIP#17 * enable lwip_hook_dhcp_parse_option() * +ethernet tcp client example in w5500 library examples
Hello.
Following directions in other issues, I removed core 2.7.1 and installed your 0.0.3 .
The code I'm compiling is:
It prints "Still unconnected" for about 5 minutes, then self-assigns 169.254.205.199 .
The W5500 board is connected correctly (I think: if I try swapping MISO/MOSI, or unconnecting SCLK or CS I get "Error initializing eth").
I left SPI settings commented after trying 'em and noticing they didn't change anything.
I don't see DHCP requests on my LAN.
The text was updated successfully, but these errors were encountered: