You are reading a single comment by @tev and its replies. Click here to read the full conversation.
  • Thanks for the support. That's pretty much what I figured was going on. I was just hoping there was a more reliable way than using a fixed delay before running the second command, as that seems a bit like a fragile approach since it relies on trying to guess how long app loading time will take.

    But technically, I don't really need to load my whole app and its UI. What I'd ideally like is to be able to import a few functions from the app and execute those, perhaps using require() or something. I think I could put some shared functions pertaining to data handling into an appname.lib.js file and export them that way? It seems that I've seen some apps such as Sleeplog do that. It seems that would work more cleanly.

    As far as returning vs. printing, I in fact tried both approaches in printHTMLStampLog, because I had no idea what I was doing. It just didn't feel like the docs I read were all that clear exactly how it worked. I understand the Storage.* stuff, but I could not find references to Puck.eval or Puck.write in the search box on the Espruino docs, and I couldn't find an explanation on when to use '\n' and '\x10' and things like that or what the Bluetooth.* functions were. I had seen those in various source code but couldn't find the explanations.

    My code involved in this is currently very simple. I could put most of it in interface.html, but it's just that testing that currently involves pushing it up to Github Pages and waiting up to ten minutes just to test the code, whereas I can test code on the Bangle device immediately. I'd have to look into getting a local web server going to work around that, which is another time and effort investment I will have to consider.

    Update:
    I've changed my interface.html code to this:

          function onInit() {
            Puck.eval("load('timestamplog.app.js')",­ output => {
              setTimeout(
                Puck.eval("stampLog", output2 => {
                  document.getElementById("content").inner­HTML = output2;
                }),
                2000);
            });
          }
    

    as a test (stampLog is an object containing simple datatypes), but I still don't get any output. The browser console reports:

    BLE> Unable to decode "\r\u001b[Jstamplog: skipping save to storage because no changes made\r", got SyntaxError: Unexpected token '', "
    stamplo"... is not valid JSON
    

    “skipping save to storage” is a normal debug message that my app logs to the console, so it's as if it's trying to parse the wrong part of the console (the output of stampLog is way further down than that).

About

Avatar for tev @tev started