Need help with server.available() [SOLVED]

[Edit 6 Jul '19 My conclusion: all these time variations are due to the router to which the enet shield is connected. After a router factory reset the duration of server.available is and stay at its lower value - depending upon the enet library used - for days and, as time passes, the occurrence of random increase in duration become more frequent resulting sometimes in half working communication such as no email of server half working etc]

Hello to all,

I am struggling to resolve a persistent issue that is now confirmed to be in the call to server.available (called every loop ~3k/sec) and seems the unique instability point of my system.

It happens to last a variable time and I would love to [u]understand what this time depend on[/u] and to try to progress from there.

The execution duration lasts from 80us to 500us (and maybe more) it depends on the specific shield plugged and may depend upon the activity

Few example:

It can last 80 us and stay at this value for hours despite accesses to the server Than become steady 300us immediately after an access to the server and than become steady 200us immediately following an access of the board as client

With another 5100 shield it may spontaneously jump from steady 80 to steady 300 and revert to 80 immediately following a server access.

On a 5500 shield, it may spontaneously jump from 140 to >255 for 15 mins and up to 12 hours and spontaneously revert to a steady 140.

I admit my difficulty with c++ that makes me lose ends in face of the lib's code

Why does it bother me? First following an increase of the duration the server does not respond until reset which is totally unacceptable (unless some recovery workaround). Second I expect a deterministic behavior in my environment.

Note that it is possible that all is fine with arduino but something is wrong with my router!

Thanks for your time

You need to share your code.

I would also like to see the code. I also would like to know why you need to make that call so often.

attached the code and libs.
Note that ethernet lib is slightly modified to include query for RIP thanks to Pert

To the question why am I coming back to this issue “so often”: each time I come back with narrower and targeted question because it’s still here and my strategy (which improved over time) still yield no satisfying result

_12.ino (145 KB)

libraries.zip (312 KB)

guy_c: attached the code and libs. Note that ethernet lib is slightly modified to include query for RIP thanks to Pert

To the question why am I coming back to this issue "so often": each time I come back with narrower and targeted question because it's still here and my strategy (which improved over time) still yield no satisfying result

Sorry, I thin you misunderstood my question. I was asking why you need to make the call to server.available s often. I was not questioning why you are asking for help.

guy_c: attached the code and libs. Note that ethernet lib is slightly modified to include query for RIP thanks to Pert

To the question why am I coming back to this issue "so often": each time I come back with narrower and targeted question because it's still here and my strategy (which improved over time) still yield no satisfying result

It's probably best to keep working on a single thread to maintain continuity with those who have helped you get this far and to prevent xy problems... For me to help, in addition to your code, you will need to tell me what you are making, what you know about the code you've written. How much of the code has been tested and known to work, and where it's gone off the rail, what your expected behavior is, and what the actual behavior. You seem confident it's a server.available() issue, but my experience with code has been, it's never where I'm looking... I don't mean to be offensive, as I've been down this road a hundred times... If we take away the confidence in where the problem is (because if we know where the problem is, why can't we solve it?) we have to go back to where we know we were last on track.

May I ask you one question please. Why don't you use the .NET Framework? It provides a lot of helpful libraries as well as support in development.

The call to the server is part of the code's main loop which happens to run at ~2.5kHz. interval may increase if a function last more e.g. a communicating one, such as sendEmail

The issue is as i described it. One can see in the code how things are measured.

Gates:
May I ask you one question please. Why don’t you use the .NET Framework?
It provides a lot of helpful libraries as well as support in development.

.NET is dependant on a CLR virtual machine that I have not found in source code for the Arduino. According to Microsoft, most of the Arduino chips won’t meet the system requirements.

Maybe with in that one answer holds the fountain of information which has been needed to solve one of the problems.

.NET is dependant on a CLR virtual machine that I have not found in source code for the Arduino. According to Microsoft, most of the Arduino chips won't meet the system requirements.

Arduino isn't even close to being compatible. Go to your grave trying.

Gates: Go to your grave trying.

Excuse me? I was answering your one question. Under what context would you suggest using .NET on an Adruino forum? I was being kind to answer your question as to why I wouldn't use it, but I'm curious now as to why you thought it would be a solution to anything.

Please focus on my problem. Thanks. Nobody will even look atit with this discussion.

guy_c:
Please focus on my problem. Thanks. Nobody will even look atit with this discussion.

I’ve been doing just that. I’ve gone back into your previous posts all the way back to April of this year or December of last year, to better understand what you are trying to do. And, I’m looking over your code to grasp your intent there as well. I’ve never worked with the Ethernet sheild or Wiznet chip. I have built my own embedded server, much like yours, using a ENC28J60, mostly because I could use all pth components, so it’s taking me a bit of time to respond with anything useful, but I can assure you that I am looking at your problem.

Thank you Perehama. I am deeply grateful. Could you find arduino libs for this microchip mac?

guy_c: Thank you Perehama. I am deeply grateful. Could you find arduino libs for this microchip mac?

The ENC28J60? Yes, but first, let me say that although it works on the SPI bus, it offloads more work onto the microcontroller than does the Wiznet Chip, which is why I think Arduino used Wiznet for the shield. There are libraries out there https://github.com/njh/EtherCard that adapt the code to be directly compatible with the ethernet sheild. However, I found it to be too memory intensive. I took a lot of my source directly from Guido Socher's tuxgraphics.org, because I needed to get the memory down to what would work on a ATmega328P. He borrowed the ENC28J60 code from Pascal Stang's enc28j60.c. I recall it worked very well, but it was far from "Arduino" by the time I was done. One thing I might suggest aside from addressing your direct problem is recycling responses. instead of creating 500 responses for every instance, only create valid ones for stuff you can do, and one for stuff beyond your scope. Maybe you're doing that, I'm still working through it, but I found that was helpful to reduce overall memory usage.

while writing I realized that the issue may well be at the router’s ethernet port. I inserted a switch in the middle and let it run from 14:16 Jerusalem (11:16 GMT). So far its on steady 83us. Will report here the outcome of this setting
attaching the monitor output

field 5100 mercury switch.txt (66.7 KB)