android - Bluetooth LE connection time/caching -



android - Bluetooth LE connection time/caching -

i want connect bluetooth device , write value characteristic fastest way it's possible. code gives bad results:

1) ble scan - can see have hardcoded mac adress of device want connect to. timestamp of connectgatt method invoke.

@override public void onlescan(bluetoothdevice device, int rssi, byte[] scanrecord) { if(device.getaddress().equals("f1:9f:ee:6b:ab:83")) { mconnectedgatt = device.connectgatt(this, false, mgattcallback); start = system.currenttimemillis()/1000; }; }

2) onconnectionchanged - enother timestamp , substract them know how much connecting operation lasted

@override public void onconnectionstatechange(bluetoothgatt gatt, int status, int newstate) { super.onconnectionstatechange(gatt, status, newstate); end = system.currenttimemillis()/1000; log.d("qwerty", "time " + (end - start)); if (status == bluetoothgatt.gatt_success && newstate == bluetoothprofile.state_connected) { log.d("qwerty","success"); gatt.discoverservices(); } else if (status == bluetoothgatt.gatt_success && newstate == bluetoothprofile.state_disconnected) { log.d("qwerty","disconnected"); } else if (status != bluetoothgatt.gatt_success) { log.d("qwerty","connection error"); gatt.disconnect(); } }

and there main problem. time between device.connectgatt , onconnectionstatechange takes 3 - 8 seconds far long me. i'd happy if around 1 sec. write characteristic takes less sec in onservicesdiscovered listener it's not problem.

question 1): there way create connection time faster?

question 2): there way store bluetooth connection device in cache, lastly long @ first connection , during later invokes faster?

question 3): other suggestions create work faster? maybe approach bad.

1) yes peripheral must give improve connection intervalparameters on connect. after services/characteristics discovery can slow them downwards 1 time again save battery on long lasting connection if need to.

2) bonding might help future connection.

3) if have many services/characteristics take longer find them , generate handle tables in lower layer stack. ios should send min-connection-interval of 20ms (32) , max of 40ms (64) can hack 10ms-20ms , around 18-19ms interval. on android might aggressive , can cause samsung refuse. seek [20;40ms]

android bluetooth bluetooth-lowenergy

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -