Getting an error that a class has no member named

                                                             ^
src/main.cpp:455:21: error: 'class TelnetSpy' has no member named 'setCallbackOnConnect'
 SerialAndTelnet.setCallbackOnConnect(telnetConnected);
                 ^
src/main.cpp:456:21: error: 'class TelnetSpy' has no member named 'setCallbackOnDisconnect'
 SerialAndTelnet.setCallbackOnDisconnect(telnetDisconnected);

However I see this in the TelnetSpy.h file:

void setCallbackOnConnect(void (*callback)());
void setCallbackOnDisconnect(void (*callback)());

Those lines are in the public section of the class.

The callback is defined earlier in the file as:

void telnetConnected() {
SERIAL.println(“Telnet connection established.”);
}

void telnetDisconnected() {
SERIAL.println(“Telnet connection closed.”);
}

The program is working fine in Arduino IDE. I’m just trying to get some experience with PlatformIO.

As a note, I had included the library in the platformio.ini file but when I got that message I went ahead and removed it and downloaded the source into my lib directory so if for some reason I was loading a different library I’d know for sure I was using the right one. It’s no longer defined in the platformio.ini file.

What is your platformio.ini? Is this an ESP8266 or ESP32 project?

Sorry, it’s an ESP8266. This editor won’t let me upload the ini file so here is it’s ugly self.

[env:esp01_1m]
platform = espressif8266
board = esp01_1m
framework = arduino
lib_deps =
    tzapu/WiFiManager@^0.16.0
    knolleary/PubSubClient@^2.8
    yasheena/TelnetSpy@^1.1
monitor_port = /dev/ttyUSB0
monitor_speed = 115200

The author of the library has not updated the library.properties to indicate a new version – it is still the same from 2018 although the code has been changed in 2019 with those functions you need. Thus with

You get an older version. You can also see that by looking into .pio\libdeps\esp01_1m\TelnetSpy\TelnetSpy.h where the actual library was downloaded and see that it has no such function.

To get the current github version which is still unreleased, change the platformio.ini to include a direct download link of the library (or the repo), via https://github.com/yasheena/telnetspy/archive/refs/heads/master.zip.

However, the current version also has a bug which leads to a compilation failure as noted and fixed in Fix bug #13 by anubisg1 · Pull Request #16 · yasheena/telnetspy · GitHub, that still hasn’t been merged by the author. So we have to use the fixed branch

[env:esp01_1m]
platform = espressif8266
board = esp01_1m
framework = arduino
lib_deps =
    tzapu/WiFiManager@^0.16.0
    knolleary/PubSubClient@^2.8
    https://github.com/anubisg1/telnetspy/archive/refs/heads/patch-1.zip
monitor_port = /dev/ttyUSB0
monitor_speed = 115200

Then, a minimal code of

#include <Arduino.h>
#include <WiFiManager.h>
#include <TelnetSpy.h>

void telnetConnected()
{
	Serial.println("Telnet connection established.");
}

void telnetDisconnected()
{
	Serial.println("Telnet connection closed.");
}

TelnetSpy SerialAndTelnet;

void setup()
{
	SerialAndTelnet.setCallbackOnConnect(telnetConnected);
	SerialAndTelnet.setCallbackOnDisconnect(telnetDisconnected);
}
void loop() {}

compiles for me.

1 Like

Wow! Thank you. That seems like going beyond the call of duty. I appreciate the effort very much. That did fix the problem.

Jim.