yasheena / telnetspy Goto Github PK
View Code? Open in Web Editor NEWTelnet Server For ESP8266: Cloning the serial port via Telnet. "Debugging over the air"
License: MIT License
Telnet Server For ESP8266: Cloning the serial port via Telnet. "Debugging over the air"
License: MIT License
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?
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.
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.
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!
Compiling error when i try to compile with esp8266 2.6.3 platform
/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.
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
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..
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))
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.
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.
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).
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 :-)
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;
}
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?
Hello,
Unfortunately, verbose output from serial is not transferred via Telnet only Print, Println etc.
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.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.