1. Is the ether.link() executed as first thing or is there some prior code? It might be that for some reason the ethernet PHY needs to start up properly before it will be able to communicate.
Yes your right, the link() function just reads out a register from the PHY. Therefore it is needed to initialize the Ethernet before. But if you have an ether object you already done that by calling the constructor. And it should work.
2. Following on the first item: it could be possible that http.get() initializes the interface.
This is true as well. If you have a closer look here (Line 5 & 112 and many more) you will see that the lwIP stack uses this object as its backend.
From what I've learned about the lwIP stack is that it does not rely on the PHY link flag to find out whether an interface is up or not. Maybe I’ve picked the wrong bit for the new PHY, I will investigate that.
But anyway I would not recommend using multiple Ethernet objects. Not because it will not work, but it will initialize the interface multiple times and this can result in packet lost on the Ethernet.
Furthermore lwIP is written in a way that it has to own the interface. At the moment there is no way to ask lwIP if it is up or down. But in the current implementation of the HTTPClient it will initialize the TCP/IP stack the first time it gets used.
There is no multitasking on the mbed target. Therefore the initialization of the TCP/IP stack will stall the program until it's initialized.
Vlad if I understand that right you try to find out whether you have a cable connected or not. And drive your program in online or offline mode. That sounds like exactly what I had the link function in mind, great idea!!! I will have a look at the link function.
But be careful with your second Ethernet object ;-)
Rolf
I am developing a basic UI for my mbed attached to an ethernet cable. I want it to be able to detect if there is a connection and display "Connected" while if there is no connection to display "Not Connected".
I have looked at the ethernet library and found link();
It states that if there is a link this variable will pass a 1 and a 0 if there is no link.
I am also using the HTTP lbrary to request a search from google after it is connected. It seems as though link() does not send anything but a zero even if it is connected.
I noticed that if I call the link() after I use http.get(url, result, 2000); the result is that link() works except if the ethernet is not connected it does not even get past http.get which never makes it to the connected test.
What am I doing wrong and how can implement link() to provide me with a correct value.