I am new to Arduino. I used Arduino IDE for upload code to ESP8266 module. I wrote an ATM application on the tiva-tm4c123 board. I am trying to connect to the application from the internet using telnet and ip address. I uploaded the example code of the ESPtelnet library to the ESP8266 module and connected the esp wifi module to the tm4c123 card by using uart. The ESP8266 module sends the data from the tiva card to the putty screen that I connect via telnet. But it does not transfer what I write from the putty screen to the tiva card. I couldn't find a function like telnet.read(). Is there a telnet function that will read the data from the Putty screen? I searched a lot but couldn't find it. If I find this function, I know that I can send the read data to the tiva card with Serial.write(telnet.read).ESP's RX and TX are connected to the tiva card. I created a wireless connection to the Putty screen. When a char or string is entered on the telnet screen, it will send it to the tiva card with Serial write from the TX of the ESP8266.I want to write a code that will run in the following logic.
if (telnet.available()) {
Serial.print(telnet.read());
}
Here is the example code
#include "ESPTelnet.h"
/* ------------------------------------------------- */
#define SERIAL_SPEED 115200
#define WIFI_SSID "****"
#define WIFI_PASSWORD "****"
/* ------------------------------------------------- */
ESPTelnet telnet;
IPAddress ip;
/* ------------------------------------------------- */
void setupSerial(long speed, String msg = "") {
Serial.begin(speed);
while (!Serial) {
}
delay(200);
Serial.println();
Serial.println();
if (msg != "") Serial.println(msg);
}
/* ------------------------------------------------- */
bool isConnected() {
return (WiFi.status() == WL_CONNECTED);
}
/* ------------------------------------------------- */
bool connectToWiFi(const char* ssid, const char* password, int max_tries = 20, int pause = 500) {
int i = 0;
WiFi.mode(WIFI_STA);
#if defined(ARDUINO_ARCH_ESP8266)
WiFi.forceSleepWake();
delay(200);
#endif
WiFi.begin(ssid, password);
do {
delay(pause);
Serial.print(".");
} while (!isConnected() || i++ < max_tries);
WiFi.setAutoReconnect(true);
WiFi.persistent(true);
return isConnected();
}
/* ------------------------------------------------- */
void errorMsg(String error, bool restart = true) {
Serial.println(error);
if (restart) {
Serial.println("Rebooting now...");
delay(2000);
ESP.restart();
delay(2000);
}
}
/* ------------------------------------------------- */
void setupTelnet() {
// passing on functions for various telnet events
telnet.onConnect(onTelnetConnect);
telnet.onConnectionAttempt(onTelnetConnectionAttempt);
telnet.onReconnect(onTelnetReconnect);
telnet.onDisconnect(onTelnetDisconnect);
// passing a lambda function
telnet.onInputReceived([](String str) {
// checks for a certain command
if (str == "ping") {
telnet.println("> pong");
Serial.println("- Telnet: pong");
}
});
Serial.print("- Telnet: ");
if (telnet.begin()) {
Serial.println("running");
} else {
Serial.println("error.");
errorMsg("Will reboot...");
}
}
/* ------------------------------------------------- */
// (optional) callback functions for telnet events
void onTelnetConnect(String ip) {
Serial.print("- Telnet: ");
Serial.print(ip);
Serial.println(" connected");
}
void onTelnetDisconnect(String ip) {
Serial.print("- Telnet: ");
Serial.print(ip);
Serial.println(" disconnected");
}
void onTelnetReconnect(String ip) {
Serial.print("- Telnet: ");
Serial.print(ip);
Serial.println(" reconnected");
}
void onTelnetConnectionAttempt(String ip) {
Serial.print("- Telnet: ");
Serial.print(ip);
Serial.println(" tried to connected");
}
/* ------------------------------------------------- */
void setup() {
setupSerial(SERIAL_SPEED, "Telnet Test");
Serial.print("- Wifi: ");
connectToWiFi(WIFI_SSID, WIFI_PASSWORD);
if (isConnected()) {
ip = WiFi.localIP();
Serial.print(" ");
Serial.println(ip);
setupTelnet();
} else {
Serial.println();
errorMsg("Error connecting to WiFi");
}
}
/* ------------------------------------------------- */
void loop() {
telnet.loop();
// send serial input to telnet as output
// this part read tiva and transmit to ESP
if (Serial.available()) {
telnet.print(Serial.read());
}
}
//* ------------------------------------------------- */