You are reading a single comment by @user125533 and its replies. Click here to read the full conversation.
  • var my_device;
    var cmd_rx_characteristic;
    var cmd_tx_characteristic;
    
    function handleCmdRx(event) {
    
    }
    
    function onDisconnect(event) {
        const device = event.target;
        if (cmd_rx_characteristic) {
            cmd_rx_characteristic.stopNotifications(­)
            .then(_ => {
              log('Notifications stopped');
              cmd_rx_characteristic.removeEventListene­r('characteristicvaluechanged',
                handleCmdRx);
            })
            .catch(error => {
              log('Argh! ' + error);
            });
          }
    }
    
    function getSupportedProperties(characteristic) {
        let supportedProperties = [];
        for (const p in characteristic.properties) {
          if (characteristic.properties[p] === true) {
            supportedProperties.push(p.toUpperCase()­);
          }
        }
        return '[' + supportedProperties.join(', ') + ']';
      }
    
    
    //Find the device and rx/tx characterstics...
    
    NRF.requestDevice({ filters: [{ services: ['DE3A0001-7100-57EF-9190-F1BE84232730']­ }] })
    .then(device => {
        my_device = device;
        device.on('gattserverdisconnected', onDisconnect);
        return device.gatt.connect();
    })
    .then(server => server.getPrimaryService('DE3A0001-7100-­57EF-9190-F1BE84232730'))
    .then(service => service.getCharacteristics('803C3B1F-D30­0-1120-0530-33A62B7838C9'))
    .then(characteristics => {
        console.log(characteristics.length + ' characteristics');
        characteristics.forEach(characteristic => {
            console.log(getSupportedProperties(chara­cteristic));
            console.log(characteristic.uuid);
            if(characteristic.uuid == "803C3B1F-D300-1120-0530-33A62B7838C9") {
                if(characteristic.properties.read) {
                    console.log('Found cmd_rx characteristic');
                    cmd_rx_characteristic = characteristic;
                    characteristic.startNotifications()
                    .then(characteristic => {
                        characteristic.on('characteristicvaluech­anged',
                            handleCmdRx);
                        console.log('Notifications started.');
                    });
                } else if(characteristic.properties.writeWithou­tResponse) {
                    console.log('Found cmd_tx characteristic');
                    cmd_tx_characteristic = characteristic;
                }
            }
        });
    });
    
    

    Here's the code I'm trying to use. Line 44 should filter it down to two characteristics, but it returns 4. Line 49 tries to print the UUID of the characteristic, but always prints 0x0000.

  • Sun 2021.02.21

    @user125533, to speed our analysis and to assist us in a visualization of what that code block outputs, would you mind posting that content please.

About

Avatar for user125533 @user125533 started