ESPTelnet icon indicating copy to clipboard operation
ESPTelnet copied to clipboard

Feature change: Inherit ESPTelnet from WiFiClient so that it is a Stream

Open AFontaine79 opened this issue 3 years ago • 6 comments

Right now, ESPTelnet contains WiFiClient as one of its members. This is a has a relationship. WiFiClient itself inherits from Stream as follows: WiFiClient --> ESPLwIPClient --> Client --> Stream If ESPTelnet inherited from WiFiClient, then code like the following would be unnecessary:

void ESPTelnet::print(String str) {
  if (client && client.status() == ESTABLISHED) {
    client.print(str); 
  }
}

This may be a little tricky to figure out since the WiFiClient object is returned by the WebServer object. Doing client = is fairly straightforward, but I don't think you can just do this = inside a member function. I'm going to think about this a bit.

Anyway, the motivation is that having this a Stream object makes it fully compatible with Serial. I want to be able to pass a generic Stream to a CLI module and not have it be concerned with whether the transport is telnet or serial.

Would you be open to me working on this and potentially contributing some updates to this library?

AFontaine79 avatar Mar 24 '21 16:03 AFontaine79

Hey Aaron, That would be kind of neat. Sure, take a stab at it.

That's why I have all the stuff online - for people to use and tinker with it...

Cheers l.

LennartHennigs avatar Mar 24 '21 19:03 LennartHennigs

Hi Lennart, Sorry I've been slow to respond on this. It's been a quite busy couple of weeks. I would like to take a stab at the changes. One thing I notice is that WiFiClient already inherits from Stream. It seems that rather than ESPTelnet inheriting from Stream, it should return a reference to the current connection. I'm going to put some consideration into this as I work on the CLI module.

A.

AFontaine79 avatar Apr 07 '21 21:04 AFontaine79

Nice and clean lib. Returning a client ref it would help a lot to output serial on telnet.

SergiuToporjinschi avatar Jul 11 '21 18:07 SergiuToporjinschi

[Nov 21] Has this work completed? If so, what version of the Library (will it) appear in. I's seeing Version 1.2.1 on Arduino

RichK2015 avatar Nov 14 '21 14:11 RichK2015

no, not completed. there is a working branch that uses it. still need to decide how to split/branch out functionality.

LennartHennigs avatar Nov 15 '21 11:11 LennartHennigs

// send indvidual characters } else { if (on_input != NULL) { if (input.length()) { on_input(input + c);//** input = ""; } else { on_input(String(c)); } } //** on_input(input + String(c));

kantat avatar Sep 26 '22 18:09 kantat

There is now an ESPTelnetStream class in version 2.0.0 that provides the mentioned functionality. Thanks again to @AFontaine79 for providing the base for it!

LennartHennigs avatar Nov 20 '22 23:11 LennartHennigs