Telnet device

Posted on
  • I'm a bit puzzled abouit the Telnet serial device. A static object is defined in­b/master/src/jswrap_serial.c#L152-L160 but on the esp8266 I don't actually get that device. Telnet just doesn't exist. I can fortunately get to the device as require("Telnet").Telnet. Why is that?

    Update: mhh, doesn't look like require("Telnet") does anything useful :-(

  • Maybe, for whatever reason USE_TELNET doesn't get defined at the point that build_jswrapper is called in the Makefile. You could try removing "#if" : "defined(USE_TELNET)" and seeing if it gets built in?

    Something needs to be in there though, or every other platform will have a 'Telnet' symbol :)

  • Telnet exists in generated jswrapper.js, search in the file returns 24 times
    But there is no entry for Telnet like this one for Serial1

    {287, JSWAT_JSVAR | JSWAT_EXECUTE_IMMEDIATELY, (void (*)(void))gen_jswrap_Serial1},

    require("Telnet") returns a variable which at least can be used for switching mode
    Tested on a just compiled version for ESP8266

    t = require("Telnet")
    =function () { [native code] }
  • After changing wrapper part, there is an object Telnet1 now, similiar to Serial1
    Would like to have an explanation, whats happening behind the scenes, but I don't
    At the end, there is an Telnet1, but I don't know what it should be used for
    Reached end of my knowledge :-(

      "type" : "object",
      "name" : "Telnet1",
      "instanceof" : "Telnet",
      "#if" : "defined(USE_TELNET)"
    A telnet serial device that maps to the built-in telnet console server (devices that have
    built-in wifi only).
  • Hmm... Maybe there is a module or something else called 'Telnet' and that's causing some confusion for build_jswrapper?

  • There is a library called Telnet, see jswrap_telnet.c
    Can a library be used like a serial port ?
    As far as I understand @tve (correct me if I'm wrong), he would like to have Telnet instance already created, which can be used with all methods.

  • Good idea about the Telnet1. So it looks like the problem is that the object has the same name as the class. Maybe the best it to rename the class. "TelNet"? "TNet"? "TelnetConsole"?

  • If you just removed the:

      "type"  : "library",
      "class" : "Telnet"

    that might fix it? I guess everything would be on the global object Telnet instead, but that's not such a big deal as the object is going to exist anyway? Or you could use a lowercase telnet library.

    If that fixes it then it could possibly be fixed in build_jswrapper - however there's then some confusion about how to add stuff to a library. There's a branch on GitHub where I was trying to sort this mess out a bit (using more sensible JSON namings), but I haven't got around to merging/test enough yet.

  • I renamed the class to TelnetConsole, but that didn't do the trick. I also noticed­b/master/scripts/build_tern_json.js#L81-­L82 which hopefully just affects docs generation?

    Edit: the renaming does work. Maybe "TelnetServer" is more appropriate, though.

  • I'm still stumped. What I'm trying to do is call Telnet.setConsole(true) in order to prevent the console from jumping back to Serial1 as soon as I disconnect. I have a Nextion display on Serial1 so I have to prevent anything from being output there that is console-related.

    I'm actually not sure that setting the console to Telnet works. I think it'll block once the buffer is full. If I do Serial2.setConsole(true) it's OK in that characters just go out that device and there's nothing listening, but the problem is that then it's unrecoverable via telnet. Maybe something I could do is when disconnecting telnet to only reset the console to the "old_console" if console==EV_TELNET. This way I can do Serial2.setConsole(false), have stuff go out there (which is the debug TTY anyway) but not prevent reconnecting via Telnet.

  • Mhh, so it looks like something is not initialized properly at cold-boot on the esp8266. After a HW reset Serial2.print("foo") says Uncaught Error: Function "setConsole" not found! but if I do reset() then it works just fine. Same for Telnet after renaming the class to TelnetServer.

  • I'm not seeing what is missing is the esp8266 init sequence to ensure that SerialX etc. are created at boot time. Gordon, can you shed some light on where these objects are created at boot time?

  • The objects should be created 'on-demand' via jswrapper.c - after they're created, the function pointer inside them points to the constructor function for that object - and that is used by jswrapper to figure out what' inside them.

    All I can think is that the function pointer has changed somehow.

    I guess, most likely, you've saved some code and then updated the firmware without clearing out the area reserved for saved code? That'll have moved the function addresses around and will have broken the pointers.

    That's been a common thing all along... one of the reasons I've been pushing for all-in-one hex files that overwrite saved code.

    I guess you could change the hex file to write another blank.hex over the area reserved for saved code?

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

Telnet device

Posted by Avatar for tve @tve