Page 1 of 1

Reconnecting to a Known Device

Posted: 15:14, 11 May 2016
by sjrcgtek
I am building an app where I keep a list of known devices (i.e. devices that I previously scanned for and connected to). When my app restarts, I want to reconnect to these devices, but I can't reinitiate the scan because the device is not in pairing mode. The problem is that i no longer have a device JSON object with all the methods added to it by the easyble scan/connect. It seems that the api should provide something like the following:

evothings.easyble.reconnect = function(device,success,fail) {
console.log("Attempting Reconnect on: " + device.address);
internal.knownDevices[device.address] = device;
internal.addMethodsToDeviceObject(device)
internal.connectToDevice(device,function(dvc) {
internal.connectedDevices[dvc.address] = dvc;
success(dvc);
},fail);
}

It is, of course, possible that I have misunderstood this process. If so please advise. Thanks!

Re: Reconnecting to a Known Device

Posted: 12:39, 30 Jun 2016
by Fredrik
The "easyble" library does not support this use case. You would have to use the underlying cordova-ble plugin directly, like so:

Code: Select all

evothings.ble.connect(
   address,
   function(info)
   {
      console.log('BLE connect status for device: '
         + info.deviceHandle
         + ' state: '
         + info.state);
   },
   function(errorCode)
   {
      console.log('BLE connect error: ' + errorCode);
   }
);


However, I suspect it will not work, as most BLE devices I've seen will accept connections only when in advertising mode.

Some BLE devices also change address randomly and frequently, making their old addresses invalid.

Good luck!