Pages: [1] 2 3 ... 11   Go Down
Author Topic: new library UIPEthernet: uIP adapted to Arduino for ENC28J60  (Read 25852 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 10
Posts: 170
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

e.g:
Code:
#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);

  UIPEthernet.begin(mac,myIP);

  server.begin();
}

void loop() {

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

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

Have fun!

- Norbert

« Last Edit: February 14, 2014, 09:37:13 am by ntruchsess » Logged

Offline Offline
Full Member
***
Karma: 10
Posts: 170
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello.

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


greetings
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley 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 smiley. 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
Logged

Offline Offline
Full Member
***
Karma: 10
Posts: 170
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley
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:
   
        delay(80);
        while (iSMTPClient.available()>0) {
                c=iSMTPClient.read();
        }
        delay(80);
        while (iSMTPClient.available()>0) {
                c=iSMTPClient.read();
        }
        iSMTPClient.stop();
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 ?
Logged

Offline Offline
Full Member
***
Karma: 10
Posts: 170
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Full Member
***
Karma: 10
Posts: 170
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Offline Offline
Full Member
***
Karma: 10
Posts: 170
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Excellent,

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  smiley-grin
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley

Thank you for your help

Code:
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 ?
    server.available();
  }
}

void loop()
{
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client)
  {
    while (client.connected())
    {
      if (client.available())
      {
        if (blah blah)
          quick_stuff();
        else
          long_stuff();
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
  }
}
Logged

Offline Offline
Full Member
***
Karma: 10
Posts: 170
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

use Ethernet.maintain() for that.

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

- Norbert
« Last Edit: December 05, 2013, 12:57:26 am by ntruchsess » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Norbert,

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.

 
« Last Edit: December 05, 2013, 08:11:30 am by Charly86 » Logged

Pages: [1] 2 3 ... 11   Go Up
Jump to: