[SOLVED] Ethernet communication breaking down, when moved from lab to on-site

Greetings;

I have this Arduino Mega project, monitoring a bunch of sensors (pH, conductivity, pressure for pool chemistry) and communicating the readings via a web server and a daily email. It uses a SunFounder Ethernet Shield (W5100)

I've beta tested it for weeks in my office/lab, which is about 10m/30ft from my router and all has been fine. A couple of weeks ago, I moved it to the pump room, which has a 50m/165ft Cat6A run to the router and it can't make it 24hrs before dropping the communication. I tried it as the only device on that cable and with a GigaBit switch in-between (a WiFi AP is the other device on the switch). the WiFi AP works perfectly fine and the Pool Automation as well, on a Cat5E running the 50m in the same conduit.

The router reserves an IP address for the W5100, 192.168.XX.XXX, which I display on the TFT screen. When the thing hangs, it displays 192.168.0.100, which is totally unrelated and obviously some default...

I'm using the standard Ethernet.h library and the sample sketch found in the ArduinoIDE... as the basis for the ethernet comms.

It's a royal PITA to try to trouble shoot it on-site - hot, damp, noisy down a steep set of stairs. I do have Juraj's ArduinoOTA, but once I lose connection, I'm back to huffing it (last night's knee MRI showed a second tear in my meniscus, unrelated but no less painful)...

Any pointers on where to look would be helpful.

I do now have a couple of W5500s on hand, (ArduinoOTA apparently works better with those), just in case... and some ESP8266s as well. I was hoping to avoid WiFi, since I'm in a potentially noisy environment, with several pumps and ionizers running...

Cheers;

Most Arduino example projects setup stuff in the setup function and then leave it as is. That is fine for examples but generally not a good idea for robust embedded applications. Change your code so that you handle the network from within loop. When something goes wrong reset the connection and start over.

You can do this in your lab, not need to debug it outside. Your sketch should be able to handle you removing the cable and plugin it back in after random intervals of time.

I'm using the standard Ethernet.h library and the sample sketch found in the ArduinoIDE... as the basis for the ethernet comms.

I just wonder, what you have done to the sketch if you are able to see

When the thing hangs, it displays 192.168.0.100, which is totally unrelated and obviously some default...

so you must have added a lot stuff to the IDE example. Which IDE example? The WebClient Repeating?

As we don't see your sketch we can't tell if you have problems with your sketch, with your hardware with your environment.

I can only suggest a stepwise approach.
a) Use the standard WebClient Repeating in that environment. disconnect any HW unrelated to webclient How long will it run?

Klaus_K:
Most Arduino example projects setup stuff in the setup function and then leave it as is. That is fine for examples but generally not a good idea for robust embedded applications. Change your code so that you handle the network from within loop. When something goes wrong reset the connection and start over.

You can do this in your lab, not need to debug it outside. Your sketch should be able to handle you removing the cable and plugin it back in after random intervals of time.

Danke Klaus!
That's a great idea. As much as I hate error handling, it's the right way to go.
Cheers!

noiasca:
I just wonder, what you have done to the sketch if you are able to see
so you must have added a lot stuff to the IDE example. Which IDE example? The WebClient Repeating?

As we don't see your sketch we can't tell if you have problems with your sketch, with your hardware with your environment.

I can only suggest a stepwise approach.
a) Use the standard WebClient Repeating in that environment. disconnect any HW unrelated to webclient How long will it run?

Thanks Noiasca,
The whole project is bigger than the 900 lines or so allowed by the Forum, so I chose not to send it. Just needed some general guidelines, so I can tackle the problem.
I will incorporate your suggestion of isolating the web server/client and Klaus' comms initialization and report back.
Cheers.

Greetings;

As I'm trying to trap the dropped Ethernet link, I'd like to proceed as follows:

Since I'm using a W5100, Ethernet.linkStatus() is not available. As I mentioned, when the link is dropped, Ethernet.localIP() returns 192.168.0.100, instead of the reserved IP assigned by my router.

It seems to test for that default IP may not be as trustworthy as a specific test for an active connection. Is there such a test?

Or, shall I just ramrod a Server.begin() and Client.begin() every so often, regardless of the status of the connection?

I'm posting data to the webserver every 5 seconds and sending an email once a day. I also have a timer to write the sensor data to an SDcard every 15mins (that might be the right timing).

BTW, when I push the reset button or power-cycle the system, occasionally it will refuse to establish an Ethernet link unless I remove and reinsert the SDCard, which is located on the Ethernet shield as well. Not sure this has anything to do with the above mentioned link instability.

Cheers;

trilife:
Since I'm using a W5100, Ethernet.linkStatus() is not available. ... It seems to test for that default IP may not be as trustworthy as a specific test for an active connection. Is there such a test?

I found (working with WiFi) that it is best to test on the application layer. Sometimes the network seems to be still connected but you cannot receive or send any data.
Some protocols have functions to confirm connections. You need to look which protocols you use for your application and see whether there are useful functions available.
A low-level function is ping which should mostly be available. For it to work a package needs to travel the full path. So, you could try local ping to your router another node in your house or ping Google if you want to test whether the internet connection works as well.

Greetings;

Update:

I got the project back to the lab and replaced the W5100 with a W5500 cleaning up some harnesses in the process.

I also added Ethernet.maintain() at the end of the loop().

In the lab, I was able to disconnect and reconnect the cable, wait beyond lease renew time and reconnect without a problem.

Back in situ, it seems to be working just fine. Waiting for some brownouts...

Thanks again for all the help and suggestions.

Changing topic to SOLVED.