• Hi,

    there is NRF.setServices and I have no trouble setting up a custom service and characteristics when executing code in the IDE, and use it thereafter. Then I tried to put this in a .boot.js file and an issue pops up: the writable characteristic calls onWrite twice each time a message arrives.

    So I thought its because setServices is called multiple times (e.g. after long-press BTN3), but even the following doesn't solve it:

    setTimeout(() => {
      var cc = require('concom');
    
      cc.t = (0|cc.t) + 1;
    
      function has_service(sid, cid) {
        var svc = {};
        svc[cid] = {};
        var svcs = {};
        svcs[sid] = svc;
        try {
          NRF.updateServices(svcs);
        } catch (e) {
          return false;
        }
        return true;
      }
    
      if (has_service(0xf011, 0xf012)) return;
    
      NRF.setServices({
        0xf011: {
          0xf012: {
            maxLen: 53,
            writable: true,
            onWrite: (e) => cc.read(new Uint8Array(e.data))
          },
          0xf013: {
            maxLen: 53,
            notify: true
          }
        }
      });
    }, 3 * 1000);
    

    When I run its parts individually, everything works (e.g. first has_service returns false, then setServices, then has_service returns true) and I get one onWrite per message. When I do a hard reset with this in the boot file and write to the characteristic, onWrite gets called twice.

    It would be great if anyone could shed some light on this :)

    edit: .t is 1

About

Avatar for !evil @!evil started