4 years, 10 months ago.

UIPServer stops responding

Hi, it's me again :)

In the beggining let me appologize for the wall of text and thank you for all your work in this library :)

I've been using UIPEthernet since you kindly helped me to run it on Nucleo F411RE and it was fun. But when I started to run stability tests on it I noticed something strange. When I start UIPServer it begins to do its job and then just stops. By "stops" I mean it doesn't indicate that there are valid requests waiting (and there are). As a starting point to my further research I used your

Import programWebSwitch_ENC28J60

HTTP Server serving a simple webpage which enables to remotely turn LED1 on/off. Compile, download, run and type 'IP_address/secret/' (don't forget the last '/') into your web browser and hit ENTER.

and added a simple DS1820 to read data from.

When first time I saw that I was afraid that something in my code breaks and that Nucleo hangs, so I have added a Ticker to blink LED1 and to my surprise - it was still blinking even when http reqests stop being processed. Then I added a simple printf:

                size = client.read(buf, size);
                string received((char*)buf);
                // printf added here, commandCount starts at 0 
                // and is incremented after each reqest parsed after this point
                printf("%d", commandCount); 
                printf(" - %s", received.c_str());

And again - LED1 blinks, but after few requests (and that number is not constant, sometimes it runs for 60+ requests, sometimes goes silent after only 2; for now it looks quite random) console stops logging new requests and web clients can't connect to Nucleo (both web browser and my C# service that connects to Nucleo). After that point no new connections to Nucleo succeed and the only solution is to restart it (in fact as a failsafe I have added a Ticker that restarts it if there was no request registered after 100 seconds, but of course that is a temporary solution).

My next guess was that maybe the ENC28J60 does hang or stops parsing packets, but I've enabled printf's in UIPEthernet.cpp in void UIPEthernetClass::tick(void) and it in fact does receive them (and a lot of them to be honest, it logs both IP and ARP packets incoming).

And so I went and asked uncle google what he thinks and after many, many, maaaaaany hours I found this: https://github.com/ntruchsess/arduino_uip/issues/30 and boy I was glad - I wasn't the only one hitting my head :) It looks like Norbert Truchsess was able to fix this behaviour (https://github.com/ntruchsess/arduino_uip/commit/027171ee990ee8a54e40a102f56cdf17897e45a0) in his andruino library and I was even happier... But when I tried to modify your version of the library I have noticed two things: first of all your library was created after that fix was implemented and secondly - you have modified the code a lot and I couldn't figure out how to include his fix into your code and if it is necessary in the first place.

What I tried was to change #define's as he did in UIPClient.h and modify UIPClient.cpp to reflect that but I was aware that changing this won't fix the problem. Then I have changed UIPClient.cpp from:

if (data)


if (data && data->state)

but that didn't help neither. Then I've tried to change UIPServer.cpp in UIPClient UIPServer::available(void) from:



if(UIPClient::_available(u) && u->state & UIP_CLIENT_REMOTECLOSED)

and now I got some results... But "not perfect" is a mild understatement :) While requests are being logged (in that first place I have showed at the beggining), the clients don't receive any response :/ So I've reverted all my changes and as a temporary solution right after http_send I call client.stop(). That somehow helps, server stops after more requests but still stops nevertheless. I tried to make requests that have "Connection: Close" header (previously I tried with "Connection: Keep-Alive" - same result) but that didn't help neither.

While I'll try to work on that some more I was hoping you may be willing to look into that as well :)

On a side note - do you have by any chance mbed version of the HardwareSerial.h that can easily be used to debug this library? Out of hurry I ended up replacing Serial.print's with simple printf's, but that is a tedious work and before I start to write my own version of that helper I prefer to ask first, reinvent the wheel later :)

Question relating to:

mbed library for ENC28J60 Ethernet modules. Full support for TCP/IP and UDP Server, Client and HTTP server (webserver). DHCP and DNS is included. client, ENC28J60, ethernet, server, uIP, UIPEthernet

1 Answer

4 years, 10 months ago.


I have updated the UIPEthernet library to be in line with the one released for Arduino (version 1.09). Thanks to the tremendous work done by Norbert this should now fix the leaking client-data caused by race-condition on remote close. Unfortunately I did not have time to run a thorough long term test. Please let me know how it works.



Accepted Answer


Thank you very much (and BIG thank you to Norbert, if he ever gets here) - it looks like it worked like a charm. Right now my code is running for 18+ hours and no request got lost - 7691 requests sent every 9 seconds, 100% success rate :) I'm going to let it run some more, but already it is a great improvement and it looks very promising. Now I'm going to run tests on UDP client and server and see how it goes.

Thank you once more,


posted by Trash Bin 09 Mar 2015

Hello, I have imported your latest code last week and facing the same problem. How should I update it? Thanks a lot

posted by Ahmet Bahar 13 Jun 2016

Hello Ahmet,
Which mbed platfrom are you using? The UIPEthernet library depends on the millis function which requires SysTick . I have recently learnt that unfortunately SysTick isn't available on each mbed board. To test millis please run the code available here.

posted by Zoltan Hudak 14 Jun 2016

Hi Zoltan, Thanks for your kind reply. I am using Nucleo-F103RB platform. But it is a cheap clone, not the original. And also the millis code you have send has no output. I have changed to Millis_start to startMillis as in the millis.cpp code. Thanks for your time. Any recommendation will be helpful to decide to continue with this platform or use a higher level platform. Regards.

posted by Ahmet Bahar 17 Jun 2016