-
• #2
Would you mind sharing your code? It would make it easier to guess what might be wonky 🙂
-
• #3
ill post the relevant sections (i guess). This is basically toplevel, everything else is just functions.
Bangle.loadWidgets(); Bangle.drawWidgets(); Bangle.setOptions({ lockTimeout: 0, backlightTimeout: 10000, btnLoadTimeout: 0, hrmSportMode: -1 }); NRF.setTxPower(8); var bootTimer = 0; setInterval(function() { if (BTN.read()) bootTimer++; else bootTimer=0; if (bootTimer<10) E.kickWatchdog(); }, 2000); Graphics.prototype.setFontAnton = function(scale) { // Actual height 69 (68 - 0) . . . . setDrawClock(); onInit(); // set up our new services initGraphics();
function onInit() { NRF.on('connect', function () { connected = true; uiLog("connected"); }); NRF.on('disconnect', function () { connected = false; uiLog("disconnected"); NRF.eraseBonds(onBondErased); }); NRF.on('bond', function(status) { uiLog("bond: " + status); if(status == "success"){ connected = true; } else { connected = false; } }); NRF.on('advertising', function(isAdvertising) { uiLog("advertising: " + isAdvertising); }); NRF.setServices({...}); uiLog("Waiting..","Bluetooth Connection"); setInterval(stepCount, 30000); setInterval(batteryPercentage, 5000); Bangle.on('accel', onAccel); Bangle.on('HRM-raw', onHRM); Bangle.setHRMPower(1, "app"); }
-
• #4
The app works fine when i launch it from the WebIDE,
How do you upload from web IDE, to ram or storage?
however, when installing it from the apploader and then "reloading", i suddenly have code duplicated in ram, therefore functions being called twice.
So e.g.
in ram it is like this:
Bangle.on("accel", onAccel);
Bangle.on("accel", onAccel);Where/how do you look and see this? In the web IDE left console field? Does it happen immediately on first launch or after an extra reload? Can the code be duplicated more than twice so you have e.g. three instances of the
accel
listener? -
• #5
I guess you have a fork of the repo set up, could you link to that? 🙂
edit: found it https://github.com/sfnk/BangleApps :)
-
• #6
I guess this is the app.js file in question?: https://github.com/sfnk/BangleApps/blob/master/apps/00emerno/app.js
What happens if you uncomment the
setUI
code but don't add theremove
handler? -
• #7
- Uploading to ram
- 'Download from RAM' in the webide, there you can see the duplication.
- It happens when i do the install default apps for example. Then after completion it requires a reload. At that point the Problem exists.
- I did not see 3x or more yet. But i will test this in 1-2 hours.
- Will check the setui possibility and report back.
Thanks for the Quick response so far!
- Uploading to ram
-
• #8
Can you explain a bit more what you do? So you 'install default apps', then install your app as the only clock app, and then you long-press the button on the watch to reload, connect with the Web IDE and when you view what's in RAM you see your code in there twice?
Or are there other steps involved?
One thing is you could have saved to flash once accidentally with the IDE which would overwrite the default code that runs with your app - but doing an 'install default apps' or even reinstalling the bootloader should fix that
-
• #9
For sure, sorry for any confusion.
- I install "default apps" -> this already installs my app as clock app, then you get prompted to "reload" or set it in the apploader to automatically reload. No further install from the WebIDE.
- Connect with the WebIDE - "Download from RAM" shows this duplicated code.
- Prints in the WebIDEs console are also duplicated, so is behaviour of the app, e.g. buzzing executed twice (multiple times?)
I will try what @Ganblejs suggested now and report back.
edit: this showed no different behaviour.Edit: the duplication is only present for
setInterval() setTimeout() Bangle.on() NRF.on()
2x my code, 1x code from the widget?
var bleServiceOptions = { "uart": true }; NRF.on("connect", function () {WIDGETS["bluetooth"].draw();}); NRF.on("connect", function () {connected=true;uiLog("connected");}); NRF.on("connect", function () {connected=true;uiLog("connected");}); NRF.on("disconnect", function () {WIDGETS["bluetooth"].draw();}); NRF.on("disconnect", function () {connected=false;uiLog("disconnected");NRF.eraseBonds(onBondErased);}); NRF.on("disconnect", function () {connected=false;uiLog("disconnected");NRF.eraseBonds(onBondErased);}); NRF.on("bond", function (status) {uiLog("bond: "+status);if(status=="success"){connected=true;}else{connected=false;}}); NRF.on("bond", function (status) {uiLog("bond: "+status);if(status=="success"){connected=true;}else{connected=false;}}); NRF.on("advertising", function (isAdvertising) {uiLog("advertising: "+isAdvertising);}); NRF.on("advertising", function (isAdvertising) {uiLog("advertising: "+isAdvertising);});
- I install "default apps" -> this already installs my app as clock app, then you get prompted to "reload" or set it in the apploader to automatically reload. No further install from the WebIDE.
-
• #10
Ahh, ok, as you've changed a bunch of stuff in your app loader, is it at all possible that you've got the code defined again somewhere else?
So Widgets, but also boot code (which runs for every app)
You could try searching all js files with:
require("Storage").list().filter(f=>f.endsWith(".js")).forEach( f => { if (require("Storage").read(f).includes('"connect"')) print(f+" contains connect"); })
that searches for the text
"connect"
but you could extend it to search for some other more useful search phrase -
• #11
no, cannot imagine it being literally duplicated. Also not finding any evidence for it.
this is the generated print:
bootupdate.js contains connect 00emerno.app.js contains connect widbt.wid.js contains connect
-
• #12
update, i found a way around it, probably exposing a bug?
i did the follwing to avoid duplicate appstart basically.
E.on('init', startApp); startApp();
and
function startApp(){ if(appStarted){ return; }
The "bug" that listeners are added twice is still there, but this avoids it.
-
• #13
Ahh - you're calling the function once, and then asking Espruino to call the function again with
E.on('init',
. I don't think that's really a bug.As you're executing the file from flash, you might as well just remove the
E.on('init', startApp);
line, since when your app starts is run it's going to callstartApp();
anyway.E.on('init',
and theonInit
function are really there for other Espruino devices where you can develop the app in RAM and then typesave()
to effectively 'hibernate' your app to flash memory. Then when your app 'wakes' theE.on('init'
gets called - but that's not something we do on Bangle.js. There's a bit of info on that at https://www.espruino.com/Saving
Hey guys,
long time lurker, first time poster here.
So i'm having trouble understanding / fixing this.
I created my own app.js, got everything to work that this is my default app.
The app works fine when i launch it from the WebIDE, however, when installing it from the apploader and then "reloading", i suddenly have code duplicated in ram, therefore functions being called twice.
So e.g.
in ram it is like this:
Bangle.on("accel", onAccel);
Bangle.on("accel", onAccel);
when launching from the WebIDE, this duplication is not present.
What am i missing? How do i get a "clean" launch after installing?
Thanks in advance.
edit: when installing from the webide after the installation from the apploader the console prints:
Uncaught Storage Updated!
might be related?