Writing modular code using "require" #521
Replies: 17 comments
-
Posted at 2014-10-17 by JumJum In options of WebIDE is a point PROJECT(SANDBOX) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-17 by @gfwilliams Yes, absolutely. Just follow the 'Project Tour' that's accessible from 'Project' in the Settings menu. It'll let you set up a directory that can have your own modules in. You can also just type Hope that helps! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-17 by DrAzzy You can do both. You can set a folder for the web ide to look in. There's an option to set the sandbox folder in the settings, and it will look in the modules subfolder there. You might have to enable this as well. Also, you can do require("http://yoursite.com/path/to/module.js") Lol, beaten... Was it really an hour between when I loaded the page and wrote the reply? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-17 by DaveNI Excellent! I should be receiving my board next week and in the meantime have been putting together some code - migrating a central heating timer from delphi to javascript - this will be in its own module. It may be of use to others (for anything that needs triggered regularly and repeats on a weekly cycle) so I will share it (with documentation) when finished. I find the following site very useful for developing/testing javascript: http://repl.it/languages/JavaScript (hopefully the code I have written will run ok on espruino - I'm doing nothing fancy!) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-17 by DrAzzy For reliable timing, you'll need a crystal (32.768khz) to solder onto the board (see http://www.espruino.com/Clocks ) or (probably better, if you're controlling your heat with it ;-) ) an external RTC module (with a battery, so even when the espruino resets, it'll keep time) - there's already a module for the DS3231, used in the most common RTC boards. Espruino runs normal javascript - but you have to be much more aware of memory usage, since it's running on a microcontroller with 48k of ram, some of that used for the interpreter and stack. The length of the code actually becomes relevant. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-17 by DaveNI Assuming I'm connected to the internet could I regularly update the inbuilt clock? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-17 by DrAzzy Yeah - you could use the Date class and rely on regular updates of the time, definitely. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-18 by @allObjects ...like that and just took advantage of the Project-Sanbox feature for my Resistive Touchscreen directly (no touch controller) (sub) project at http://forum.espruino.com/conversations/256122 Thanks @DaveNI / / @jumjum for bringing that up and to my attention as a posting subject... (...and same time shame on me not having worked through all tutorials (yet)). - :(< ... :-) #require #module #localmodule |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-20 by @gfwilliams
@DaveNI where did you order your board from? There's a new revision (1v4) of the board that's slowly working its way out to distributors, and that one has the crystal pre-installed. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-20 by DaveNI It was shipped from digitalmeans this afternoon. Hopefully it's the new version! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-21 by @gfwilliams I just checked and I think you might be out of luck... I'm sending Digitalmeans some 1v4 boards in the next few days, but they still have the 1v3 in stock. Adding the crystal isn't a big deal though - they're really cheap, or you can probably scavenge one from an old watch or clock if you have one kicking around. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-21 by DaveNI The package just arrived - really great service, ordered on sunday night! Its the 1v3 but I don't mind - if I enjoy using it I'll probably get another and ensure its a 1v4. (I may even get a DS3231 RTC module for battery backup) Now to get playing :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-10-21 by @gfwilliams Great - have fun with it! If you have any questions just ask on here, I'm sure someone (or sometimes 3 people!) will be happy to help :) The next version of the firmware (1v71) will actually remember the internal RTC's date even after a reset - so if you keep a battery plugged into the JST connector then it should 'just work'. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-01-10 by CanyonCasa If have setup the sandbox but it only allows a single projects and module setup. I have also tried pulling files from Google Drive via a link but it doesn't seem to work. Not sure if its because it's https or because it doesn't reference a .js file directly or if I'm just doing it wrong. Any possibility of supporting relative local references like NodeJS, such as the line below. I like to organize long code blocks into project specific modules that I don't necessarily want in a modules library or folder.
NodeJS also supports reading JSON files that I find handy for loading configurations and data, such as the line below.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-01-10 by DrAzzy I think that is due to the aggressive limits on chrome webapps. They are really locked down, with regard to accessing system resources. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-01-10 by Snerkle The See this post That includes files, folders, sub-folders, .json, index.js and package.json support. This hasn't made its way to the WebIDE and I don't know if it ever will. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-01-11 by @gfwilliams
Do you have an example link? If it really is a link to a text file then it should work.
Does
As @drazzy says, the WebIDE is pretty locked down, although once a sandbox is set up this should be possible (it's just not implemented yet). I think the issue is that @Snerkle's module search code only works specifically with node.js at the moment. I think there would need to be a bit of refactoring for it to work in the Web IDE - but if that was done it would be fine. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2014-10-17 by DaveNI
I understand the purpose of require("modulename") but I was wondering if this approach could be used to load my own modules and to help structure my own code.
If I place my own modules in a specific folder can the Web IDE be configured to look for them there or does it always look online for minified versions of the Espruino modules?
(Even if the Web IDE cannot access my local file system it would be good if it could access custom modules via my locally hosted web server)
Beta Was this translation helpful? Give feedback.
All reactions