2017년 6월 4일 일요일

BLE - Notify about disconnect


I am trying to work on an app using the BLE. However, I am stuck trying to figure out how to have the scanning-connecting process to keep on going whenever a disconnection occurs. I want this to be more automatic. So I have my "scanning" once you initialize the app, so I guess that's why it does not restart the scanning because the screen is not being initialized. I tried setting some timer but 
1. I still don't understand those very well, 
2. My app stops at the last command of the clock. 

SO, can you please help me. A screenshot is found attached. 



(In summary I want the app to start scanning once a disconnection occurs,)

--
This is not easy to do, because your device will stop advertising once it is connected. It seems that a state change is only detected after 20 seconds or so.
The way to do this is to have the device communicate with your phone constantly (at cost of battery life). Then, when you do not recieve data, the connection may be lost.
There are also BLE devices that support notification of range events, like beacons. I do not know what you device can do in this respect.

-- 
To add: maybe just using when BluetoothLE.RssiChanged (Recieved signal strength) could help. A strength of 0 would mean disconnected. Let us know if it works. I never tried.

refer to: Bluetooth-Low-Energy RSSI changes periodically on Android devices

-- 
You said  "The way to do this is to have the device communicate with your phone constantly (at cost of battery life)."
How do I do that.

I have a beacon, that seems to disconnected after a couple of seconds of being connected. 

-- 
Put a clock in your app, enable it after the beacon is connected, set a timer interval of 500 milliseconds, or whatever seems suitable and every time the timer event fires (use when timer... event block), send something to the beacon. I do not know what your beacon expects as communication messages, so you will have to experiment.
That is exactly the fun of using App Inventor, experiment and find out.

-- 

댓글 없음:

댓글 쓰기