It's because the Web IDE was originally made as a website where each file executed in the same scope, and adds itself to the global 'Espruino' variable - I can't just 'require()' everything as-is. Ideally I'd rewrite every file to handle both loading styles, but I don't have the time to do that while also checking it still works fine as a Chrome App, NWjs app, and on the Espruino website.
As-is it does make debugging extremely frustrating, since the filenames aren't correct :(
Looks to me like connection.write is in serial_nodeserial.js. connection shouldn't be global at all - it looks like you're either:
a) trying to write before you're actually connected
b) disconnecting before the code has actually been written
b) somehow managing to have got two separate instances of the EspruinoTools loaded - so one is connected while the other isn't.
There should really be a lot more being written to the console - it might be worth trying to figure out why that's not happening as the extra log messages would probably let you know what's going on.
I still don't understand why you can't just use the existing espruino-cli code though - or at the very least start from that code which does exactly what you want and then strip out the bits you don't want.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
It's because the Web IDE was originally made as a website where each file executed in the same scope, and adds itself to the global 'Espruino' variable - I can't just 'require()' everything as-is. Ideally I'd rewrite every file to handle both loading styles, but I don't have the time to do that while also checking it still works fine as a Chrome App, NWjs app, and on the Espruino website.
As-is it does make debugging extremely frustrating, since the filenames aren't correct :(
Looks to me like
connection.write
is in serial_nodeserial.js.connection
shouldn't be global at all - it looks like you're either:a) trying to write before you're actually connected
b) disconnecting before the code has actually been written
b) somehow managing to have got two separate instances of the EspruinoTools loaded - so one is connected while the other isn't.
There should really be a lot more being written to the console - it might be worth trying to figure out why that's not happening as the extra log messages would probably let you know what's going on.
I still don't understand why you can't just use the existing espruino-cli code though - or at the very least start from that code which does exactly what you want and then strip out the bits you don't want.