GithubHelp home page GithubHelp logo

yasheena / telnetspy Goto Github PK

View Code? Open in Web Editor NEW
59.0 8.0 31.0 63 KB

Telnet Server For ESP8266: Cloning the serial port via Telnet. "Debugging over the air"

License: MIT License

C++ 100.00%
arduino-library esp8266 telnet-server debugging-tool over-the-air esp32 arduino rfc854 serial

telnetspy's People

Contributors

anubisg1 avatar leojz avatar maxgerhardt avatar obrain17 avatar race2infinity avatar yasheena avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

telnetspy's Issues

Does not work in AP only mode (ESP32)

I was never able to establish a connection when using AP only mode on an ESP32 (never tried an 8266).

I have changed the code in handle() to do this about line 548 (commented out below) and I can now use a telnet client when using the AP connection:

```

if (!listening) {

wifi_mode_t currentMode = WiFi.getMode();
bool isAPEnabled = ((currentMode & WIFI_MODE_AP) != 0);
bool isSTAconnected = WiFi.status() == WL_CONNECTED;

// if (WiFi.status() != WL_CONNECTED) {
if (!isSTAconnected && !isAPEnabled)
return;
}

It is possible to use it without the ring buffer?

It is possible to use it without the ring buffer?

I mean: if I sometimes want to connect to the ESP8266 to se the actual debug messages and not the previous ones? Just like serial, if there is one connected sees the messages otherwise they are lost.

newlines not rendered on Windows telnet

Thanks for the great library. I'm using it in one of my projects to replace some home grown telnet logging libraries. I noticed when using Telnet on Windows the newlines are not left-justified. I think this is because you need a '\r' after a '\n'. For example using your stock example code in a Serial window it shows correctly as:

Connecting to WiFi . Connected!
Ready
IP address: 10.10.10.28

Type 'C' for WiFi connect.
Type 'D' for WiFi disconnect.
Type 'R' for WiFi reconnect.
All other chars will be echoed. Play around...

but in the telnet window:

                                Connecting to WiFi . Connected!
Ready
IP address: 10.10.10.28

Type 'C' for WiFi connect.
                          Type 'D' for WiFi disconnect.
                                                       Type 'R' for WiFi reconnect.
All other chars will be echoed. Play around...

Telnet connection established.

Works fine using telnet from Linux, like an ubuntu shell in Windows10 though.

Linker error when building for ESP32-C3

When building a project in PlatformIO targeting the ESP32-C3, the linker throws the following error:

Linking .pio\build\m5stamp-c3\firmware.elf
c:/users/a/.platformio/packages/toolchain-riscv32-esp/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: .pio\build\m5stamp-c3\libda1\libTelnetSpy.a(TelnetSpy.cpp.o): in function `TelnetSpy::debugWrite(unsigned char)':
G:\Documents\PlatformIO\Projects\Mux Controller/.pio/libdeps/m5stamp-c3/TelnetSpy/TelnetSpy.cpp:346: undefined reference to `ets_write_char_uart'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\m5stamp-c3\firmware.elf] Error 1

Based on this issue in the ESP-IDF repo, it seems ets_write_char_uart() is no longer available for the ESP32-C3. I've managed to bypass this error for now with setDebugOutput(false) and commenting out the debugWrite() and line 520 in TelnetSpy.cpp, but perhaps there is a better solution using the UART driver's uart_tx_chars() instead (I can't seem to find uart_tx_one_char() as suggested in the linked issue in the C3's API reference).

On another note, thank you for all your work on this library!

Example code doesn't compile on 1.8.13

/home/jwl/sketchbook/libraries/telnetspy-master/TelnetSpy.cpp: In member function 'void TelnetSpy::setDebugOutput(bool)':
/home/jwl/sketchbook/libraries/telnetspy-master/TelnetSpy.cpp:406:42: error: invalid conversion from 'void*' to 'fp_putc_t {aka void ()(char)}' [-fpermissive]
os_install_putc1((void
) TelnetSpy_putc); // Set system printing (os_printf) to TelnetSpy
^
In file included from /home/jwl/.arduino15/packages/esp8266/hardware/esp8266/2.7.1/tools/sdk/include/os_type.h:28:0,
from /home/jwl/.arduino15/packages/esp8266/hardware/esp8266/2.7.1/tools/sdk/include/user_interface.h:28,
from /home/jwl/sketchbook/libraries/telnetspy-master/TelnetSpy.cpp:12:
/home/jwl/.arduino15/packages/esp8266/hardware/esp8266/2.7.1/tools/sdk/include/ets_sys.h:219:6: error: initializing argument 1 of 'void ets_install_putc1(fp_putc_t)' [-fpermissive]
void ets_install_putc1(fp_putc_t routine);
^
/home/jwl/sketchbook/libraries/telnetspy-master/TelnetSpy.cpp:415:50: error: invalid conversion from 'void*' to 'fp_putc_t {aka void ()(char)}' [-fpermissive]
os_install_putc1((void
) TelnetSpy_ignore_putc); // Ignore system printing
^
In file included from /home/jwl/.arduino15/packages/esp8266/hardware/esp8266/2.7.1/tools/sdk/include/os_type.h:28:0,
from /home/jwl/.arduino15/packages/esp8266/hardware/esp8266/2.7.1/tools/sdk/include/user_interface.h:28,
from /home/jwl/sketchbook/libraries/telnetspy-master/TelnetSpy.cpp:12:
/home/jwl/.arduino15/packages/esp8266/hardware/esp8266/2.7.1/tools/sdk/include/ets_sys.h:219:6: error: initializing argument 1 of 'void ets_install_putc1(fp_putc_t)' [-fpermissive]
void ets_install_putc1(fp_putc_t routine);
^
Multiple libraries were found for "ArduinoOTA.h"
Used: /home/jwl/.arduino15/packages/esp8266/hardware/esp8266/2.7.1/libraries/ArduinoOTA
Not used: /home/jwl/sketchbook/libraries/ArduinoOTA
exit status 1
Error compiling for board Generic ESP8266 Module.

TelnetSpy.cpp:17:21: fatal error: RingBuf.h: No such file or directory

Compiling .pio\build\esp07\lib6c5\TelnetSpy_ID6236\TelnetSpy.cpp.o
.pio\libdeps\esp07\TelnetSpy_ID6236\TelnetSpy.cpp:17:21: fatal error: RingBuf.h: No such file or directory
......
 #include <RingBuf.h>
                     ^
compilation terminated.
*** [.pio\build\esp07\lib6c5\TelnetSpy_ID6236\TelnetSpy.cpp.o] Error 1

looks like a missing undocumented dependency

Issues when using platformIO

I just found this library and it suits my need. Thanks! I'm using platformio as my environment. It's really neat and way better than the arduino IDE. There are some issues with this library, however..

  1. There is no "max" defined.
void TelnetSpy::setMinBlockSize(uint16_t minSize) {
  minBlockSize = max(1, minSize);
}

So I had to include this in the code

#undef max
#define max(a,b) ((a)>(b)?(a):(b))

  1. There is no RingBuf.h
    You might want to update the readme to include something about which library is needed to be included. I used
    url=https://github.com/wizard97/ArduinoRingBuffer
    And it seems to work.

  2. in the example code and in the readme you have in the master branch you have:

This function installs a callback function which will be called on every telnet connect of this object (except rejected connect tries). Use NULL to remove the callback.
Default: NULL

void setCallbackOnConnect(void (*callback)());
and it's not there in the 1.1 tag. Maybe add something to the master branch readme to have it mention to use the 1.1 readme and example.

TelnetSpy.cpp: In member function 'void

C:\Users\ucupu\Documents\Arduino\libraries\TelnetSpy\TelnetSpy.cpp: In member function 'void TelnetSpy::setDebugOutput(bool)':
C:\Users\ucupu\Documents\Arduino\libraries\TelnetSpy\TelnetSpy.cpp:406:42: error: invalid conversion from 'void*' to 'fp_putc_t {aka void ()(char)}' [-fpermissive]
os_install_putc1((void
) TelnetSpy_putc); // Set system printing (os_printf) to TelnetSpy
^
In file included from C:\Users\ucupu\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4/tools/sdk/include/os_type.h:28:0,
from C:\Users\ucupu\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4/tools/sdk/include/user_interface.h:28,
from C:\Users\ucupu\Documents\Arduino\libraries\TelnetSpy\TelnetSpy.cpp:12:
C:\Users\ucupu\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4/tools/sdk/include/ets_sys.h:219:6: error: initializing argument 1 of 'void ets_install_putc1(fp_putc_t)' [-fpermissive]
void ets_install_putc1(fp_putc_t routine);
^
C:\Users\ucupu\Documents\Arduino\libraries\TelnetSpy\TelnetSpy.cpp:415:50: error: invalid conversion from 'void*' to 'fp_putc_t {aka void ()(char)}' [-fpermissive]
os_install_putc1((void
) TelnetSpy_ignore_putc); // Ignore system printing
^
In file included from C:\Users\ucupu\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4/tools/sdk/include/os_type.h:28:0,
from C:\Users\ucupu\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4/tools/sdk/include/user_interface.h:28,
from C:\Users\ucupu\Documents\Arduino\libraries\TelnetSpy\TelnetSpy.cpp:12:
C:\Users\ucupu\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4/tools/sdk/include/ets_sys.h:219:6: error: initializing argument 1 of 'void ets_install_putc1(fp_putc_t)' [-fpermissive]
void ets_install_putc1(fp_putc_t routine);
^
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

Error compiling on Arduino Nano ESP32 - cannot convert USBCDC* to HardwareSerial*

Had this error building synman/BME280 for an Arduino Nano ESP32 on PlatformIO.

lib/TelnetSpy/TelnetSpy.cpp:43:13: error: cannot convert 'USBCDC*' to 'HardwareSerial*' in assignment
Google suggested this compile flag:
platformio_options:
board_build.extra_flags:
- "-DARDUINO_USB_CDC_ON_BOOT=0"

Which didn't solve the problem because I put the entire section in, when it should have looked like:
build_flags =
-D PROJECT_NAME='"BME280 Sensor Publisher"'
-D HOSTNAME='"bme280-env-sensor"'
-D ELEGANTOTA_USE_ASYNC_WEBSERVER=1
-D ARDUINO_USB_CDC_ON_BOOT=0
-D BS_USE_TELNETSPY
-D BME280_LOG_LEVEL_BASIC

I kept searching and found an alternative fix...

https://www.esphome.io/api/uart__component__esp32__arduino_8cpp_source

There's this small section :
#if ARDUINO_USB_CDC_ON_BOOT
this->hw_serial_ = &Serial0;
#else
this->hw_serial_ = &Serial;
#endif

The build has the flag set to 0, which forces the serial value to &Serial which fails on the ESP32S3.
Changing the build flag to 1 has no effect.

So I tried changing the value of usedSer = &Serial to usedSer = &Serial0, that worked, but so did the compile flag when platformio.ini was configured properly, my bad.

The compile now runs to building a firmware image :-)

disconnect telnet client feature?

One idea to add is a function to close a telnet client session. For example in an active Telnet session, I would capture a ctrl-D (from a SerialAndTelnet.read()) which would exit the Telnet session, but keep the serial and everything else active. The only way I think you could do this now is by calling end() which kills both the server and client?

so like

void TelnetSpy::disconnectClient() {
    if (client.connected()) {
        client.flush();
        client.stop();
    }
    if (connected && (callbackDisconnect != NULL)) {
        callbackDisconnect();
    }
    connected = false;
}

no matching function for call to 'TelnetSpy::begin()'

Hello,

I’m receiving no matching function for call to 'TelnetSpy::begin()' during compilation in Arduino IDE 1.8.10 with ESP32 board:


error: no matching function for call to 'TelnetSpy::begin()'

     LOG.begin();

               ^
libraries\telnetspy-master/TelnetSpy.h:208:8: note: candidate: void TelnetSpy::begin(long unsigned int, uint32_t, int8_t, int8_t, bool)

   void begin(unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1, bool invert=false);

        ^
libraries\telnetspy-master/TelnetSpy.h:208:8: note:   candidate expects 5 arguments, 0 provided

no matching function for call to 'TelnetSpy::begin()'

I’ve added these code to my sketch:

#include <TelnetSpy.h>
TelnetSpy LOG;
Add the following line to your initialisation block void setup():

LOG.begin();
Add the following line at the beginning of your main loop void loop():

LOG.handle();

@yasheena
Any ideas what can be wrong?

Possible bug in handle() method...

Hi,
First of all thank you for your library, it is just what I was looking for to incorporate in one of my projects.
I have however detected that if an active connection from a client happens to go down before or without properly disconnecting the server will always drop any new connection attempt.

**if (!started || serverClient) {
  telnetServer.available().stop();**
} else {
  serverClient = telnetServer.available();
  if (strlen(welcomeMsg) > 0) {
   serverClient.write((const uint8_t*)welcomeMsg, strlen(welcomeMsg));
   serverClient.flush();
  }
}

For now I have just made a change to stop/disconnect any active connection if a new one comes in but I think implementing a simple watchdog timeout on active data transfer to stop/disconnect would be a better solution.
If the intended behaviour is as it currently is, please forgive me and ignore this.

do I have to keep calling handle()

I am looking for a telnet logging method, that basically only send logging to the telnet client.
The code in which I want to implement it contains a very long running loop(), which will make the SerialAndTelnet.handle(); being called only once in a long time.
Is that handle() needed when I only want to SEND data TO the telnet-client and not receive data from the client? (for me it only needs to send at several points in the long loop)
And also, will it be possible for a telnet-client to connect when the loop is already running or is the handle() needed for a client to connect?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.