• Many thanks for that.

    We now have some real progress of sorts.

    The second option you provided worked in terms of invoking the PIN on the camera screen.

    The first option just went straight through as per the original version and did not invoke the PIN or fire the passkeyRequest.

    I inserted that part into the second one just to confirm that it does fire and it does.

    So, this is the version I have been working with

    function WriteToCamera_V1(){
    var gatt;
    NRF.requestDevice({ filters: [{ id: "90:fd:9f:b8:ca:37 public" }] }).then(function(device) {
    dev=device;
    NRF.setSecurity({keyboard:1});
    console.log("Connecting"); 
    device.on('passkeyRequest', function() {
    console.log("passkey requested");
    //dev.sendPasskey("123456");
    });
    return device.gatt.connect();
    }).then(function(g) {
    gatt = g;
    console.log("Connected");
    return gatt.startBonding(true); //<---- use startBonding(true) here to force re-pairing - might be handy for debug
    }).then(function() {
    console.log("bonded", gatt.getSecurityStatus());
    return gatt.getPrimaryService("291d567a-6d75-11­e6-8b77-86f30ca893d3");
    }).then(function(service) {
    return service.getCharacteristic("5dd3465f-1aee­-4299-8493-d2eca2f8e1bb");
    }).then(function(characteristic) {
    console.log("Writing To Characteristic");
    return characteristic.writeValue([0xFF, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00] );
    }).then(function() {
    gatt.disconnect();
    console.log("Done!");
    });
    }
    
    

    When I trigger it from the Button, it produces the following in the console

    >
    WRITE TO CAMERA_V1
    Connecting
    Connected
    bonded { "connected": true, "encrypted": false, "mitm_protected": false, "bonded": true }
    passkey requested
    Writing To Characteristic
    Done!
    >
    

    The problem is that it executes the write characteristic and disconnects before I've had any sort of opportunity to pass the PIN to it.

    I put in a dummy PIN that I've commented out to test that it would send it to the camera and it does send it and the camera invokes a failed connect message as expected with it being the wrong PIN.

    What I've done to give myself a chance to send the correct PIN is to split the bond function out without the write characteristic part which I activate off one button, then change the PIN value in the console (using the variable 'p' ) and then fire a separate function to do the sendPasskey off another button.

    As soon as I fire the sendPasskey function the camera (Line 6) does the immediate disconnect in the same way as if I'd sent it the wrong PIN in the main function and produces the following :

    Connecting
    Connected
    bonded { "connected": true, "encrypted": false, "mitm_protected": false, "bonded": true }
    >p="314390"
    ="314390"
    SENDING PIN
    Uncaught InternalError: BLE task completed that wasn't scheduled (3/0)
    > 
    

    My guess at the moment (with a dummy and a correct PIN producing the same outcome) is that I'm doing something wrong that is somehow related to Comments 6 & 7 from User63214 when he was attempting to do the same?

About

Avatar for user97234 @user97234 started