Go Down

Topic: Is there a easy way to telnet directly to YUN? (Read 2956 times) previous topic - next topic

beedrill

I just started using YUN and I followed this guide:
https://www.arduino.cc/en/Guide/ArduinoYun

The console seems convenient and it works fine if I do:
 
Code: [Select]
ssh root@yourYunsName.local 'telnet localhost 6571'

in the command line.

However, it would be more convenient if I can simply do:

Code: [Select]
telnet 192.168.253.14(the ethernet IP of YUN) 6571

from another machine in the ethernet, therefore, I can directly write a telnet client and interact with YUN 32U4 programme.

Right now, it seems it's blocking all the telnet request unless it's the local machine. How can I get through this?

Thank you!

jessemonroy650

@beedrill,
It is possible to open a telnet session, but it is not advised - especially if you are on wifi.

WEP was never really secure, and WPA2 is more secure, but not enough.

Perhaps, what you need to do is easily possible with SSH. For instance, you can setup port forwarding, which might meet your needs. What are you trying to do?

FWIW: I was one of the opponents to SSH when it was being pushed on people.
SSH - are you nuts!?!

Jesse

ShapeShifter

beedrill, since you are talking about the Console class, I assume you want to have your sketch talk over a Telnet session instead of the hardware Serial port of the Console class - you want to be able to connect directly to that connection without having to SSH into the Yun and then start a local Telnet session. Is that correct?

It can be done, but note that this ONLY talks to the sketch, it cannot be used as a replacement for SSH in order to get to the Linux command line.  And, as Jesse points out, there is no security, so it's up to you to figure out a solution to that if you need it. (If you're just displaying debug output on your local network, you probably don't.)

I've posted this a few times. The solution is to use a YunServer/YunClient in the sketch. This implements a TCP socket, and if you use port 23, you can connect to it with any Telnet client. Just be aware that this is actually a raw TCP socket, and not a Telnet server. Telnet is a protocol that runs on top of a TCP stream, and adds a lot of terminal session control features. One of the things it does is an initial negotiation sequence where it figures out things like full/half duplex, terminal capabilities, etc. When a standard Telnet client makes a connection, it goes through this negotiation process. The YunClient will receive these and pass them on to the sketch as some initial garbage, and will not reply to the negotiation. This is not normally  a problem, but just be aware that the sketch is likely to get a dozen or so garbage characters at the start of the connection.

A simple example sketch:
Code: [Select]
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>

#define PORT 255
YunServer server(PORT);
YunClient client;


void setup()
{
   pinMode(13, OUTPUT);
   digitalWrite(13, HIGH);
   Bridge.begin();   // Bridge startup

   Serial.begin(115200);
   while (!Serial)
   {
      digitalWrite(13, HIGH);
      delay(125);
      digitalWrite(13, LOW);
      delay(125);
   }  
   Serial.println("Server listening on port 255");
   server.noListenOnLocalhost();
   server.begin();
   client = server.accept();
}



void loop()
{
   // There are two interesting flags in the client:
   //    opened    - read by converting the client object to a bool.
   //    connected - read by calling the connected() method
   // This gives four combinations:
   //    closed and no connection   - Try to accept a new connection.
   //    closed and connected       - Not possible.
   //    open and no connection     - Connection just closed, stop the client to clean up.
   //    open and connected         - Ready to go, process the connection

   if (client.connected())
   {
      // There is a valid connection open.
      // Read and echo any input to the serial port
      if (client.available())
      {
        Serial.print("From client: \"");
        
        while (client.available())
          Serial.print((char)client.read());
        
        Serial.println("\"");
      }
      
      // Send something to the client
      client.println("Hello Client!");
   }
   else
   {
      // The client is not connected. Is it open (previously connected?)
      if ((bool)client)
      {
         // The client is currently open, but is not connected.
         // That means that there was a valid connection the last time around the loop.
         // There was a connection on the client, but it has just closed.
         // It's necessary to stop a closed connection, otherwise resoruces are not freed
         // and the server will stop accepting new connections after about 256 sessions.
         client.stop();
         Serial.println("Client disconnected.");
      }

      // At this point the client is not connected, and has been gracefully closed.
      // Try to accept a new connection.
      client = server.accept();

      // Is the client now connected? If so, we have a new connection.
      if (client.connected())
         Serial.print("New client connection: ");
   }
}


This code uses port 255 (an arbitrary choice on my part.) If you want to use a standard Telnet client, you may want to use port 23 (although most Telnet clients let you specify the port.)

The sketch starts out by enabling the Bridge, then waiting for a USB serial connection - the LED flashes rapidly while waiting. It then starts a YunServer listening on port 255.

loop() actually manages the connection. It prints out messages to the serial port when connections are made and broken: you might want to do something special when that happens, but at a minimum make sure you keep the code that stops the client when the connection is closed.

While a connection is established, it reads all incoming data and echos it to the serial port, and sends a constant string to the other end of the connection. You will no doubt want to do something more intelligent there.

sonnyyu

I just started using YUN and I followed this guide:
https://www.arduino.cc/en/Guide/ArduinoYun

The console seems convenient and it works fine if I do:
 
Code: [Select]
ssh root@yourYunsName.local 'telnet localhost 6571'

in the command line.

However, it would be more convenient if I can simply do:

Code: [Select]
telnet 192.168.253.14(the ethernet IP of YUN) 6571

from another machine in the ethernet, therefore, I can directly write a telnet client and interact with YUN 32U4 programme.

Right now, it seems it's blocking all the telnet request unless it's the local machine. How can I get through this?

Thank you!
http://www.ibuyopenwrt.com/index.php/8-yun-compatible/158-console-class


Now we need redirect port 8888 of Arduino Yun ip (i.e. 192.168.0.102) to localhost (127.0.0.1) 6571.

Code: [Select]
opkg update
opkg install socat

(socat TCP-LISTEN:8888,fork TCP:127.0.0.1:6571) &



Now you should be able access Yun from PC

Code: [Select]
telnet 192.168.0.102 8888



Go Up