• Hi, im kinda struggling again using react-native-ble-plx

    I try to recognize when the button was pressed, i tried different things, my last approach was to add a characteristic and monitor this in my react native application, but the characteristic just wont show up, any ideas?

    NRF.setServices({
      '6e400001-b5a3-f393-e0a9-e50e24dcca9e': {
        '6e400004-b5a3-f393-e0a9-e50e24dcca9e': {
          value: 1,
          writable: false,
          notify: true,
          description: 'Button Characteristic',
          onSubscribe: function() {
            setWatch(function() {
              NRF.updateServices({
               '6e400001-b5a3-f393-e0a9-e50e24dcca9e': {
                 '6e400004-b5a3-f393-e0a9-e50e24dcca9e': {
                    value: 1,
                    notify: true
                  }
                }
              });
            }, BTN, {repeat: true, edge: 'rising', debounce: 50});
          }
        }
      }
    });
    
  • That looks good to me, but to make it show up you have to be sure that you're disconnected from bluetooth when you run NRF.setServices or at some point after (since the BLE stack needs to restart).

    ... but if you just wanted to detect a button press, maybe just do:

    setWatch(function() {
      Bluetooth.println("BTN");
    }, BTN, {repeat: true, edge: 'rising', debounce: 50});
    

    That will send just the text BTN plus a newline over the bluetooth connection (no extra control characters) and the existing code you posted up in the other thread should work fine

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

Struggle with button press with react-native-ble-plx

Posted by Avatar for user154849 @user154849

Actions