Multiple files and importing libraries #6271
Replies: 1 comment
-
Posted at 2018-08-13 by @gfwilliams Espruino works a slightly different way by default - it's a bit like 'hibernating'. There's a bit more info here: http://www.espruino.com/Saving You don't have boot/main/etc - you have one file that you upload from the IDE, however that file can The IDE only supports editing one file, so when you're getting to the point of having multiple modules you may want to switch to using the command-line tools, and then just use your favorite editor. Posted at 2018-08-13 by cuneyt OK thanks. I am actually using npm library from the console. Pretty powerful. So, if there's only one file I think the best option is to bundle the files and minify into a single file. Actually it's a good idea to have a single file. You can do many optimisations using Grunt and that kind of bundlers. Thanks I just wanted to make sure that it is the only way. Now I'm more clear on what I'm going to do. Cheers. Posted at 2018-08-13 by Wilberforce I you are bringing the file via the ide with Posted at 2018-08-14 by @allObjects No need to bundle, since at runtime 'nothing' happens, and you gain nothing but the extra step of bundling... or worse, manage the compound export yourself: On upload, the IDE goes through the files - recursively - looking (w/ reg expression) for My approach is now to develop modules by modules inline (similar to what you see in these conversations A and B), and when a module is stable enough, minify it w/ Google's minifier / closure compiler and put it minified into my modules in the local sandbox. Minifying is not just speed, but more so it is space and to provide more variables, since all (most of the time) happens in RAM (yes you can upload into FLASH directly and leaves you with even more RAM for variables...). Btw, if you miss multi-document UI in Espruino IDE, edit just your 'main' in Espruino IDE and your modules in your favorite multi-file Editor / other IDE with sourcing directly from your sandbox modules folder. Everytime you upload, your modules get also uploaded - with prior minification - by the very Espruino IDE - and you test your most recent versions of all your sw components. Posted at 2018-08-15 by cuneyt Thanks for the answers. So, if bundling not needed that means I need to upload the file which is the starting point of my app. Like I don't use the IDE. I use normal text editor and then use command line like below. Works good.
One thing I don't understand is what happens when I upload another file? It does not seem to overwrite the existing program. For example; I first uploaded
Then I wrote another program which is client.js and does completely something different:
What I expect; when I upload the second program, the first one will be overwritten therefore LED would turn off. But it doesn't. It seems it ignores the second program. I need to re-flash the firmware if I want to change the program inside. Posted at 2018-08-15 by @allObjects The term single page (web) app is a term used in context of a browser and means that after initial load of the dhtml, xhr request are made to pull data and html fragments to update the page (in the browser) without reloading it. The upload function of IDE does make sure that all required modules are uploaded first into the cache so when it comes to execution, they can be pulled from there. If you use the command, I'm not sure what is going on... but I'm sure that you can replace previously uploaded code with new / other code. From context I read that command line tool upload does the same like the IDE: upload requested modules first. Command line option has more options... To your specific case of code: I may be that your http communication you start conflicts with the upload process. Furthermore, it is non-standard ESP8266 board, so it behaves anyway different than the regular Espruino boards. Give this a shot: pack your code in a function, for example, If you use the save option, you have to have an Posted at 2018-08-18 by aliustaoglu Hi it's cuneyt. I just lost the access to the email I was registered with. So registered another account. Seems I'll be regular here. I liked this Espruino more than any other firmware. Not sure why it's called Espruino though. It should be called NodeMCU as it actually is the true Nodejs for MCU. Lua firmware should be called something else. Anyway, I finally managed to do what I was trying to do. Yes Please check my repo below to see how I use terminal. I use espruino npm package. You have all control over the code. It's awesome. Did not really use WebIDE but I'm sure it's using this library in the background in a similar way. It's good for starting but I wanna have more control over my library. And automate things. https://github.com/aliustaoglu/espruino-http-server Here all files in the /src library bundled into a single file and minified. That's it. I just hate to put everything into a single file.
Put everything into index.js and upload index.js to ESP8266. And also I can use package.json to simplify frequently used commands like erasing or flashing the firmware, uploading the code etc. led.js
httpServer.js
Then when I connect to here is how I use my package.json
Posted at 2019-08-15 by @allObjects @aliustaoglu - before @cuneyt, sorry not having responded to you then... I see the benefit of this approach, because you can just just any IDE to develop your code and then with a target specific script upload all code... and even automate it. In your scripts you include also the flashing of the firmware. You do need that only when a new version becomes available. A board once flashed with the firmware needs only the javascript application part to be uploaded. I see not all of the package.json but I assume you consider that when using it. Furthermore, you can universalize this package.json/scripts by de-version the firmware and have a link to the most recent one. For the application part you already do this by convention to always use index.js. Version and board specifics have of course be taken care of. Posted at 2019-08-17 by aliustaoglu @allObjects I've also created an npm package. If you install this npm module globally you can create this boilerplate easily and then change it as you desire and have this structure. It supports both ESP8266 and ESP32. Module is here: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2018-08-13 by cuneyt
I have been working with Arduino and MicroPython for a while and just switched to Espruino and nodejs on ESP8266. I am able to upload a file and connect to wifi and do lots of stuff. But there's one thing I cannot figure out:
MicroPython had a file structure like below:
as the name suggests boot.py is executed on boot, and main.py is the main file where you want to create your main loop. I can create another library and import it from main.py. Arduino also has similar structure. How can I do this in Espruino? Can I upload multiple files? If so how?
Beta Was this translation helpful? Give feedback.
All reactions