Skip to content

Ethernet Shield presence detection #6

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
agdl opened this issue Jul 12, 2016 · 7 comments
Closed

Ethernet Shield presence detection #6

agdl opened this issue Jul 12, 2016 · 7 comments

Comments

@agdl
Copy link
Member

agdl commented Jul 12, 2016

From @ibantxo on January 7, 2016 21:6

Hi,

I want that my code works in 3 cases:

  1. Without ethernet shield connected to Arduino.
  2. With ethernet shield, but unpluged cable
  3. With ethernet shield with a working network

The third scenario works well. But the first one "hangs" in this code line (waiting forever...):
ethClient.connect(server, port);

Is there any way to detect presence of ethernet shield or to insert a timeout in connection attempt?

Many thanks

Iban

Copied from original issue: arduino/Arduino#4400

@agdl
Copy link
Member Author

agdl commented Jul 12, 2016

From @mikaelpatel on January 7, 2016 22:37

The W5100 Ethernet controller has a very specific SPI protocol which actually makes it easy to detect if a shield is present. Please see the product data-sheet for more details. Cheers! Mikael

@agdl
Copy link
Member Author

agdl commented Jul 12, 2016

From @PaulStoffregen on January 7, 2016 23:36

You should check the return value from Ethernet.begin(). If it returns false, you should never call any of the other functions! Of course you can expect them to hang or have unpredictable results if you got a false from Ethernet.begin().

@agdl
Copy link
Member Author

agdl commented Jul 12, 2016

From @ibantxo on January 8, 2016 14:14

Umm...
Thanks Paul. But Ethernet.begin returns "void" when Ethernet.begin(mac,ip) is used.
Anyway... I have been using "Ethernet.begin(mac,ip)" inside void setup(void). Could it be used inside main loop or inside a function? Or is that a "initial setting"?

If "Ethernet.begin" could be outside "setup", another way I am thinking about is a "reconnect" function (called from main loop):

boolean reconnect(void) {
Ethernet.begin(mac, ip);

Serial.println("RECONNECT!");
int status=ethClient.connect(server, port);
Serial.print("Status: ");
Serial.println(status, DEC);
ethClient.stop();

and test with "status" value to return...

Thanks mikaelpatel. I am newbie. I will try to test "SPI way" as well. But I think is a "deeper code" for my skill level.

@agdl
Copy link
Member Author

agdl commented Jul 12, 2016

From @mikaelpatel on January 8, 2016 20:44

@ibantxo
My comment was mainly for the library maintainers as the board detect could be improved without forcing usage of DHCP. If you would like to do a detect to configure your sketch this could be done by a simple function that reads a register (byte) from the controller. The SPI sequence is very unique and this will help determine if a device is available before initiating etc.

@agdl
Copy link
Member Author

agdl commented Jul 12, 2016

From @ibantxo on January 8, 2016 22:32

That could be great, Mikael. Knowing the "status" of the device:

  • if the device is present/available or not
  • ethernet link status is ok, or not
    ....

Many thanks!!!

@PaulStoffregen
Copy link
Contributor

Version 2.0.0 will have Ethernet.linkStatus() and Ethernet.hardwareStatus().

@PaulStoffregen
Copy link
Contributor

Fixed

jonoxer pushed a commit to SuperHouse/SuperHouse_Ethernet that referenced this issue Jul 29, 2020
The W6100 IPv4 Arduino Example.(For W6100 Ethernet Shield)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants