Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

server.available() doesn't work on Opta #250

Open
fogzot opened this issue Feb 16, 2024 · 5 comments
Open

server.available() doesn't work on Opta #250

fogzot opened this issue Feb 16, 2024 · 5 comments

Comments

@fogzot
Copy link

fogzot commented Feb 16, 2024

The documentation for server.available() says:

Gets a client that is connected to the server and has data available for reading. The connection persists when the returned client object goes out of scope; you can close it by calling client.stop().

But in the following code the connection is closed immediately at the end of the scope:

#include <Arduino.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>

IPAddress ip(192, 168, 3, 2);
IPAddress dns(192, 168, 3, 1);
IPAddress gateway(192, 168, 3, 1);
IPAddress subnet(255, 255, 255, 0);
byte MAC[] = {0xa8, 0x61, 0x0a, 0x50, 0x51, 0xff};

EthernetServer TelnetServer(23);

void setup()
{
    Serial.begin(9600);

    if (Ethernet.begin(MAC, ip, dns, gateway, subnet) != 0)
    {
        TelnetServer.begin();
    }
}

void loop()
{
    EthernetClient client = TelnetServer.available();
    if (client)
    {
        Serial.println("Client connected: " + String(client.remotePort()));
        int c;
        while ((c = client.read()) != -1) {
          client.write(c);  
        }
    }
}

The connection is supposed to persist across invocations of loop() but if one tries to connect (telnet 192.168.3.2) it is disconncted immediately.

@JAndrassy
Copy link
Contributor

yes. the networking libraries in mbed core implement server.available() as server.accep().
if you need proper server.available() you can use ArduinoEthernetServer from my NetApiHelpers library. (works only with the latest mbed core release)

@fogzot
Copy link
Author

fogzot commented Feb 16, 2024

What about updating the documentation with this information? The docs sent me on a wild bug chase in my code before I guessed that there was an error in the library. And, IMHO, if the documentation says "A" and on every other platform it is "A", having it as "B" on mbed is a bug.

@JAndrassy
Copy link
Contributor

JAndrassy commented Feb 16, 2024

I guess you were looking at the Wiznet W5x00 Ethernet library documentation, because the Mbed Core Ethernet library is not documented

@fogzot
Copy link
Author

fogzot commented Feb 16, 2024

Well, no. I am looking at the official documentation for the Ethernet library:

https://www.arduino.cc/reference/en/libraries/ethernet/

That reads:

This library is compatible with all architectures so you should be able to use it on all the Arduino boards.

If a different, undocumented library exists and is used instead of the "official" one when i put #include <Ethernet.h> in my sketch, how am I supposed to know?

@JAndrassy
Copy link
Contributor

Opta doesn't use this library here.
it uses the bundled Ethernet library from Mbed Core
https://github.com/arduino/ArduinoCore-mbed/tree/main/libraries/Ethernet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants