new library UIPEthernet: uIP adapted to Arduino for ENC28J60

At the moment I'm using the EtherCard for an pretty simple application on a atmega328. Basicly I'm reading two temperatures via 1wire and report them to a remote server. I want to switch to UIPEthernet since the dhcp implementation in EtherCard is really buggy.

The problem is that the footprint gets to large with UIPEthernet. Any other way exept disabling UDP, DNS and DHCP to cut out ~3kb of the code?

Of course I'm trying to reduce code size in other parts aswell.

you may check out the code in branch 'static-memory' (or the new UIPEthernet_v1.5 version I just published that compiles in Arduino 1.5.5 and is based on 'static-memory' as well). This should compile a few hundred bytes smaller (but not 3k...). There's no easy way to shrink the library without removing core-functionality. Not using DHCP is easy in most cases without reducing much functionality of your code as you can just specify static ip (DHCP is a few kb...).

If you happen to use Serial for debugging, removing this saves a few kb (use #ifdef DEBUG or something like this is you want to optionally enable it).

https://github.com/ntruchsess/arduino_uip/releases/tag/UIPEthernet_v1.50

(Due is not supported yet, but I'm working on that)

Just got it running on DUE: http://forum.arduino.cc/index.php?topic=164281.msg1539562#msg1539562

The due branch also contains an important fix for SPI-communication could fail if ENC28J60_CONTROL_CS (in Enc28J80Network.h) is configured to anything other than (Hardware-) SS.

  • Norbert

ntruchsess: Enc28J60 does not respond to reset-command send on SPI (which is the very first access to enc28j60 SPI from UIPEthernet.init). This can be because ENC28J60_CONTROL_CS is not set to the right pin (defined in utility/Enc28J60Network.h) or you have another device connected to SPI that is not disabled during access to enc28j60 spi and interferes with enc28j60 communication.

  • Norbert

Iam trying it only with connected ethernet card, nothing else is not connected.

After some time of testing I found solution. Arduino Mega2560 have to CS connected to 53pin. On pin 8 or 48 it doesnt work. Arduino Mega ADK have to CS connectd to 8 or 48pin. On pin 53 it doesnt work.

(Of course you must set right pin in Enc28J60Network.h ENC28J60_CONTROL_CS.)

I hope that this will help somebody.

MG

hi friends,

i m new to this board...i am going to do a project using arduino mega with Ethernet field ..i need to control home appliance & i want to collect all the information (like temperature ...) from home . ..i got some details from google...like i can able to do all this things using HTML lang...but it not that much graphical view...i want to know which lang will be more graphical to control and collect the details ..i need some sample code...

ntruchsess: you may check out the code in branch 'static-memory' (or the new UIPEthernet_v1.5 version I just published that compiles in Arduino 1.5.5 and is based on 'static-memory' as well). This should compile a few hundred bytes smaller (but not 3k...).

Managed to shrink the code to fit 32kB using the 1.5 version, thanks.

Got a strange error with client.available(), it doesn't resturn false, even when eof is reached. The same happens when using the "WebClientRepeating" example, so no need to print the full code here.

The following code generates an endless loop and prints garbage:

if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

From the WebClientRepeating:

My IP address: 192.168.5.5
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ (continues forever printing this char)

I do not need to fetch any data since I just push data, but I really need to detect a successful connection.

Well, making a test "client.available() >0" works, but client stays connected.

well, that is how it is supposed to work (you find the documentation here: ‘returns: the number of bytes available’). Unfortunally it’s unspecified what available should return if the client is invalid or closed - UIPEthernet returns -1 in this case (but only if there’s no unread data in which case it returns the number of unread bytes regardless of connection status).
use Client method ‘connected()’ to check clients connection status.
use Client method ‘stop()’ to invalidate the client-object (and close the connection if not yet done).
BTW: the ‘ÿÿÿÿÿÿÿÿÿÿÿ’ is not garbadge, but int value of ‘-1’ printed as bytes to the Serial stream. -1 is returned whenever the Client is invalid (or closed).

One further remark: when doing an http-request there will allways be a response that you can either read or ignore, but as long there is still unread data client.connected() is supposed to return true.

Norbert

Yes, I figured that out (learning fast!). The problem seems to be that the client.connected() is always true after a successful connect, even when all data is read and available returns -1 permanently. Seems like the client doesn't detect that the connection is closed.

To repeat: Using Arduino 1.05, with the master branch of UIPEthernet the "WebClientRepeating" example makes one successful connect, and then client.connected() is true forever.

Even simpler example:

#include <UIPEthernet.h>
#include <SPI.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//byte ip[] = { 10, 0, 0, 177 };
char server[] = { "www.google.com"}; // Google

EthernetClient client;

void setup()
{
  Serial.begin(9600);
  Serial.println("Start...");
  Ethernet.begin(mac);

  client.connect(server, 80);
  delay(1000);

  Serial.println("connecting...");

  if (client.connected()) {
    Serial.println("connected");
    client.println("GET / HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()>0) {
    char c = client.read();
    Serial.print(c);
  }
if (0 == (millis()%1000))
  Serial.println(millis()); //debug output

  if (!client.connected()) { //never true
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}

Results in this:

Start...
connecting...
connected
6000
6000
6000
6000
HTTP/1.0 302 Found
Location: http://www.google.se/?gws_rd=cr&ei=_ivVUteOG6Xy4QS8xoHYCA
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Set-Cookie: PREF=ID=63aa5dcc409f2ebc:FF=0:TM=1389702142:LM=1389702142:S=O2CIMy7rJbFMqUpZ; expires=Thu, 14-Jan-2016 12:22:22 GMT; path=/; domain=.google.com
Set-Cookie: NID=67=NNi6xf7b_S36L6I0a3BxUIKM4DM11BimKScqBEiMo4Wh8w_b6AsiVedMOuOYuPg6BpzsuFUwOovDt8QwQzl_BV8yLRCuY8KDPBDHoYcRvKxqClp4mP7VCGJrJU_ge5LR; expires=Wed, 16-Jul-2014 12:22:22 GMT; path=/; domain=.google.com; HttpOnly
P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
Date: Tue, 14 Jan 2014 12:22:22 GMT
Server: gws
Content-Length: 258
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alternate-Protocol: 80:quic

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>7000
302 Moved</H1>
The document has moved
<A HREF="http://www.google.se/?gws_rd=cr&amp;ei=_ivVUteOG6Xy4QS8xoHYCA">here</A>.
</BODY></HTML>
8000
8000

.....

2078000
2078000

It never disconnects.

please add a call to Ethernet.maintain() to the main-loop(). I cannot test this before todays evening as I don't have the hardware with me ;-)

No difference with a Ethernet.maintain(); in the main loop. Sorry.

I do not think it matters, but I've changed the ENC28J60_CONTROL_CS to pin 8 in Enc28J60Network.h.

just reproduced and created 2 issues on github to track: https://github.com/ntruchsess/arduino_uip/issues/27 https://github.com/ntruchsess/arduino_uip/issues/28

thank you for reporting.

fixed in UIPEthernet_v1.05 and v1.52: https://github.com/ntruchsess/arduino_uip/releases

The fixes for issue #27 and #28 improved the reliability a great deal, thanks! :slight_smile:

I have a sketch running on a Nano with an EN28J60 module attached that is posting to a server continuously with 30 sec intervals. Before your two fixes this sketch hardly worked and it wasn’t until I read here that I saw that there was a problem with this library. With these fixes it looked promising though. But after ~95 mins the sketch stopped posting. No serial terminal was attached so I couldn’t see what was happening. I’m going to try later if I can run the sketch again with serial terminal attached and see if the problem occurs again.

I have also uploaded the same sketch to an Uno with the Wiznet Ethernet Shield to see if that sketch keeps working, or if that one has problems too.

The same sketch loaded on Uno + Ethernet Shield ran without problem for 4+ hours when I stopped it.

I then saw that you had also fixed #29 so I recompiled my sketch against the new UIPEthernet library. And this time the Nano ran for 150 mins before it stopped. I have now reset it again to see how long it works before freezing again.

Absolute excellent job. !!! :slight_smile: :slight_smile: :slight_smile:

I have only a problem with DNS. The sketch below works fine with the original Ethernet Lib. But with the UIPEthernet Lib I get only 0.0.0.0 for the resolved IP :~

#include <Dhcp.h>
#include <Dns.h>
#include <ethernet_comp.h>
#include <UIPClient.h>
#include <UIPEthernet.h>
#include <UIPServer.h>
#include <UIPUdp.h>


IPAddress ip(192,168,0,215); // Test
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xB5 };  // Test

IPAddress dnsServer(212,98,37,128);
IPAddress gateway(192,168,0,2);
IPAddress subnet(255,255,255,0);

DNSClient DNS;
char ntpServer[] = "0.ch.pool.ntp.org";
IPAddress timeServer;

void setup()  {
  Serial.begin(9600);
  Serial.println("start");
  
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  DNS.begin(dnsServer);
}

void loop()  {
  Serial.print("get IP of: ");
  Serial.println(ntpServer);
  DNS.getHostByName(ntpServer,timeServer);
  Serial.println(timeServer);
  Serial.println();  
  delay(10000);
}

By the way I had to remove the Ethernet Lib out of the Arduino libraries otherwise I get a "double definition in DNS.h