• In a TCP connection with console piping, LoopbackB.setconsole() throws an error:
    Uncaught InternalError: setDeviceClockCmd: Unknown Device 720 at line 1 col 101
    If the error is caught (the lines are commented out in the code below) LoopbackB.setconsole() does what it's expected to do.
    The code is:

    net.createServer(function(conn) {
        conn.on('close', USB.setConsole);
        conn.pipe(LoopbackA);
        LoopbackA.pipe(conn);
        // try {
            LoopbackB.setConsole();  // setDeviceClockCmd: Unknown Device 720
        // } catch(e) {};
    }).listen(23);
    

    The device is Espruino WiFI on 1.99.

  • Thanks - I just fixed this, so if you wait a few minutes and update a with a 'cutting edge' firmware then you shouldn't have the issue any more

  • The InternalError is gone, but LoopbackB.setconsole() itself doesn't work. There is no output.

  • Ok, thanks - sorry, I'll look into that

  • Hi,
    Same problem here, I am trying to create a remote Telnet connection, similar code as the first post from Steffen, but it doesn't work.

    I have Spruino Wifi 1.99 and connect to port 23 with Putty.

    If I send something like:

    conn.write('Welcome!\r\n');
    

    I see it in Putty, but the terminal does not respond to my keys.

    If I set an event like:

    conn.on('data', function(data) {
          USB.write('client says: ', data);
    });
    

    The text entered on putty is printed on the IDE, so the connection is working.

    Maybe Loopbacks are not working?

    Thanks Gordon

  • Hi César,
    the code in the original post is complete, for a telnet/putty console you just need the 3 lines where the loopbacks are piped. With a try/catch around LoopbackB.setConsole() (commented out in the OP) it works well in v1.99.

  • Hi Steffer,

    I put the try/catch but it was the same, terminal does not respond.

    This is my code

    function initTelnet(){
    
      console.log('Init Telnet');
    
      require("net").createServer(function(soc­ket) {
        
        console.log('Telnet client connected');
        
        socket.write('Welcome!\r\n');
        
        socket.on('error', function(err){
          USB.write(err);
        });
    
        /*socket.on('data', function(data) {
          //just a test to verify connection
          //USB.write("client says " + data);
        });*/
    
        socket.on('close', function() {
          USB.setConsole();
        });
    
        socket.pipe(LoopbackA);
        LoopbackA.pipe(socket);    
        
        try{
          LoopbackB.setConsole();
        } catch(e){
          USB.write(e);
        }
        
      }).listen(23);
    }
    
    function onInit() {
    
      console.log("Init Wifi");
      
      wifi = require("Wifi");
    
      wifi.connect("................", {password : ".................."}, function(err) {
        
        console.log("Wifi Connected");
        
        initTelnet();    
        
      });
    }
    

    When connecting with putty I see:

    Welcome!
    <- USB
    >
    

    and nothing else, no response to commands.

    ...
    EDITED the code to remove the ondata event

  • Try using the code from the OP exactly as is. The socket ondata handler definitely spoils it!

  • Ok, I removed the data event.

    Now, on connecting I get a lot of garbage, something like:

    ▒ ▒ ▒▒''▒ ▒ ▒▒▒'▒' ▒▒' ▒ ▒ ▒ ▒▒▒'▒' ▒▒' ▒ ▒ ▒ ▒▒▒'▒' ▒▒' ▒ ▒ ▒ ▒▒▒'▒' ▒▒'▒▒▒▒▒▒'
    ▒▒▒'▒▒'   ▒ ▒ ▒▒▒'   ▒▒'   ▒ ▒ ▒▒▒'   ▒▒'   ▒ ▒ ▒▒▒'   ▒▒'   ▒ ▒ ▒▒▒'   ▒▒'
    :▒▒▒▒'
    
    

    I also modified the try/catch block like this:

    try{
          LoopbackB.setConsole();
        } catch(e){
          USB.write("LoopbackB.setConsole(): " + e.type + " " + e.message + " " + e.stack);
        }
    

    and on connecting putty, the IDE shows the "setDeviceClockCmd" error, so it's still there.

  • I have now fixed the issues with Loopback not working on the cutting edge builds (turns out it was related to the addition of Software Serial support).

    I'm looking into the corruption now - I can reproduce it here too.

  • Ok, so the issue is that the telnet tool itself seems to send a whole bunch of weird characters when it connects (they are part of the actual telnet protocol). Something along the lines of:

    \xFF\xFD\x03\xFF\xFB\x18\xFF\xFB\x1F\xFF­\xFB \xFF\xFB!\xFF\xFB\"\xFF\xFB'\xFF\xFD\x05­\xFF\xFB#
    

    These really confuse Espruino as they're fed right into the console, and Espruino doesn't know to ignore them.

    However if you connect using the Chrome App IDE (communications -> connect over TCP address) it won't send the characters and everything works great.

    You can also use putty on Windows - just set the connection type to 'raw' when you connect.

  • yes it works!

    now I can send new code from IDE via wifi :D thanks Gordon.

    One last thing: First I could not send code because I had the option to "Reset before Send" active. Could you modify the IDE to ignore that option if sending via wireless?

  • Great!

    In an ideal world I'd be able to make the Telnet service low-level enough that it could survive a reset. It's on my Todo list for Espruino WiFi, but it's not straightforward!

    I think the easiest option is just to make reset do something different on Espruino:

    global.reset=function() {
      clearWatch();
      clearInterval();
      console.log("-= RESET =-");
    }
    

    Just to post up the complete code that I have (in case it's useful for anyone):

    var WIFI_NAME = "";
    var WIFI_OPTIONS = { password : "" };
    
    var wifi = require("Wifi");
    wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
      if (err) {
        console.log("Connection error: "+err);
        return;
      }
      console.log("Connected!");
      wifi.getIP(print);
      
      require("net").createServer(function(con­n) {
        conn.on('close', x=>USB.setConsole());
        conn.pipe(LoopbackA);
        LoopbackA.pipe(conn);
        LoopbackB.setConsole();
      }).listen(23);
    });
    global.reset=function() {
      clearWatch();
      clearInterval();
      console.log("-= RESET =-");
    };
    

    It would actually be possible to check process.env.CONSOLE=="LoopbackB" inside reset and to avoid doing a reset only in the cases where code was uploaded over WiFi.

  • ok! I will check it.

    now, how can I combine Telnet with an http server? It doesn't work, and I think I read about that only one server can be created.

    Is there another solution?, ¿could websockets work?

  • how can I combine Telnet with an http server?

    Yes, unforunately the ESP8266 module's AT command firmware only supports one server at a time.

    Is there another solution?, ¿could websockets work?

    Yes, totally. I posted this up a while back which serves a full Espruino IDE off of an Espruino WiFi.

    All you have to do then is modify onPageRequest to serve up the pages you want.

  • Interesting, I will definitely check that method, thanks Gordon

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

LoopbackB.setConsole() InternalError in TCP connection (Espruino WiFI)

Posted by Avatar for Steffen @Steffen

Actions