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!
Reconnecting to a Known Device
Re: Reconnecting to a Known Device
The "easyble" library does not support this use case. You would have to use the underlying cordova-ble plugin directly, like so:
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!
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 11 guests