• When connecting to Espruino programmatically I send for example
    This works well, but besides looking a little ugly it is a big waste when connected over BLE.

    If the were a key, say \x1f, that makes jsiHandleChar

    1. delete the current line like Ctrl-U (\x15)
    2. turn echo off permanently until re-enabled by echo(1)

    the command sent became '\x1fprint(E.getTemperature())\n'.

    This saves 9 bytes (almost halve of one BLE packet's payload, and probably a little overhead for parsing and interpreting the echo(0) call.
    Is this something to consider as an enhancement?

    Regards, Steffen

  • Am I right in thinking that you only do it once when you initially connect?

    Do you have the ability to write code for the Espruino device itself? It'd be pretty easy to add code to do the echo(0) and clear line automatically when Bluetooth was connected, meaning you don't need to send anything.

    I'm a bit worried about adding stuff like that because if anyone ever enters the key by accident (eg copy pasting something with some dodgy char codes in) at any point it basically makes the board seem like it's crashed until it is rebooted :(

  • Or define on the board:

    funtion p(){print(E.getTemperature()};

    Then you can do:
    \x15\x10\p()\n and save 20 bytes!

  • Thanks for your replies.
    @Gordon: Yes, it is mostly when starting a small "session" after a while. I agree with your concerns about accidentially pasted code, that's why I didn't just suggest it as enhancement.
    And for the exactly same reason the example has \x1f instead of \x02 (Ctrl-b).
    @Wilberforce: E.getTemperature was just an example. I don't always know which code is needed. If it's more than 1 line of code the only safe way is to send echo(0) first.

    Although I'm able to make code changes I don't want to run propriatary code builds. A year from now I might have lost interest in making own Espruino builds (not in Espruino) - then I'll loose either the official Espruino improvements or my propriatary enhancements.
    So I'll continue wasting 20 bytes with each session :)

  • Did you know you can prefix a line with "\x10" to turn echo off just for that line? Especially if you're doing a small session that'll save you sending echo(0)\n each time, at the expense of one extra character per request.

  • Yes, I've made good experience prefixing all commands with \x15\x10.
    Once I've disovered these magic characters a lot of trouble was gone! There are still constellations where an additional echo(0) seems to be required but I cannot tell which ones specifically.
    Btw, I understand that for \x10print(1);print(2)\n echo is off for both print statements, while for \x10print(1)\nprint(2)\n the second print statement is echoed (if echo was on). I believe that my need for echo(0) comes from more complex code snippets that are separated by \n.

  • I believe that my need for echo(0) comes from more complex code snippets that are separated by \n.

    Yes, that'll be the issue. \x10 is just for a single line. You should be able to send all your code (even big bits of code) without newlines, but you could always just enclose multiple lines in angle brackets: "\x10{print(1)\nprint(2)\n}".

  • Wow, a basic JS technique I didn't even think of. This makes the introduction of a new echo-off-char really unnecessary. Thank you so much Gordon for engaging in this discussion!

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

Enhance console by a new key to clear line and echo off in one go

Posted by Avatar for Steffen @Steffen