Saving power with ENC28J60 Ethernet server

Hello everyone!

I am trying to reduce the power consumption of the ENC28J60 shield with a duty cycle: I power off (Vin to 0V) the ethernet shield during 1 sec, then switch it on and wait for a request. When it is received, i turn off again, all in a while loop.
Meanwhile, my web browser sends a request every second (simply using <meta http-equiv='refresh' content=''1''> in html).

I observe that:
I can power off during up 1 sec without trouble (almost no request lost).
after power on, request is handled 6-8 sec later, which is a lot! This is my problem.

Why 6-7 sec are required between switch on and request reception?

Here is the code:

  unsigned long int stamp;
  while (1)
  {
    switchPeriph_ON(); //Periph = ENC28J60. Turn it on via Mosfet
    VERBOSE("Periph switched on");
    Ethernet.init(ETH_CS_PIN);  //Relunch Ethernet shield
    Ethernet.begin(mac_addr, ip_addr, dns_addr, gw_addr, mask);
    server.begin();
    VERBOSE("Eth and Server started"); // which took 30-80ms

    stamp = millis();
    while (!ethernet_com()) { delay(1); } // wait for a request
    VERBOSE("\n>>>>>>>>>>>> %l <<<<<<<<<<<<\n", millis()-stamp); // Print time need to receive + handle request

    delay(100);
    ethernet_com(); //Don't understand why, but it is necessary to call it again
  
    switchPeriph_OFF();
    VERBOSE("Periph switched off");
    delay(1000); // stay off 1 sec to save power
  }

Here is the ethernet_com() function:

bool ethernet_com()
{
  client = server.available(); // listen for incoming clients

  if (client)
  {
    VERBOSE("------- New client connected. -------");
    http_index=0;
    boolean currentLineIsBlank = true; //an http request ends with a blank line
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        [...]
    return true;
  }
  return false;
}

Here is the output:

12:05:02.714 -> Periph switched off

12:05:03.698 -> Periph switched on

12:05:03.733 -> Eth and Server started

12:05:10.016 -> ------- New client connected. -------

12:05:10.016 -> GET / HTTP/1.1

12:05:10.016 -> Host: ip address

12:05:10.016 -> User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0

12:05:10.016 -> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,/;q=0.8

12:05:10.050 -> Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3

12:05:10.050 -> Accept-Encoding: gzip, deflate

12:05:10.050 -> Connection: keep-alive

12:05:10.050 -> Upgrade-Insecure-Requests: 1

12:05:10.050 -> Cache-Control: max-age=0

12:05:10.050 ->

12:05:10.050 -> Http rqst ended

12:05:10.050 -> Start reply

12:05:10.050 -> [...]

12:05:10.212 -> Disconnected client.

12:05:10.212 ->

12:05:10.212 -> >>>>>>>>>>>> 6440 <<<<<<<<<<<<

12:05:10.212 ->

12:05:10.294 -> Periph switched off

12:05:11.325 -> Periph switched on

Thank you very for your insights, or any other ideas to reduce ENC28J60 consumption!

don't do that. you loose the configuration of the enc28j60 chip, which is done by the library in 'begin'

I don't understand.

I am calling each time

Ethernet.init(ETH_CS_PIN);  //Relunch Ethernet shield
Ethernet.begin(mac_addr, ip_addr, dns_addr, gw_addr, mask);
server.begin();

What do I loose?

ok. I missed that. the 6 seconds are enc boot and DHCP to get the IP address.

Ok, interesting to understand.

Do you think it can be improved somehow?

Do you have any other idea to reduce power consumption?

using static IP would save much time

and you could implement in the library the power down mode

with #include "Enc28J60Network.h" you could try Enc28J60Network::powerOff() and Enc28J60Network::powerOn() without doing begin after powerOn
but don't turn off the power line

1 Like

Thank you very much for the reference. I understand that you contributed to this library, thanks for sharing your work!

I actually use a much simpler wiring (no transistor, no pull-up...). So I cannot run the example codes.
What's the benefit of this wiring of the UIPEthernet library?

Did you already measured power consumption using Enc28J60Network::powerOff() ?

Thanks a lot!

no. I never tried it.

what simpler wiring? the esp8266 CS wiring is necessary only for pin 15 as CS, but it is not required to us pin 15 as CS. I hope you don't use UIPEthernet or EthernetENC with esp8266. the library bundled with esp8266 core is much better for esp8266.

if you use UIPEthernet, I recommend you to switch to EthernetENC.

I simply used Ethernet.h

Sorry, I don't understand this sentence:

In the readme, it is said that UIPEthernet is compatible with esp8266.

I have to switch to ESP32 anyway, esp8266 has too few pins, so the library might not be compatible anymore.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.