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

Not working on none WiFi ethernet connections #27

Closed
Mynogs opened this issue Oct 9, 2022 · 6 comments
Closed

Not working on none WiFi ethernet connections #27

Mynogs opened this issue Oct 9, 2022 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@Mynogs
Copy link

Mynogs commented Oct 9, 2022

In the function "ESPTelnet::begin" stands:
if (WiFi.status() == WL_CONNECTED || _isIPSet(WiFi.softAPIP())) {

This means that ESPTenet only works if there is a WiFi connection. I use wired ethernet on my board.
I fixed the problem like this:

bool ESPTelnet::begin(bool forceConnected, uint16_t port /* = 23 */) {
  ip = "";
  // connected to WiFi or is ESP in AP mode?
  if (forceConnected | WiFi.status() == WL_CONNECTED || _isIPSet(WiFi.softAPIP())) {

It works, but it's not pretty...

Greetings
Mynogs

@LennartHennigs
Copy link
Owner

LennartHennigs commented Oct 9, 2022

Hey,

Thanks for your comment.
Does this line of code create problems as well, as you don't use WiFi?

server = WiFiServer(port);

Cheers
l.

@Mynogs
Copy link
Author

Mynogs commented Oct 9, 2022

"WiFiServer" is a poorly chosen name. It also works with the wired ethernet without any problems. A better name would be "EthernetServer" or something similar.
I check if I can start telnet by
ETH.localIP() != IPAddress()
This is perhaps a universal method...
Greetings
Mynogs

@Arnold-n
Copy link

Arnold-n commented Oct 29, 2022

Many thanks @LennartHennigs for your very useful library, and @Mynogs for starting this issue. I have the same problem and would like to support the solution above, perhaps with two minor changes:
-swap arguments for backward compatibility, and use default value false for forceConnected, and
-use || instead of | in expression.

bool ESPTelnet::begin(uint16_t port /* = 23 */, bool forceConnected /* = false */) {
  ip = "";
  // connected to WiFi or is ESP in AP mode?
  if (forceConnected || WiFi.status() == WL_CONNECTED || _isIPSet(WiFi.softAPIP()))

To me ethConnected seems a more descriptive name than forceConnected. In my code eth.connected() must become true to set ethConnected true.

@LennartHennigs
Copy link
Owner

LennartHennigs commented Oct 30, 2022

Hey @Arnold-n,
thanks for reaching out. I find your and @Mynogs request a valid one.
As you seem to be using an ethernet connection, too, could you please verify that this line of code:

server = WiFiServer(port);

...in the begin() function does not create a problem?
That would be helpful.
Thx.

Cheers
l.

@Arnold-n
Copy link

Thanks @LennartHennigs - and indeed WiFiServer does not create a problem.

I agree with @Mynogs that the name WiFiServer is confusing, I think it should have been called NetworkServer as (in my limited understanding of things) it just seems to use whichever network connection is available.

In my code I use

#include <WiFiClient.h> // WiFiClient (-> TCPClient), WiFiServer (->TCPServer)
 using TCPClient = WiFiClient;
 using TCPServer = WiFiServer;

and setup() uses ethernet if available and if a connection can be made, or else it falls back to WiFi. In both cases telnet is working fine, even after a dis- and reconnect.

ESPTelnet telnet;
#include "W5500lwIP.h"
Wiznet5500lwIP eth(CSPIN);

setup() {
  .. /* set up SPI and W5500 ethernet here */
  if (eth.connected()) {
    telnet.begin(23, true);
  } else {
    .. /* set up WiFi here */ ..
    telnet.begin(23);
  }

What I didn't achieve yet is a change from ethernet to WiFi if ethernet gets disconnected after setup() finishes (and back when it is reconnected).

For anyone using the code above for a W5500, it is important to apply this patch to the BSP if the W5500 may be absent or unpowered, to avoid a WDT crash upon boot.

@LennartHennigs
Copy link
Owner

LennartHennigs commented Nov 3, 2022

Hey @Arnold-n and @Mynogs,
I added a second parameter to the begin() function:

bool begin(uint16_t port = 23, bool checkConnection = true);

This allows you to bypass the WiFi check.
It's on Github already will soon release it officially.

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

No branches or pull requests

3 participants