function connectDevice(params) {
    var address = params.address;
    //console.log(address + "|Internal call to connect");
    var d = Q.defer();
    var paramsObj = {
        "address": address
    };
    bluetoothle.connect(
        function connected(obj) { // success
            //console.log(address + "|Internal call to connect - success");
            if (obj.status == "connected") {
                d.resolve(obj);
            } else {
                obj.connectFailed = true;
                d.reject(obj); //sould this work? it might be a delayed error
            }
        },
        function conenct_err(obj) { // failure function
            d.reject(obj);
        },
        paramsObj);

    return d.promise;
}
/*
    Connect to a Bluetooth LE device. The app should use a timer to limit the connecting time in case connecting 
    is never successful. Once a device is connected, it may disconnect without user intervention. The original 
    connection callback will be called again and receive an object with status => disconnected. To reconnect to 
    the device, use the reconnect method. If a timeout occurs, the connection attempt should be canceled using
    disconnect(). For simplicity, I recommend just using connect() and close(), don't use reconnect() or disconnect().
    */
Connect to a Bluetooth LE device. The app should use a timer to limit the connecting time in case connecting
is never successful. Once a device is connected, it may disconnect without user intervention. The original
connection callback will be called again and receive an object with status => disconnected. To reconnect to
the device, use the reconnect method. If a timeout occurs, the connection attempt should be canceled using
disconnect(). For simplicity, I recommend just using connect() and close(), don't use reconnect() or disconnect().
Connect to a Bluetooth LE device . The app should use a timer to limit the connecting time in case connecting is never successful . Once a device is connected it may disconnect without user intervention . The original connection callback will be called again and receive an object with status = > disconnected . To reconnect to the device use the reconnect method . If a timeout occurs the connection attempt should be canceled using disconnect () . For simplicity I recommend just using connect () and close () don ' t use reconnect () or disconnect () .
function connectDevice(params) {
    var address = params.address;
    var d = Q.defer();
    var paramsObj = {
        "address": address
    };
    bluetoothle.connect(
        function connected(obj) { 
            if (obj.status == "connected") {
                d.resolve(obj);
            } else {
                obj.connectFailed = true;
                d.reject(obj); 
            }
        },
        function conenct_err(obj) { 
            d.reject(obj);
        },
        paramsObj);
    return d.promise;
}
function connectDevice ( params ) { var address = params . address ; var d = Q . defer ( ) ; var paramsObj = { "address" : address } ; bluetoothle . connect ( function connected ( obj ) { if ( obj . status == "connected" ) { d . resolve ( obj ) ; } else { obj . connectFailed = true ; d . reject ( obj ) ; } } , function conenct_err ( obj ) { d . reject ( obj ) ; } , paramsObj ) ; return d . promise ; }
Connect to a Bluetooth LE device.
Connect to a Bluetooth LE device .
//console.log(address + "|Internal call to connect"); // success //console.log(address + "|Internal call to connect - success"); //sould this work? it might be a delayed error // failure function