Objective
This article will use a simple example of how to use the Bluetooth function of the Android phone to periodically search the signal strength of the peripheral Bluetooth node, for interested in playing Bluetooth indoor positioning enthusiasts to provide a little ideas. ( If you want to use the Android phone and Bluetooth module communication to achieve remote control function, you can refer to: http://www.cnblogs.com/zjutlitao/p/4231635.html , want to use the notebook and Bluetooth module communication to achieve the remote control function, you can refer to: http://www.cnblogs.com/zjutlitao/p/3886826.html; If you want to use a notebook Bluetooth to do bluetooth positioning, haha, suggest giving up ... )
Effect
Periodically scan peripheral Bluetooth devices--draw different sizes of circles based on signal strength (for developers, the introduction of how to search for BT signal strength LZ thought it should be enough, and then it was free to play)
Brief introduction
Code reference:https://github.com/beautifulzzzz/Android/commit/e1d12e756d8e7c9efd9c89fb084c3f100b451427
The " member variable " Surfaceview space is used to draw the animation effect, Bluetoothadapter is used to get the Bluetooth device, followed by Bluetooth device information vector, Bluetooth device signal strength vector, brush vector ~
Initialization is performed in the OnCreate function by initializing the ① brush initialization, ②surfaceview initializing and setting the callback function (because the interface cannot be updated in the thread, So the message is sent out of the thread and processed in the message handle, so we see a message handle in the 37~65 line to receive the message and redraw the Surfaceview based on the message content)
The start search function is used every time a search is triggered, where the first time a Menuoptions button event is triggered in a 182 row, and then the dodiscovery is called periodically after the drawing ends.
" Search information and store " When you start a search, if you search for a device, the bleetoothdevice.action_found message is triggered, and the Bluetooth device's name and MAC address are placed in a vector to save Signal strength Rssi is placed in the Rssi vector to be saved; Bluetoothadapter.action_discovery_finished is triggered when the search is over, indicating that a search period is over, sending msg through the bundle, informing the drawing The message handle to draw.
"The drawing message handle handles bundle messages and refreshes " when a search cycle is completed, a bundle message is sent to trigger the drawing (45~48 line below), and the drawing finishes calling Dodiscovery to search again, and so on.
Postscript
When you know how to periodically get around the Bluetooth signal strength, and then combined with the marketing of Bluetooth nodes in the market based on positioning technology can design a specific application scenario of the indoor positioning ~ hope that this article is helpful!!! ☆⌒ (*^-゜) v
RELATED LINKS
This article link: http://www.cnblogs.com/zjutlitao/p/4314096.html
More Highlights: http://www.cnblogs.com/zjutlitao/p/
Project code: HTTP://PAN.BAIDU.COM/S/1MGZCW4O
[Android] 13, Andoran tooth positioning (a)--how to periodically get Bluetooth node signal strength?