我是Arduino的新手。我使用Arduino IDE用于上传代码到ESP8266模块。我在Tiva-TM4C123板上写了一个ATM应用程序。我正在尝试使用Telnet和IP地址从Internet连接到应用程序。我将ESPTELNET库的示例代码上传到ESP8266模块,并使用UART将ESP WiFi模块连接到TM4C123卡。ESP8266模块将数据从TIVA卡发送到我通过Telnet连接的Putty屏幕。但它不会转移我从Putty屏幕写入Tiva卡的内容。我找不到像telnet.read()这样的函数。是否有一个Telnet函数,可以从Putty屏幕中读取数据?我搜索了很多但找不到它。 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());}
下面是示例代码
#include“esptelnet.h”/ * -------------------------------------------- * / #define serial_speed 115200 #define wifi_ssid“****”#define wifi_password“****”/ * ------------------------------------------------- * / esptelnet telnet;ipaddress ip;/ * ------------------------------------------- * / void setupserial(长速度,String msg =“”){serial.begin(速度);虽然(!序列){}延迟(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()); } } //* ------------------------------------------------- */
Serial.write (telnet.read ());
.最好是使用而
比如果
在这里:而(telnet.available ())