I'm looking at the server side aspects of the SDK, particularily the bt_comm.py script. What I'm wondering is if there's a simple way to query if a given inPulse device is available or not. Eg. in the PingStat example, if you had the py_ping_stat.py script looping, or being called regularily by a daemon, but you had gone out of range or your inPulse was otherwise unavailable, then I assume the script would fail with an error.
So what I'd like to implement is a method of determining, prior to attempting a bluetooth communication, if the watch is actually present.
Looking at the lightblue documentation, what comes to mind is using the
finddevicename(address, usecache=True) function. Maybe something like this (pseudocode as I don't know Python yet):
import lightblue
bdaddress="00:00:00:00:00:00"; // the address of our bluetooth device
try:
if(lightblue.finddevicename(bdaddress, false)) {
return true; //we got an answer so our bdaddress is valid and in range/connected
} else {
return false; // no answer so bdaddress is invalid or out of range/disconnected
}
except:
return false; // there was an error so the address is invalid or out of range / not connected
Alternatively, it might be preferable / easier to use the
finddevices(getnames=True, length=10) function, then just parse the returned list and see if the desired address is present or not. (My lack of python knowledge prevents me from figuring out which option would be better /easier to implement. For now.)
I'm thinking something like this could be incorporated into the existing bt_comm.py tool as a function, either under the BT_Socket class or by itself.
Any ideas / assistance / feedback would be most welcome!