if need update
var fs = new(require("FlashStoreWrite"))(0x7c000);
// Save module source in EEPROM
fs.item('MyGeneralScript').wget('http://MyScript location');
E.on('init', function() {
var fs = new(require("FlashStore"))(0x7c000);
require( fs.item('MyGeneralScript').module() );
var MY = require("MyGeneralScript");
});
Full my code:
// Init ESP8266
var ESP8266 = require("ESP8266");
//ESP8266.setLog(1);
//ESP8266.printLog();
E.setClock(80);
// 18:FE:34:Cb:33:66
var fs = new(require("FlashStoreWrite"))(0x7c000);
var rfs=new(require("FlashStore"))(0x7c000);
var Config = rfs.item('config').valueOf();
console.log(Config);
var sleep = 0;
var objectToSend = {};
objectToSend.id = 'd03';
// Init WiFi Networks
var wifi = require("Wifi");
wifi.setHostname(objectToSend.id);
wifi.connect("XXX", {password:"XXX"}, function(err){
setTimeout(function(){
objectToSend.internalIp = wifi.getIP();
//console.log("connected? err=", err, "info=", wifi.getIP());
initDevice();
},2000);
});
wifi.stopAP();
wifi.save();
function initDevice(){
var http = require("http");
http.get("MYLINK", function(res) {
res.on('data', function(data) {
var tt = JSON.parse(data);
sleep = tt.sleep; // Set sleep time
if(tt.ver>Config.ver){
console.log("GETTING NEW FIRMWARE");
fs.item('config', tt);
// Save new general scipt
fs.item('Generalscript').wget('LINK TO MY SCRIPT');
}
if(tt.debug==1){
console.log("DEBUG");
digitalWrite(D2,0); // Enable LED
startDevice();
}else{
digitalWrite(D2,0); // Disable LED
startDevice();
}
});
});
}
function startDevice(){
// Retrieve module source, add to module cache and then use..
require( fs.item('Generalscript').module() );
var GeneralScript = require("Generalscript").Generalscript;
var gs = new GeneralScript();
gs.getVer();
}
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.
I found answer.. http://forum.espruino.com/conversations/283045/
I just use
Full my code: