• OK, so here we go with a basic template for connecting and sending commands.

    There is a bit of an issue regarding the bonding timing out when the flag isn't set to True to force it to pair. Basically, if you haven't sent the pin to it within about 7 seconds it times out which isn't long enough to set it through the terminal and send it.

    As I want to have the Pixl auto-connect to the camera as soon as it is switched on and stay connected, it would be a bit of a pain to have to go through the PIN entry process every time its switched on.

    Because the camera stores the bonding and it literally only needs to be sent the PIN once, I have not set it the flag to True but instead made a separate function with it being to True to initially set it. That way as soon as the Pixl powers on every time after the PIN has been set then it connects immediately and we are ready to send real commands to it.

    The process for initial bonding only then is
    1) Switch the Pixl on
    2) Wait for the PIN entry screen on the camera to timeout
    3) Press Button 4 on the Pixl which will start a new bonding process with no timeout
    4) Enter the PIN value from the console with pin="xxxxxx"
    5) Press Button 3 on the Pixl which will then send the PIN and complete the bonding.

    All subsequent restarts of the Pixl will connect the camera automatically with it being ready to receive commands.

    I have included an example byte array for a command (it triggers the Auto Focus on the camera) and this is then sent using Button 1 on the Pixl.

    The full camera control protocol for the camera can be downloaded here

    https://documents.blackmagicdesign.com/D­eveloperManuals/BlackmagicCameraControl/­20181019-740d71/BlackmagicCameraControl.­pdf

    var characteristicWrite;
    var characteristicRead;
    var dev;
    var gatt;
    var pin="";
    var ServUUId="291d567a-6d75-11e6-8b77-86f30c­a893d3";
    var CharUUID="5dd3465f-1aee-4299-8493-d2eca2­f8e1bb";
    
    function Connect(){
    // Insert own camera MAC address in id //
    NRF.requestDevice({ filters: [{ id: "90:fd:9f:b8:ca:37 public"  }] }).then(function(device) {
    dev=device;
    NRF.setSecurity({keyboard:1, mitm:1});
    console.log("Connecting");
    device.on('passkeyRequest', function() {
    console.log("passkey requested");
    });
    return device.gatt.connect();
    }).then(function(g) {
    gatt = g;
    console.log("Connected");
    return gatt.startBonding(); //< If the camera has been previously bonded the PIN pop-up will not be invoked //
    }).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");
        characteristicWrite=characteristic;
        return characteristic.writeValue([0xFF, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00] );
    }).then(function() {
      console.log("Done!");
    });
    }
    
    function Bond(){
    // Insert own camera MAC address in id //
    NRF.requestDevice({ filters: [{ id: "90:fd:9f:b8:ca:37 public" }] }).then(function(device) {
    dev=device;
    NRF.setSecurity({keyboard:1, mitm:1});
    console.log("Connecting");
    device.on('passkeyRequest', function() {
    console.log("passkey requested");
    });
    return device.gatt.connect();
    }).then(function(g) {
    gatt = g;
    console.log("Connected");
    return gatt.startBonding(true);//< This will force the PIN pop-up to be invoked irrespective of previous bond//
    }).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");
        characteristicWrite=characteristic;
        return characteristic.writeValue([0xFF, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00] );
    }).then(function() {
      console.log("Done!");
    });
    }
    
    function SendPin(){
    //Enter required PIN in console using pin="xxxxxx"//
    dev.sendPasskey(pin);
    }
    
    function WriteValNoConnect(){
    //Writes Auto-Focus command to the connected camera without re-connection//
    characteristicWrite.writeValue([0xFF, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00] );
    }
    
    function onInit(){
    //Automatically connects the camera and establishes Characteristic to be written to//
    // If camera has been bonded the PIN pop-up will not be invoked//
    Connect();
    }
    
    
    setWatch(function() {
      console.log("WRITING AUTO FOCUS COMMAND TO CAMERA");
      WriteValNoConnect();
    }, BTN, {edge:"rising", debounce:50, repeat:true});
    
    setWatch(function() {
      console.log("NO FUNCTION ASSIGNED");
    }, BTN2, {edge:"rising", debounce:50, repeat:true});
    
    setWatch(function() {
      console.log("SENDING PIN : "+pin);
      SendPin(); 
    }, BTN3, {edge:"rising", debounce:50, repeat:true});
    
    setWatch(function() {
      console.log("BONDING");
      Bond();
    }, BTN4, {edge:"rising", debounce:50, repeat:true});
    
    
About

Avatar for user97234 @user97234 started