Problems with ENC28J60 losing connection/freezing (using UIPEthernet or etherShield)? READ THIS!
-
For TCP you are right - the boolean return-value is not required as the library does free memory not before a packet is acknowledged or the connection is closed. I guess here I can remove some code from the lib. UDP does not retransmit and would loose packets just because of collisions. UDP should loose packets only when they time out or get dropped due to physical failure.
-
Hi Everyone,
I wanted to report my experience here as I thought you all would probably be able to understand it far better than I can, and maybe even find it interesting. I'm a newbie, so bare with me...
For the longest time, I was using the UIPEthernet library 'improperly'. I wanted to open a connection and keep it opened(indefinitely if necesssary), and "stream" my data to my program - a long string of text parameters, about 200 bytes. The easiest way to do this seemed to be just simply not disconnect. Using the basic examples as a starting point however, this results in the need to "ping" the Arduino every time you want data, resulting in a perpetual game of "ping/pong". The connection never actually closes, but using client = server.available(); to call your actions causes this I guess, since it only returns 1 if there is data waiting to be read. This is what all of the examples seemed to use, so I thought it was the right way. Adding fuel to the flames, I found a blog that seemed to call this a bug, and showed how to fix it with the stock Ethernet library, so I thought I was on the right track. I wanted to use UIPEthernet though, and the ping/pong scheme seemed workable, if kludgey, so I implemented it. I had it working for a long time - a couple of months - without any trouble overall. I mean, I could open a telnet session with PuTTY and have it sit there open for days and randomly "ping" the arduino and get a packet.
However, I just knew it didn't seem right, and like I said it was kludgey, made all of the other things I was having the Arduino do all the more difficult. I wanted to fix it, to the point of making a fool of myself asking about it on the Arduino forums.
So anyway, after studying some other examples for a while, and reading some other things, I figured out the "proper" way to do things - store your (up to 4 connections) in an array; that way you can check them for (dis)connections, send data to individual ones, etc. Elementary I assume, but like I said .. you gotta start somewhere. ;) Fantastic! No more pinging!
Except now I've lost the stability I had. Couldn't keep a connection for more than 12 hours it seemed, let alone the days and weeks I had before. Frustrated, I basically dropped the project for a couple of weeks. The other day I decided to pick it up in earnest again. I couldn't find anything wrong with my code after going over and over it, so I hit google again..
This thread came up, and seemed pertinent. I installed the fix version of the library, and what do you know - stability. :) Been almost 48 hours now. Nothing else has changed, so I'm going to call it fixed. I don't really know what to make of all that, but I find it interesting that I had such great stability using the first method overall, even though it was "wrong".
I want to thank everyone for their efforts, especially Norbert for the superb support of his library. It truly makes it a pleasure to use. I can only hope I can contribute to the general community on such a high level one day.
Edit: 72 hours+ and still going strong.
-
Using official Arduino Mega ADK via proper 3.3V level shifter. Powering ENC with 3.3V from the same Arduino.
ENC stopped responding to pings after just one night. The main program continues to work.
The main program polls 1-wire temperature sensor, displays the temperature to an SPI display and controls another device using standard digital outputs.
I strongly suspect that the problem is in Errata 14.
If I have some time (which is not likely to happen any time soon) I'll look into it and will try to fix it for EtherCard library as it is smaller for I will need all that stuff to fit into Pro Mini based on ATmega 328.
-
ha!
everyone have to care about the source. Have t measure the source current and have added a multimeter.This probably add very small voltage drop, but it was more than enough for ping to start loosing packets! It is very sensitive to the power source. After adding just 0.2V pings stop been lost.
-
ha!
everyone have to care about the source. Have t measure the source current and have added a multimeter.This probably add very small voltage drop, but it was more than enough for ping to start loosing packets! It is very sensitive to the power source. After adding just 0.2V pings stop been lost.
-
@axillent said:
After adding just 0.2V pings stop been lost.
You're saying that you got it back to life without doing a reset or interrupt the supply first?
@m26872 said:
You're saying that you got it back to life without doing a reset or interrupt the supply first?
I'm not looking for the extreme recovery abilities)
My steps are:-
multimeter added to measure current between +3.3V source and VCC pin on ENC shield
-
power on
-
result - many ping were lost
-
power off
-
3.3V source was turned 0.2V up
-
power on
-
result - none of ping were lost
-
-
So glad to have found this thread! Sounds like the exact problem I've been having. Ethernet gateway, with enc28j60 shield would randomly stop responding to Vera, to telnet (on 5003) and to pings. Sometimes in hours, occasionally making it a few days. Looking at my sensors, the radio stack is still working fine, the Ethernet side of the GW is just a dead stick.
I replaced my UIPEthernet files with the ones from GitHub above, disabled DEBUG and UDP to get it to fit, re-compiled, and re-deployed. Will report back how it goes!
BTW - the statement above says: "•DON'T activate the DEBUG-flag in MyConfig.h because this definitely will 'break' the gateway." I had to turn off DEBUG to fit the code on my UNO anyway, but I'm curious to why having DEBUG on breaks gateways?? (I had DEBUG on in my previous version with the old UIPEthernet files.. Did it contribute to my issue?).
-
My Mega app was surviving maybe as much as 5 minutes using the UIPEthernet library for Arduino >= 1.5. I made the changes as you suggest noting in particular that the reset has to come first. It's now been running flawlessly for 48hrs. I have have great hopes for this continuing.
I don't understand why this is still not in the main distribution after so long.
Anyway many thanks for posting this solution. It's a lifesaver.
-
Thank you for this post! Saved the day!
Just for information, im using EtherShield, with this lib: https://github.com/jonoxer/etherShield/blob/master/enc28j60.c
(it has ugly limitations, but has the smallest memory requirement in my case)The solution fits almost exactly, with some small modifications (around line 290):
if( (enc28j60Read(EIR) & EIR_TXERIF) ) { enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_TXRST); enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_TXRST); enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, EIR, EIR_TXERIF); // Might be overkill but advised by Microchip Errata point 12, //MagKas 2014-10-25 }Thanks again!
-
HI! Thanks for the topic! I'm new on this forum and I'm using enc28j60 with UIPE Lib. I have a lot of hang-up in my sketch.
Can somebody tell me wich is the best adapter-library combination to make a secure client-server arduno based sensor?
enc28j60 O WIZNET5100? UIPEEthernet, Ethercard or EtherShield ?The solution proposed is modify enc28j60.cpp about line 215
Enc28J60Network::sendPacket(memhandle handle)
.....
if( (readReg(EIR) & EIR_TXERIF) )
{
writeOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_TXRTS);
}
...
}by
if( (enc28j60Read(EIR) & EIR_TXERIF) )
{
enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_TXRST);
enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_TXRST);
enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, EIR, EIR_TXERIF);
}It is correct???
Sorry for my English. Thanks again. Daniel
-
HI! Thanks for the topic! I'm new on this forum and I'm using enc28j60 with UIPE Lib. I have a lot of hang-up in my sketch.
Can somebody tell me wich is the best adapter-library combination to make a secure client-server arduno based sensor?
enc28j60 O WIZNET5100? UIPEEthernet, Ethercard or EtherShield ?The solution proposed is modify enc28j60.cpp about line 215
Enc28J60Network::sendPacket(memhandle handle)
.....
if( (readReg(EIR) & EIR_TXERIF) )
{
writeOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_TXRTS);
}
...
}by
if( (enc28j60Read(EIR) & EIR_TXERIF) )
{
enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_TXRST);
enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_TXRST);
enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, EIR, EIR_TXERIF);
}It is correct???
Sorry for my English. Thanks again. Daniel
-
@m26872 Thanks!
Wich library is better to use? UIPEthernet works well with W5100? I need a library that can handle client/server request.
Thanks very much!!! -
I choose to reply to this very old topic because I updated to the latest UIPEthernet and this issue is still happening to me. I was about to replace it with a W5100 but came across this and tried it, compiled, uploaded, and here it goes. 24 hours of continuous web serving using an Arduino Mega 2560 and still counting!
I wish this get incorporated into UIPEthernet
-
I choose to reply to this very old topic because I updated to the latest UIPEthernet and this issue is still happening to me. I was about to replace it with a W5100 but came across this and tried it, compiled, uploaded, and here it goes. 24 hours of continuous web serving using an Arduino Mega 2560 and still counting!
I wish this get incorporated into UIPEthernet
@mhdayusuf Do you have a copy of the changes you made? I am quite struggling to make it work and is not obvious to me what changes you made... Thanks.