You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • @tve just asked about how it might be possible to build code into Espruino such that after the board was reset(), it was still there - and it seems it might be worth thinking about here.

    The initial reasons I can think of are:

    • The ability to boot right up, connect to a network, and then be able to connect to the Espruino and program it (@tve's suggestion)
    • Same thing, but with some random radio connection of your choice (NRF24, RFM69, etc)
    • An 'Espruino PC' - Since Espruino can do VGA output, and the console can be redirected, we could actually have a proper all-in-one Espruino-based PC.
    • Maybe you have some teaching tool and you want some things pre-initialised (like an LCD that says 'hello')

    The obvious one is to build C code into the firmware - but then you need separate firmware for each type of device (and in the WiFi case you still have to store WiFi credentials somewhere), and also C knowledge.

    Another option is to allow user-defined JS code to be written into flash memory, in the same area that the existing saved code is stored in. Then when initialising, Espruino would load that code up before anything else - even if it was right after a reset() call.

    Because of the way Espruino works, any functions that got defined would still take up RAM, and it'd eat into the amount of code that you could save to flash. I think in a lot of cases that wouldn't be too bad though?

    It seems like a neat solution anyway, and it's not too evil to implement. You'd just have a function like E.setBootupCode("...."), and if required you could still build that into the binary.

    Only bad point as far as I can see is that in the WiFi case, reset() would reset all the open socket connections (unless we had a 'special' connection type that could survive?). It probably makes sense to build in Telnet console functionality (it'd be easy in the firmware, and might help with debugging if there was buggy JS code), and to expose it via some function call. That special connection type could then persist through resets, and the code that you upload would be simply:

    E.setBootupCode(
      "require('WiFi').connect(wifi, credentials, function(){"
     +"E.enableTelnetServer('mypassword')"
    +"});");
    

    Any thoughts about this? Does there seem to be a better way of handling it?

About

Avatar for Gordon @Gordon started