You are reading a single comment by @Jean-Philippe_Rey and its replies. Click here to read the full conversation.
  • Here it is:
    Please note DevName,serviceUUID,characteristicUUID and MessageToSend have been replaced in the code below because of confidentiallity agreement.

    var devices;
    var gatt;
    var DevName="MyActuator";
    
    var serviceUUID="2fc3af42-7a4a-1431-d1f1-fs5­51e3bf022";
    var characteristicUUID="32160fb9-5337-4e71-b­0f8-ff412e3ae078";
    var MessageToSend=[0x00,0x01,0x03];
    
    
    function scan(){
      NRF.findDevices(function(d) {
        devices = d;
        console.log(devices);
      }, 5000);
    }
    
    function SendCommandToActuator() {
      NRF.requestDevice({ filters: [{ name: DevName }] }).then(function(device) {
        return device.gatt.connect();
      }).then(function(g) {
        gatt = g;
        console.log(gatt);
        return gatt.getPrimaryService(serviceUUID);
      }).then(function(service) {
        return service.getCharacteristic(characteristic­UUID);
      }).then(function(characteristic) {
        return characteristic.writeValue(MessageToSend)­;
      }).then(function() {
        gatt.disconnect();
        console.log("Done!");
      });
    }
    
    function Bond(){
      NRF.requestDevice({ filters: [{ name: DevName }] }).then(function(device) {
        console.log("found device");
        return device.gatt.connect();
      }).then(function(g) {
        gatt = g;
        console.log("connected");
        return gatt.startBonding();
      }).then(function() {
        console.log("bonded", gatt.getSecurityStatus());
        gatt.disconnect();
      }).catch(function(e) {
        console.log("ERROR",e);
      });
    }
    

    When I load this script and I call SendCommandToActuator(), I get this log:

    	
    >
     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v94 Copyright 2016 G.Williams
    >
    =undefined
    >SendCommandToActuator()
    =undefined
    BluetoothRemoteGATTServer {
      "device": BluetoothDevice {
        "id": "96:05:05:f7:ac:1c random",
        "rssi": -61,
        "services": [  ],
        "data": new Uint8Array([2, 1, 4, 12, 9, 79, 75, 73, 78, 45, 54, 50, 54, 48, 49, 57]).buffer,
        "name": "MyActuator",
        "gatt":  ...
       },
      "connected": true }
    Uncaught Error: Unhandled promise rejection: Disconnected
    
    
About