UIPEthernet.h library size ?

Hello,
I have a question about the library UIPEthernet.h because I have a lake of flash for my programm. (This question may be usefull for the others big library).
Secondly, I looked at the library examples and I was surprise to than the example below is very big computed : 25 466 bytes ! With an arduino Uno with 32k of flash, there is not a lot of free memory !

So, I would like to know if there is a way to compute only the functions and dependencies necessary for the programm ?

#include <UIPEthernet.h>

EthernetClient client;
signed long next;

void setup() {

  Serial.begin(9600);

  uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
  Ethernet.begin(mac);

  Serial.print("localIP: ");
  Serial.println(Ethernet.localIP());
  Serial.print("subnetMask: ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("gatewayIP: ");
  Serial.println(Ethernet.gatewayIP());
  Serial.print("dnsServerIP: ");
  Serial.println(Ethernet.dnsServerIP());

  next = 0;
}

void loop() {

  if (((signed long)(millis() - next)) > 0)
    {
      next = millis() + 5000;
      Serial.println("Client connect");
      // replace hostname with name of machine running tcpserver.pl
//      if (client.connect("server.local",5000))
      if (client.connect(IPAddress(192,168,0,1),5000))
        {
          Serial.println("Client connected");
          client.println("DATA from Client");
          while(client.available()==0)
            {
              if (next - millis() < 0)
                goto close;
            }
          int size;
          while((size = client.available()) > 0)
            {
              uint8_t* msg = (uint8_t*)malloc(size);
              size = client.read(msg,size);
              Serial.write(msg,size);
              free(msg);
            }
close:
          //disconnect client
          Serial.println("Client disconnect");
          client.stop();
        }
      else
        Serial.println("Client connect failed");
    }
}

So, I would like to know if there is a way to compute only the functions and dependencies necessary for the programm ?

The linker only includes code that is actually used. If a function is never called, it is not included in the resulting HEX file.

OK, So, I conclude the library I choose is very big. (but I do not have the choice because of my shield is not compatible with Ethernet.h)
I compared the cumputing of a simple sample with the library UIPEthernet.h and Ethernet.h.
The result is very different : lightly more than 15k for Ethernet.h and 22k for UIPEthernet.h.
I am surprised of this difference.

Do you know any other lighter library compatible with Ethernet LAN Network Breakout Mini Module ENC28J60 Arduino Compatible - dipmicro electronics ?

Use a static IP, instead of DHCP like you have, and you can lose the UDP functions.

The library will use more space than the standard ethernet library since the ENC28J60 does not have a hardware TCP/IP stack, unlike the W5100.

Use a static IP, instead of DHCP like you have, and you can lose the UDP functions.

This is a simple example supplyed with the UIPEthernet library, not my programm.
In my programm, I use a static IP.

tack:
Use a static IP, instead of DHCP like you have, and you can lose the UDP functions.

If you don't need DHCP nor DNS and use TCP-only, you can save aprox. 5k of flash by turning off UDP entirely. To do so set UIP_CONF_UDP to 0 in uipethernet-conf.h
You also might want to check out the version in branch static-memory which saves a few hundred bytes compared to the one in master.

  • Norbert

You can use the ethercard library, GitHub - njh/EtherCard: EtherCard is an IPv4 driver for the ENC28J60 chip, compatible with Arduino IDE

tymop:

Use a static IP, instead of DHCP like you have, and you can lose the UDP functions.

This is a simple example supplyed with the UIPEthernet library, not my programm.
In my programm, I use a static IP.

Well it tends to help if you post the code YOU are using, and not just some example code. My crystal ball is out for repair again. LOL

If you don't need DHCP nor DNS and use TCP-only, you can save aprox. 5k of flash by turning off UDP entirely. To do so set UIP_CONF_UDP to 0 in uipethernet-conf.h

Thank you, I tried, and as you said : 5ko less ! :slight_smile:

Well it tends to help if you post the code YOU are using, and not just some example code. My crystal ball is out for repair again. LOL

LOL, I understand. My purpose was not to debug my code, but to understand why the library was so big.
As the "Simple Example" was big too, I did not wanted to complexity the problem. I think than is the problem is resolved with a simple example, it may be resolved for my programm.

You can use the ethercard library, GitHub - njh/EtherCard: EtherCard is an IPv4 driver for the ENC28J60 chip, compatible with Arduino IDE

Thank you, really good : a simple example = 8ko. I think is is what I expexcted.
I think I will try to adapt my programm to this library.

:grin: Thank you for all your answers. 8)