Hi,
Working with the evothings BLE example using the RFduino.
It works great when connecting and turning on and off the blue LED. However, when the RFduino is not available, the client app on my phone takes forever to report back that it can not connect with the device. It is stuck on "Connecting..." for long time.
Where in the code can I make changes to set the error reporting time, let say after trying to connect to the rfduino for up to a maximum of 30sec, if can't find one, report Error:
Thanks
Error code reporting time issue
Re: Error code reporting time issue
That would be the function evothings.rfduinoble.connect().
There, one might call setTimeout() before startScan(), store the timer ID and disable it in the startScan() callback if a device is found.
There, one might call setTimeout() before startScan(), store the timer ID and disable it in the startScan() callback if a device is found.
Re: Error code reporting time issue
Thanks Fredrik,
I need a little bit more guidance as I am not expert with js. This is what I did (after some research how to use setTimeout) and, as you suggested modified the code. But my question is I wanted my phone to start scanning and report back within 30sec, the Error message - if it can't find the RFduino, So i put the setTimeout after the startScan, would that be wrong? Here is my modified code. I tested this but it did not work, (could not connect to the RFduino even if it is present). So I think I did something wrong modifying it. Also not 100% sure if i placed the clearTimeout(myVar); correctly in the code, Any suggestions would be great
Thanks a lot !
I need a little bit more guidance as I am not expert with js. This is what I did (after some research how to use setTimeout) and, as you suggested modified the code. But my question is I wanted my phone to start scanning and report back within 30sec, the Error message - if it can't find the RFduino, So i put the setTimeout after the startScan, would that be wrong? Here is my modified code. I tested this but it did not work, (could not connect to the RFduino even if it is present). So I think I did something wrong modifying it. Also not 100% sure if i placed the clearTimeout(myVar); correctly in the code, Any suggestions would be great
Code: Select all
evothings.rfduinoble.connect = function(deviceName, success, fail)
{
evothings.easyble.startScan(
myVar = setTimeout(
function(device)
{
console.log('found device: ' + device.name);
if (device.name == deviceName)
{
evothings.easyble.stopScan();
console.log('connectToDevice');
internal.connectToDevice(device, success, fail);
clearTimeout(myVar);
}
}, 3000),
function(errorCode)
{
fail(errorCode);
});
};
Thanks a lot !
Re: Error code reporting time issue
You put the setTimeout() call inside startScan(), which wouldn't work well. The timer should be a local variable (the "var" specifier), so outside functions can't accidentally mangle it. We also need to call stopScan() to prevent further callbacks.
Disclaimer: this code is untested and may fail.
Disclaimer: this code is untested and may fail.
Code: Select all
evothings.rfduinoble.connect = function(deviceName, success, fail)
{
var timer = setTimeout(function() {
console.log('timeout!');
evothings.easyble.stopScan();
timer = false;
fail('timeout!');
}, 3000);
evothings.easyble.startScan(
function(device)
{
console.log('found device: ' + device.name);
if (device.name == deviceName)
{
evothings.easyble.stopScan();
console.log('connectToDevice');
internal.connectToDevice(device, success, fail);
clearTimeout(timer);
}
},
function(errorCode)
{
fail(errorCode);
});
};
Return to “Questions and answers”
Who is online
Users browsing this forum: No registered users and 42 guests