Go Down

Topic: IS there a proper workflow for ethernet, say for when it loses connection? (Read 729 times) previous topic - next topic

iisfaq

Say I have an ethernet shield and I configure it during the setup() phaseto either give it a static IP or get a DHCP one.

Is there a proper workflow for detecting say a loss of connection and somehow reestablish the connection if it is possible?

If I pull the ethernet cable and it has been configured during setup() how do i detect it is now broken?

Obviously I do not want to try to reestablish a connection every 5 ms etc...

Just looking for ideas here?

Chris

pylon

It sounds as what you're looking for is a way to detect a link loss. Unfortunately the WizNet5100 chip of the Ethernet Shield doesn't support that.

Usually you set in the setup routine the boards IP address or get it by DHCP. If the connection is interrupted the IP address usually is still valid and doesn't need a change. You shouldn't open a connection in the setup routine and hold it constantly for a long time. Open a connection, send any information you need to send and close it.

Maybe you should describe what exactly you want to do, there might be a better way to achieve the same.

iisfaq

I am configuring the Ethernet in the Setup() method along with an EthernetServer and a MiniWebServer and then in the loop it checks for an incoming connection and processes it if a client is waiting.

I guess I am wondering what the situation is if I pull the ethernet cable out and then plug it back in to simulate a loss of connection.

Or what happens if the switch is turned off and then back on.

How would I know to reconnect ie run Ethernet.Begin again (is that what I am supposed to do?)

I guess it would be best for me to just test this out but I thought someone may have wrote an article about this before.

My project is an aquarium controller and the web server is needed on the arduino to read values and configure the system.

I have had issues where it no longer responds so I am just wondering about issues that could affect it.

My project is quite complex with around 35 different classes in separate .CPP and .H files

It controls 9 LED channels, a scheduler, a web server, and has temperature, humidity, and power monitoring capabilities. It supports easing functions for lights along with multiple points for each channel. I also have used a relay which turns on a battery powered air pump if the whole system loses power.

Just a work in progress but it seems to stop responding for no reason. I do not appear to have any memory leaks based on the free ram type of code.


weird_dave


pylon

Quote
I guess I am wondering what the situation is if I pull the ethernet cable out and then plug it back in to simulate a loss of connection.

Or what happens if the switch is turned off and then back on.
Both shouldn't be a problem if the interruption in the connection wasn't lasting to long. If you use DHCP it might be a good idea to renew your lease from time to time but with standard home routers you could hold your lease almost infinitely. If you configure fixed IPs you shouldn't have any problems at all.

I don't know the "MiniWebServer" library, please post a link to it.

Quote
Just a work in progress but it seems to stop responding for no reason. I do not appear to have any memory leaks based on the free ram type of code.
"Stop responding" means it doesn't answer web requests or does it also stop sending anything on the serial interface? Do you send anything on the serial interface or is the web server the only interface you have? Does it respond to pings in this situation?

iisfaq

I don't know the "MiniWebServer" library, please post a link to it.
Looks like it is from Nick Gammon

https://github.com/nickgammon/HTTPserver

I may have created the name when I implemented it in my project.

Chris

Go Up