Go Down

Topic: new library UIPEthernet: uIP adapted to Arduino for ENC28J60 (Read 123916 times) previous topic - next topic


Jul 17, 2013, 11:05 pm Last Edit: Feb 14, 2014, 03:37 pm by ntruchsess Reason: 1
Existing enc28j60 libraries for Arduino support tcp in 'single-packet-mode' only (EtherCard comes with brief support to stream multiple-packets, but no real persistent connection). To overcome this limitation I've started to merge the code of Adam Dunkels uIP with the ethershield-lib and code from SerialIP calling the new library 'UIPEthernet'

the 'EchoServer'-example allready runs successfully on Arduino-Uno with cheap enc28j60-breakout-board from eBay. The library implements the same EthernetClient/EthernetServer-API as the stock Ethernet-library.

Code: [Select]

#include <UIPEthernet.h>
#include <UIPServer.h>
#include <UIPClient.h>

UIPServer server = UIPServer(1000);

void setup() {

 uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
 IPAddress myIP(192,168,1,6);



void loop() {

 if (UIPClient client = server.available()) {
   if (client) {
     while (client.available()) {
       int c = client.read();

code is located on github: https://github.com/ntruchsess/arduino_uip

Have fun!

- Norbert


I've added EthernetClient and EthernetServer-like classes so reading data from a Socket as a Stream is possible now. (See example above)



sry to dig up an old topic, but i really have to say: its an awsome lib.

i gave it a short try now (and will try for longer) - and so far its just working fine!

great job ntruchsess



Thanks, thanks, and thanks again.
A full IP Stack is finally available for the enc28j60.
I've done some test with your lib and it works :) And fine. For those are interrested in, you can find them here (in french):http://bibi21000.gallet.info/index.php/fr/domotique/82-arduino-fr/185-arduino-et-enc28j60-ethercard-ou-uipethernet.html

The only small problem is that we must update headers to change the CS pin. Maybe it should be a good idea to pass it in the begin function, like ethercard do.

I've implemented SMTP protocol, and it works :). But I need to solve some memory leaks and optimize memory use. When everything will be done, I can send you a pull request via github.

Thanks ... again


thank you for the feedback :-)

and thank you for blogging about UIPEthernet. I really do like programming but when it comes to distribute the word about it I'm a bit lazy ;-)

- Norbert


Your welcome.
I've spent many days trying to implement smtp using EtherCard ... but never succeed.
And only some hours to do it with your lib  :)
I've fork your repo on githubhere : https://github.com/bibi21000/arduino_uip.
Let me know if you interrested in a pull request.
Implementation of SMTP is done, only a small memory leaks is almost here.
It seems that 15bytes are lost when I try to stop the client :
Code: [Select]
        while (iSMTPClient.available()>0) {
        while (iSMTPClient.available()>0) {

I've added some code to empty the client queue, it reduce memory leaks but it is always here.
I've sent about 900 email this night and only 45bytes lost.
Any idea ?


not sure about the memory-leak as you do a lot of dynamic memory-allocation and I didn't analyse this in detail, but I've left some comments on your commits on Github.

- Norbert


Thanks for your response and comments on github (I've also comment them).
The memory leak does not come from my code, I'm almost sure.
My first test uses array of char, and the memory leak was there too.
It seems that if I close the connection quickly, I lost some bytes (always 15 bytes).
Thanks again
Have a nice day


stop is implemented nonblocking. So if you happen to stop a connection before all packets are sent the connections dynamically allocated memory remains allocated until the packets are actually send. It's freed as soon the latest outgoing packet is acklowledged. You also cannot allocate a new connection on this connection-entry until then (which shouldn't be a problem as there are three more slots available with default-config).

Try calling Ethernet.maintain() (or any other method that dispatches a call to Ethernet.tick()) in a loop for a few 100ms and check for available ram after that.

- Norbert


Hi All,

Well I used uIP long time ago on other microcontroller projects, this code rocks, thank you guys.

If I remember correctly, I tought there was some option to reduce code size by removing some of function of the library, does this apply to this version too ?

I just say that because I will be short in code size and I want to reduce the library code by removing function, for example I do not need iUP respond to ping nor use UDP protocol.

Is there some include define I should change fot this ?

Anyway, having a begin with the option to set the CS pin of the enc28j60 is a excellent idea ;-)

Thanks for your help.


this code rocks, thank you guys.

thank you for the kudos ;-)

If I remember correctly, I tought there was some option to reduce code size by removing some of function of the library, does this apply to this version too ?

you may reduce by aprox. 5kb by switching off UDP (and at the same time DNS and DHCP as this requires UDP). This can be configured in uipethernet-conf.h

If RAM is an issue you may also configure number of concurrent sockets and number of pakets per socket, but this will not reduce the foodprint in flash.



Thanks for this, just what I needed

Shame on me  :smiley-red:, I didn't looked in utility folder...

Good to know for the RAM size also, I will test this tonight  :D


Hi  guys,

I've done little test with this stack, all works fine and even with REST web server API running, Arduino always reply to ping during processing except when I do some time consuming code.

I have now a little question, if in my main loop I process data as the code below, then if I need to call a function that may take long time, how do I in this function (long_stuff() in example below) I do refresh the stack to uIP continue responding to ping ?

Of course I do not want putting flags and manage all in main loop. The stack does not have interrupt of enc28J60 connected, so I can imagine I need to call a callback or refresh function ?

Would be interested to know which  :)

Thank you for your help

Code: [Select]

void quick_stuff (void)
  // very quick stuff does not take long time

void long_stuff (void)
  while (blah blah !!!)
    //do my stuff (may be long)
    // So Here, how to I refresh the uIP stack ?

void loop()
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client)
    while (client.connected())
      if (client.available())
        if (blah blah)
    // give the web browser time to receive the data
    // close the connection:


Dec 05, 2013, 06:54 am Last Edit: Dec 05, 2013, 06:57 am by ntruchsess Reason: 1
use Ethernet.maintain() for that.

Do you make use of a REST-library and if so which one?

- Norbert


Dec 05, 2013, 01:43 pm Last Edit: Dec 05, 2013, 02:11 pm by Charly86 Reason: 1

Thank's, I found it and used it, but it did not solved my problem. But may be I'm in the wrong direction. My problem is that I loose some ping randomly, so I tried to investigate, and searched where are done ping response. Are they done by uIP or by the enc28J60 directly ?

This is very strange, because even with a sketch doing nothing in the main loop (echoserver sample), I loose some ping packet (may be 1 every 50/100 packet).

So I tried ethercard library just to test (spent time to understand that I needed to set CS pin to pin 10 at init because by default it use digital pin 8 )  and then tried the ethernode ino file. No problem, ping are consistent. After I changed the refresh value so my browser will always query the ethercard stack with web server on. Of course after this change, ping varied from 1ms to 50ms but this is normal the app is really stressed (and debug info sent on Arduino Serial) in this case, but I never lost a ping.

Did you encounter this kind of problem ? My desktop and Arduino are located on same cisco switch, I will try to ping from linux computer to be sure, not really always trusting TCP/IP microsoft stack, sometimes I saw strange things.

For the Rest API tried some but I'm writing my own, lot of them used official ethernet shield not the enc28j60 so not the same "process". So instead spending time to search and adapt, I decided to write quickly mine, very basic and simple.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131