Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error ESP8266TelnetCliennt.cpp #15

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 3 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,6 @@
# Arduino-Telnet-Client
a minimal (but real) telnet client for Arduino, <b>actually able to login and send commands to a generic telnet server.</b>
# ESP8266-Telnet-Client

<h2>Getting Started:</h2>
It's a normal Arduino library...so just install it and take a look at the example provided to understand how to use it!<br>
<a href="https://www.arduino.cc/en/Guide/Libraries">how to install an Arduino library</a>
Based on the excellent work of @alejho. (https://github.com/alejho)

<h2>Useful tips:</h2>
https://github.com/alejho/Arduino-Telnet-Client

<b>By default</b> the connection is made on <b>port 23</b>, but you can specify a different port passing it as optional argument to the login method.

<b>By default</b> the answer received from the server is <b>printed on serial port</b>, but you can <b>edit just the "print()" method in TelnetClient.cpp to redirect the chars received</b> from the server as you prefer.

<a href="https://imgbb.com/"><img src="https://i.ibb.co/6ykMpDV/print.png" alt="print" border="0"></a>

<b>The only thing you have to configure in your sketch is the char that represent the "prompt"</b> for the server you're connecting to:

<a href="https://imgbb.com/"><img src="https://i.ibb.co/jMJ7LtX/prompt-char.png" alt="prompt-char" border="0"></a>

for this use this function in your sketch:

<a href="https://ibb.co/1n6vZBg"><img src="https://i.ibb.co/VNmjVb1/prompt-char2.png" alt="prompt-char2" border="0"></a>

There are some other <b>configuration parameters</b> you can modify in the header file (Telnet.h).
They are quite self explanatory:

<a href="https://ibb.co/dM5Ljz1"><img src="https://i.ibb.co/V9qQJPr/param.png" alt="param" border="0"></a>

<h2>Messing with a Mikrotik router?</h2>
For some reason I don't understand you're not the first here for this!<br>
I didn't find an explanation for this, but the telnet server implemented on Mikrotik routers asnwers twice...not a big deal, everything works, but your output can be a little messy:

<a href="https://ibb.co/jVCVxdk"><img src="https://i.ibb.co/CJjJXqK/doubleprompt.png" alt="doubleprompt" border="0"></a>

<h2>Known issues:</h2>
It seems that login continuously resetting arduino many times in a short time cause problems at the Ethernet shields...it simply begin to work not properly or to not connect at all.<br>
In this case the only solution seems to disconnect/reconnect the power supply...hope to find a solution for this.

<h2>Troubleshooting:</h2>

For any issue you want to report about this library please uncomment <b>this macro (TNDBG)</b> in the header file

<a href="https://ibb.co/tp4b3Zx"><img src="https://i.ibb.co/XxbzVy3/tndbg.png" alt="tndbg" border="0"></a>

then <b>post the output or your sketch in the <b>Issues section</b> being as specific as possible</b> (share your code, and explain what you're trying to do!).<br>
In general I'm very happy to receive feedback and to help people with their projects...but remember that is just an hobby for me, I'm doing it for free...so words as <b>"please" and "thank you" are really appreciated</b>.
86 changes: 86 additions & 0 deletions examples/telnetDraytekRouter/telnetDraytekRouter.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <ESP8266TelnetClient.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

//Enter your Wifi details here (multiple SSIDs possible)
#ifndef STASSID
#define STASSID "**********"
#define STAPSK "**********"
#define STASSID2 "*********"
#define STAPSK2 "*********"
#endif

//put here your router ip address, and login details
IPAddress draytekRouterIp (192, 168, 1, 2);
const char* user = "************";
const char* pwd = "***********";

const char* ssid = STASSID;
const char* password = STAPSK;
const char* ssid2 = STASSID2;
const char* password2 = STAPSK2;


ESP8266WiFiMulti WiFiMulti;

WiFiClient client;

ESP8266telnetClient tc(client);



void setup () {

Serial.begin (9600);

// We start by connecting to a WiFi network
WiFi.mode(WIFI_STA);
WiFiMulti.addAP(ssid, password);
WiFiMulti.addAP(ssid2,password2);

Serial.println();
Serial.println();
Serial.print("Wait for WiFi... ");

while (WiFiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}

Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Connecting.... ");




//WHICH CHARACTER SHOULD BE INTERPRETED AS "PROMPT"?
tc.setPromptChar('>');

//this is to trigger manually the login
//since it could be a problem to attach the serial monitor while negotiating with the server (it cause the board reset)
//remove it or replace it with a delay/wait of a digital input in case you're not using the serial monitors

// char key = 0;
// Serial.println("\r\npress Enter to begin:");
// do{
// key = Serial.read();
// }while(key<=0);

//PUT HERE YOUR USERNAME/PASSWORD
if(tc.login(draytekRouterIp, user, pwd)){ //tc.login(RouterIp, "admin", "", 1234) if you want to specify a port different than 23
tc.sendCommand("ipf view -V");
tc.sendCommand("exit");
}
else{
Serial.println("login failed");
}
tc.disconnect();

}

void loop () { // run your loop routine

}
62 changes: 45 additions & 17 deletions examples/telnetMikrotikRouter/telnetMikrotikRouter.ino
Original file line number Diff line number Diff line change
@@ -1,31 +1,59 @@
#include <TelnetClient.h>
#include <SPI.h>
#include <Ethernet.h>
#include <ESP8266TelnetClient.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

//Enter your Wifi details here (multiple SSIDs possible)
#ifndef STASSID
#define STASSID "**********"
#define STAPSK "**********"
#define STASSID2 "*********"
#define STAPSK2 "*********"
#endif

EthernetClient client;
telnetClient tc(client);
//put here your raspi ip address, and login details
IPAddress mikrotikRouterIp (192, 168, 1, 2);
const char* user = "************";
const char* pwd = "***********";

byte clientMAC[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress clientIp (192, 168, 1, 177);
const char* ssid = STASSID;
const char* password = STAPSK;
const char* ssid2 = STASSID2;
const char* password2 = STAPSK2;

//put here your router's ip address
IPAddress mikrotikRouterIp (192, 168, 1, 2);

ESP8266WiFiMulti WiFiMulti;

WiFiClient client;

ESP8266telnetClient tc(client);



void setup () {


Serial.begin (9600);
Ethernet.begin (clientMAC, clientIp);

//want to use dhcp?
//if (!Ethernet.begin (clientMAC)){
//Serial.println("\r\nDHCP error");
//while(1);
//}
// We start by connecting to a WiFi network
WiFi.mode(WIFI_STA);
WiFiMulti.addAP(ssid, password);
WiFiMulti.addAP(ssid2,password);

Serial.println();
Serial.println();
Serial.print("Wait for WiFi... ");

while (WiFiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}

Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Connecting.... ");

//WICH CHARACTER SHOULD BE INTERPRETED AS "PROMPT"?
//WHICH CHARACTER SHOULD BE INTERPRETED AS "PROMPT"?
tc.setPromptChar('>');

//this is to trigger manually the login
Expand Down
63 changes: 46 additions & 17 deletions examples/telnetRaspberry/telnetRaspberry.ino
Original file line number Diff line number Diff line change
@@ -1,29 +1,58 @@
#include <TelnetClient.h>
#include <SPI.h>
#include <Ethernet.h>
#include <ESP8266TelnetClient.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

//Enter your Wifi details here (multiple SSIDs possible)
#ifndef STASSID
#define STASSID "**********"
#define STAPSK "**********"
#define STASSID2 "*********"
#define STAPSK2 "*********"
#endif

EthernetClient client;
telnetClient tc(client);
//put here your raspi ip address, and login details
IPAddress raspberryIp (192, 168, 1, 1);
const char* user = "************";
const char* pwd = "***********";

byte clientMAC[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress clientIp (192, 168, 1, 177);
const char* ssid = STASSID;
const char* password = STAPSK;
const char* ssid2 = STASSID2;
const char* password2 = STAPSK2;

//put here your raspberry's ip address
IPAddress raspberryIp (192, 168, 1, 11);

ESP8266WiFiMulti WiFiMulti;

WiFiClient client;

ESP8266telnetClient tc(client);



void setup () {

Serial.begin (9600);
Ethernet.begin (clientMAC, clientIp);

//want to use dhcp?
//if (!Ethernet.begin (clientMAC)){
//Serial.println("\r\nDHCP error");
//while(1);
//}
// We start by connecting to a WiFi network
WiFi.mode(WIFI_STA);
WiFiMulti.addAP(ssid, password);
WiFiMulti.addAP(ssid2,password);

Serial.println();
Serial.println();
Serial.print("Wait for WiFi... ");

while (WiFiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}

Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Connecting.... ");

//WICH CHARACTER SHOULD BE INTERPRETED AS "PROMPT"?
//WHICH CHARACTER SHOULD BE INTERPRETED AS "PROMPT"?
tc.setPromptChar('$');

//this is to trigger manually the login
Expand Down
9 changes: 9 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=ESP8266TelnetClient
version=0.1
author=RJB
maintainer=RJB
sentence=ESP8266 real Telnet Client
paragraph=Allows esp8266 telnet access with login over multiple wifi ssid
category=Communication
url=https://github.com/videojedi/ESP8266-Telnet-Client
architectures=*
Loading