• This Pixl program advertises a service, treats "onWrite" queries, and write the received character in a loop, every second:

    var eventData = "NOTHING";
    
    NRF.setServices({
      0xEDCB : {
        0xBA98 : {
          description: "MyCharact",
          writable  : true,
          onWrite : function(evt) {
            eventData = evt.data;
          }
        }
      }
    },
    { advertise: [ 'EDCB' ]});
    
    var counter = 0;
    
    function intervalHandler()
    {
      console.log("counter: " + counter + " Data=" + eventData);
      counter++;
    }
    
    setInterval(intervalHandler, 1000);
    
    g.clear();
    g.flip();
    LED.set();
    
    NRF.on('connect', function(addr) {
      console.log("Connection. addr=", addr);
    });
    
    NRF.on('disconnect', function(reason) {
      console.log("reason=" + reason);
    });
    

    Apparently, it can receive only one character. When sending byte arrays of more than one byte with nRF Connect or BLEScanner, nothing happens. However, when sending one byte only, it is received and correctly displayed.

    What do you think, please ?

  • I think you might need to specify a length:

    NRF.setServices({
      0xEDCB : {
        0xBA98 : {
          maxLen : 20, // <- this line here
          description: "MyCharact",
          writable  : true,
          onWrite : function(evt) {
            eventData = evt.data;
          }
        }
      }
    },
    { advertise: [ 'EDCB' ]});
    

    That way you can tell it that it can take more data.

  • Perfect, many thanks.

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

Pixl onWrite can receive one character only from nRF Connect or BLEScanner

Posted by Avatar for rchateauneu @rchateauneu

Actions