• Using nRF Connect to read data from my Bluetooth sensor, I write 'g' to the RX characteristic and then read 1099 packets of data via notifications (23 Byte MTU size, including 3 bytes header). See screenshot:

    1. packet: 04-e1-4B-...: 2 bytes ID and then 4 bytes each for number of packets (55) and number of data bytes (1099)
    2. packet: 41-A5-43-...: Sensor ID
    3. packet: 00-00-D6-...: Sensor configuration
    4. following packets

    Using the standard MDBT42Q 2V04 firmware and the application below, however, the packets are not correct. I get the first packet, but the 2nd packet seems to be missing, and the 3 and 4th packet appear to contain identical data (which they don't).

    It seems like the event data passed into the characteristicsvaluechanged() callback is not updated properly on each callback, or is my application code incorrect?

    Thanks,
    -- Terrence

    var gatt;
    var service;
    var cntdata;
    var cntpackets;
    
    function getData() {
      console.log("getData()");
      console.log("searching for devices ...");
    
      NRF.requestDevice({ timeout: 20000, filters: [{ name: 'device name'}], active:true })
      .then(function(device){
          console.log("found - connecting ...");
          return device.gatt.connect();
      })
      .then(function(gattp){
          console.log("get primary service");
          gatt = gattp;
          return gatt.getPrimaryService("6e400001-b5a3-f3­93-e0a9-e50e24dcca9e");
      })
      .then(function(servicep){
          console.log("get TX characteristic");
          service = servicep;
          return service.getCharacteristic("6e400003-b5a3­-f393-e0a9-e50e24dcca9e");
      })
      .then(function(characteristicp){
          cntdata = 0;
          cntpackets = -1;
          console.log("start notfifications");
          characteristicp.on('characteristicvaluec­hanged', function(event) {
            var dataview = event.target.value;
            cntpackets++;
            if (cntpackets == 0) {
              console.log("total data: " + dataview.getInt32(2, true) + ", total packets: " + dataview.getInt32(6, true));
            } else {
              cntdata += dataview.byteLength;
            }
            console.log("packet: " + cntpackets + ", data: " + cntdata);
            if (cntpackets < 4) {
              console.log(dataview);
            }
          });
          return characteristicp.startNotifications();
      })
      .then(function(){
          console.log("get RX characteristic");
          return service.getCharacteristic("6e400002-b5a3­-f393-e0a9-e50e24dcca9e");
      })
      .then(function(characteristicp){
          console.log("send 'g' command");
          characteristicp.writeValue('g');
      })
      .then(function() {
        return new Promise(function(resolve) {
          setTimeout(resolve, 10000);
        });
      })
      .then(function() {
        console.log("end delay - disconnecting ...");
        gatt.disconnect();
        console.log("getData(): done");
      })
      .catch(function(err) {
        console.log("ERROR", err);
      });
    }
    
    getData();
    
    
About

Avatar for AkosLukacs @AkosLukacs started