Reconnecting to a Known Device

Ask, and ye shall receive.
sjrcgtek
Posts: 6
Joined: 01:18, 07 Mar 2016

Reconnecting to a Known Device

Postby sjrcgtek » 15:14, 11 May 2016

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!

Fredrik
Site Admin
Posts: 196
Joined: 15:00, 18 Nov 2013

Re: Reconnecting to a Known Device

Postby Fredrik » 12:39, 30 Jun 2016

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!


Return to “Questions and answers”

Who is online

Users browsing this forum: No registered users and 14 guests