The plan is to write a module and include it in custom build with JSMODULESOURCES to have all nice tools in place without wasting time on load.
Starting with a time helper as sample, I was fiddling around and have no clue how to write a working module. Any suggestions how to make this work?
// module code jstools.js
var jstools = function (){};
jstools.prototype.setTimeByUrl = function(url,tz,callback) {
require('http').get(url, function(res){
var date = new Date(res.headers.Date);
if (date > 0 ) {
setTime(date/1000);
E.setTimeZone(tz);
error = null;
} else {
error = 'no date';
}
if (callback)
callback(error);
});
};
exports = jstools;
// test code
var jstools = require('jstools');
setTimeout(function(){
jstools.setTimeByUrl('http://www.espruino.com',1,function(e){console.log(e);});
},1000);
//output
Uncaught Error: Function "setTimeByUrl" not found!
at line 1 col 9
jstools.setTimeByUrl('http://www.espruino.com',1,function(e)...
^
in function called from system
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.
The plan is to write a module and include it in custom build with JSMODULESOURCES to have all nice tools in place without wasting time on load.
Starting with a time helper as sample, I was fiddling around and have no clue how to write a working module. Any suggestions how to make this work?