You are reading a single comment by @Jean-Philippe_Rey and its replies. Click here to read the full conversation.
  • Well, nice try but no difference, gatt is disconnected after the 1000ms delay.

    function Connect(dev){
      NRF.requestDevice({ filters: [{ name: Devname }] }).then(function(device) {
        return device.gatt.connect();
      }).then(function(g) {
        gatt = g;
        console.log(gatt);
        return new Promise(function(resolve) {
          setTimeout(resolve, 1000);
          console.log("delayed for 1000ms...");
        });
      }).then(function() {
          console.log("end delay");
        return gatt.getPrimaryService(serviceUUID);
      }).then(function(service) {
        return service.getCharacteristic(characteristic­UUID);
      }).then(function(characteristic) {
        return characteristic.writeValue(MessageToSend)­;
      }).then(function() {
        console.log("Done!");
      });
    }
    

    Which, when executed, gives:

    >Connect(MyDev)
    =undefined
    BluetoothRemoteGATTServer {
      "device": BluetoothDevice {
        "id": "96:05:05:f7:ac:1c random",
        "rssi": -64,
        "services": [  ],
        "data": new Uint8Array([2, 1, 4, 12, 9, 72, 75, 73, 18, 45, 54, 30, 54, 48, 49, 57]).buffer,
        "name": "MyActuator",
        "gatt":  ...
       },
      "connected": true }
    delayed for 1000ms...
    end delay
    Uncaught Error: Unhandled promise rejection: Not connected
    > 
    

    I really can't understand why it connects THEN disconnects quickly.

About