Save on Send (to Flash) and the SX127x module

Posted on
  • Why does the following code work just fine on the Pixl.js when code is uploaded to RAM, but when I use "Save on Send (to Flash)", or save() it wrapped in an onInit() function, does it just print "Sending.." and then stop?

    SPI1.setup({ sck:D3, miso:D4, mosi:D5 });
    var sx = require("SX127x").connect({spi: SPI1, cs: D6, rst : D7 });
    
    var config = {
      forcePaBoost: true,
    };
    clearInterval();
    // Until DIO0 line irqs are implemented we need this:
    setInterval(function() { sx.onIRQ(); }, 100);
    
    sx.setTxConfig(config);
    
    console.log('Sending..');
    sx.send("Hello", function() {
      console.log("TX done");
    });
    
  • I believe it's to do with execution speed. It turns out require("SX127x").connect doesn't execute immediately, and so you should only use it maybe 10ms after calling it.

    When you upload you get that delay automatically because of the upload, but executing from flash it's too quick.

    Just doing:

    var sx = require("SX127x").connect({spi: SPI1, cs: D6, rst : D7 });
    //....
    setTimeout(function() {
     sx.setTxConfig(config);
    console.log('Sending..');
    sx.send("Hello", function() {
      console.log("TX done");
    });
    }, 10);
    

    should do it - ideally there should be a callback function when initialisation is done

  • Hmm, that makes sense but it didn't resolve it either. I tried increasing the timeout from 10 to 100ms, and putting the onIRQ setInterval inside the timeout function, but no luck so far.

  • @Gordon I just spent three hours rewriting the SX127x module to use Promises, got it working, and when I wanted to create a PR I discovered that you already fixed it by adding the callback code 😂️

    Callback code works fine 👍️

    How does it usually take before the changes on master are available for use?

  • ...pub to .../modules has to happen to get modules updated.

    Furthermore: the connect sets stuff in the SX127X... (writes to registers of XS127X) which has to rerun on every power cycle... This is in addition to the fact that that setting of stuff is done in an asynchronous matter... and that is the actual - compound - issue.

    @gendor, for the SX127X init reason, it is a good practice to always have an onInit() construct in the code to ensure consistent behavior no matter what upload approach is used and power cycle.

    @Gordon, what's the reason to not do simple callback to follow the prevailing pattern of .connect() (with undefined/err arg)? I'm aware of the callback hell... but at this point it is not hell yet and but I'm not sure if it is worth to complicated it that much with a Promise, even though it is more sophisticated.

  • @allObjects Sorry if I wasn't clear. Gordon implemented a simple callback fix two weeks ago (see https://github.com/espruino/EspruinoDocs­/commit/8ca56d2929298152f683e4309bf876e7­35034216#diff-71fd1b58c3b419a0205973a478­fd66da5ff6b2c138a5e4a35cfbbb2e129c06b0 ) after our initial discussion earlier in this thread, but I only noticed it after I created my own fix using Promises when I was looking to contribute it back to the code base. I was just wondering when his fix would be published to .../modules.

  • Sorry about that - updates to the website are manual as I like to check what's changed each time. Usually it should happen in a few days, but last week was a bit crazy and I didn't get around to it.

    I'll get it updated now

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Save on Send (to Flash) and the SX127x module

Posted by Avatar for gendor @gendor

Actions