Enc28J60 socket API

Hi, all.

I try to write socket API for enc28j60 ethernet but it seems to be very hard.

None of dozen of libs for enc28j60 including turicas(GitHub - turicas/Ethernet_ENC28J60: [NOT MAINTAINED, NOT COMPLETED] Implementation of an Arduino-compatible socket layer library that uses Microchip ENC28J60 Ethernet controller.), simon monk's (Dr. Monk's DIY Electronics Blog: Simplified Ethernet Library for 28J60 Shield), ethercard (GitHub - njh/EtherCard: EtherCard is an IPv4 driver for the ENC28J60 chip, compatible with Arduino IDE) work properly.
Some stops to response to ping after few ping successfull pings, some just don't work for me for some strange reason, some of them does not allow to send response after it's sent once.

The only lib that seems to be good is uIP port for AVR (GitHub - sde1000/NanodeUIP: Port of uIP library to Nanode) and it already has psocks libs which provides socket API.
But it does not work in some cases (f.e. when response is sent right after data is received) and it's pretty difficult to debug network packets (~10.000 lines without debugger).
I've spent almost 2 months trying to make it working and finally failed)

Any ideas how to get functionality similar to w5100 lib?
The next methods are required:

bool available();
int read();
void write(int);

Thanks in advance.

I was able to do the same (GitHub - 4ntoine/ArduinoCommander-ethernet: Arduino sketch for ArduinoCommander (ethernet support)) in few hours for W5100-based ethernet shield since i finally received it. May be, someone will be more lucky with Enc28J60 than me :slight_smile: Anyone? Contribution · 4ntoine/ArduinoCommander-ethernet Wiki · GitHub

Hello,

I tried the libraries as well, and indeed it if far from obvious. My HW is a DINo from KMtronic, and I managed to get the web server example (using an old, maybe modified Ethershield) running. Ethercard always failed, though it looks to be smarter and more optimized. I consider using the Nanode variant, did you try that one ?

Yes, i played with Nanode a week or two.
It is designed to reply to GET response once so i was unable to work with it as with stream (use write(int outComingByte) method)

Do you think it would be feasible to align the library API with the Wiz5100 one ? How complex would that be ? Because things like IPAddress class etc. should be the same, shouldn't they ?

Very complex, I believe.

tochinet:
Do you think it would be feasible to align the library API with the Wiz5100 one ? How complex would that be ? Because things like IPAddress class etc. should be the same, shouldn't they ?

Yes it would be great! Turicas tried to do the same https://github.com/turicas/Ethernet_ENC28J60:

In a near future I want to replace all ip_arp_udp_tcp layer in the socket layer, so the architecture will be more like the standard Ethernet library:

{Ethernet.cpp, Server.cpp, Client.cpp} ? socket.c ? enc28j60.c

When this goal is reached we can create a single socket.c that communicate with one or another controller (W5100 or ENC28J60).

Actually i don't remember why it was not working for me, but i like the idea to have the same interface for w5100 and enc28j60

@Nick, could you elaborate ?

I believe probably 30-40% of the differences are linked to "programming style" and naming conventions more than functionalities. Things like MAC addresses or SPI instructions could be the same. On the 28J60, there seems to be a buffer so that you can "push" the parts of the packet and then kind of "flush" it. Sounds close to Serial API, and WIZ5100 library was reworked in order to be closer to Serial IIRC ? (or maybe it's a very bad idea because the meaning of fluch is completely different ?)

On the other hand, the TCP part on both circuits seems very different, since 5100 can handle TCP itself while 28J60 can't (what in practice limits connections one received packet / socket).

Any idea which of EtherShield or EtherCard would be a better start ? Anybody wanting to collaborate on that ? The first step wouldn't include any programming, only collaborate to understand the differences... And why not, put the result somewhere in the playground.

tochinet:
@Nick, could you elaborate ?

I believe the Enc28J60 chip has much less functionality on the chip, compared to the Wiz5100 one. Thus it is cheaper. And harder to work with.

I got one of those cheaper Ethernet boards, and when I found that doing fairly simple stuff was incredibly complex, I pushed it to one side.

tochinet:
Any idea which of EtherShield or EtherCard would be a better start ?

In the meaning of closest API psock is the closest, but it's very difficult to debug using Serial.print(..) only without hardware debugger.
Also take into account that psock is designed in a very complex way in the meaning of working with threads, so it's behaviour is pretty strange: it can go out of infinite loop in a thread and move back later.
So you have to understand psock threads idea first. I believe that with hardware debugger and/or deep knowledge of TCP it's much more easy.

Another approach can be to get one of existing tiny TCP implementation (f.e. lwIP http://savannah.nongnu.org/projects/lwip/) and port to ATMega/Arduino + Enc28j60 thought i'm not sure that it can be done as it works with hardware closely.

Anybody wanting to collaborate on that ? The first step wouldn't include any programming, only collaborate to understand the differences... And why not, put the result somewhere in the playground.

I've created stubs for enc28j60 ArduinoCommander-ethernet/Ethernet at master · 4ntoine/ArduinoCommander-ethernet · GitHub to make it easier as client-side (ArduinoCommander) is ready.
Or one can create simple Echo sketch..

This tcp implementations can help:
http://code.google.com/p/avr-uip/
http://code.google.com/p/avr-net/

tochinet:
Any idea which of EtherShield or EtherCard would be a better start ? Anybody wanting to collaborate on that ? The first step wouldn't include any programming, only collaborate to understand the differences... And why not, put the result somewhere in the playground.

Why not turicas's? He seems to have already done most of the job. I haven't tried his work yet, though. Maybe I'll find some time to do it in the weekend. Oh, and I've found another one: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1291904599/8. Quite rough and I can't get it to work, but has some good points:

  • write function can assembly one big packet from smaller chunks

  • buffer (1536bytes) for TCP/UDP data directly on enc28j60 chip. Thanks to this we can use "available" and "flush".

I think compatibility with Arduino Ethernet library is now within your reach Wink

BTW, I am currently using EtherCard on KmTronic's DINo with good results, anyway. @4ntoine: Are you sure your code is OK? With a 700-800 byte packet buffer it's quite easy to run out of RAM :(.

@4ntoine: Are you sure your code is OK? With a 700-800 byte packet buffer it's quite easy to run out of RAM :(.

This can probably be the reason. But i used libs examples to test if it's working in common case first so buffer size is used as is.
I try to modify StandardFirmata sketch to work over Ethernet (TCP) using enc28j60, so most part of the sketch seems to be mature and stable.
Firmata messages are quite short, no longer than 50 bytes (except one message).

Hi,

I did tcp implementations that can help.
It's still in work, but it's working for small (250) packets.

I would love to have comments

dovr:
Hi,

I did tcp implementations that can help.
It's still in work, but it's working for small (250) packets.
GitHub - dovrose/Socket-network-for-enc28j60---arduino: The TCP socket connection based on enc28j60 chip for arduino 1.0

I would love to have comments

Great! Can you show usage by integrating into Add Enc28J60-based ethernet shields support · Issue #1 · 4ntoine/ArduinoCommander-ethernet · GitHub?

I don't know whether you have noticed my posts about my Ethernet-library for ENC28J60. It wrapps the µIP-stack of Adam Dunkels does persisttent TCP, UCP, ICMP, DHCP and DNS and provides the same API as the stock Ethernet-lib for W5100:

  • Norbert