Avatar for user125533

user125533

Member since Feb 2021 • Last active Feb 2021
  • 1 conversations
  • 7 comments

Most recent activity

  • in Puck.js, Pixl.js and MDBT42
    Avatar for user125533

    Sorry, yes, I was joking. Thank you for trying to be helpful, though!

  • in Puck.js, Pixl.js and MDBT42
    Avatar for user125533

    Had to tweak it a bit to get it to work correctly(Needed to save the service, and make the next .then use the saved service instead of the argument), but requesting with getCharacteristic() and throwing it away /does/ get the UUID field to populate in getCharacteristics(). Fun stuff. Thanks for the help!

    var device_service;
    
    .then(server => server.getPrimaryService('DE3A0001-7100-57EF-9190-F1BE84232730'))
    .then(s => {
      device_service=s;
      return device_service.getCharacteristic('803C3B1F-D300-1120-0530-33A62B7838C9');
    })
    .then(_ => device_service.getCharacteristics('803C3B1F-D300-1120-0530-33A62B7838C9'))
    

    Now on to figuring out how to actually write commands to it, haha. :)

  • in Puck.js, Pixl.js and MDBT42
    Avatar for user125533

    For further reference, here is the results of the equivalent code under Chrome's Web Bluetooth.

    2 characteristics
    [READ, NOTIFY]
    803c3b1f-d300-1120-0530-33a62b7838c9
    Found cmd_rx characteristic
    Notifications started.
    [WRITEWITHOUTRESPONSE]
    803c3b1f-d300-1120-0530-33a62b7838c9
    Found cmd_tx characteristic
    
    
  • in Puck.js, Pixl.js and MDBT42
    Avatar for user125533
    >
     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v08 (c) 2019 G.Williams
    >
    4 characteristics
    [READ, NOTIFY]
    0x0000[vendor]
    [WRITEWITHOUTRESPONSE]
    0x0000[vendor]
    [READ, NOTIFY]
    0x0000[vendor]
    [WRITEWITHOUTRESPONSE]
    0x0000[vendor]
    > 
    
  • in Puck.js, Pixl.js and MDBT42
    Avatar for user125533
    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.removeEventListener('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-D300-1120-0530-33A62B7838C9'))
    .then(characteristics => {
        console.log(characteristics.length + ' characteristics');
        characteristics.forEach(characteristic => {
            console.log(getSupportedProperties(characteristic));
            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('characteristicvaluechanged',
                            handleCmdRx);
                        console.log('Notifications started.');
                    });
                } else if(characteristic.properties.writeWithoutResponse) {
                    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.

  • in Puck.js, Pixl.js and MDBT42
    Avatar for user125533

    This is a specific case which does not seem to be covered by other threads. I have two characteristics with the same UUID, and I need to get handles for both of them. getCharacteristic does not allow me to do this. getCharacteristics does not filter by UUID, so I get unrelated characteristics from that service as well. The characteristic does not have a working UUID property, so I cannot filter them myself.

  • in Puck.js, Pixl.js and MDBT42
    Avatar for user125533

    So I'm trying to interface a puck.js with an existing BLE product, and it has a service with two characteristics with the same UUID, but different properties and uses. One is read/notify and is output from the device, and the other is "write without response", and is input to the device. There are also another two characteristics in this service that I'm not interested in, but also have a read/notify and "write without response" pair.

    Because they have the same UUID, I believe it's not possible(Or at least reliable) for me to use getCharacteristic() to get a handle for both of them, and it becomes necessary to use getCharacteristics() and iterate through them to find the correct ones.

    However, it appears that getCharacteristics() in Espruino does not take a UUID argument as a filter, so I end up also getting the two characteristics I'm not interested in in the array of results.

    In Web Bluetooth, it looks like BluetoothRemoteGATTCharacteristic has a UUID property, but this property does not appear to exist and/or work in Espruino. Attempting to print the UUIDs of the characteristics always results in the value 0x0000.

    So how do I go about getting handles for the correct characteristics?

    Attached is a screenshot of the service/characteristics, lightly anonymized.

Actions