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!