{"id":6642,"date":"2018-12-20T11:14:08","date_gmt":"2018-12-20T11:14:08","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=6642"},"modified":"2018-12-20T11:14:08","modified_gmt":"2018-12-20T11:14:08","slug":"bluetooth-proximity","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/bluetooth-proximity\/","title":{"rendered":"Bluetooth Proximity"},"content":{"rendered":"<p>This post is going to cover aspects of determining proximity with Bluetooth devices and hence covers a couple of key pieces of data.<\/p>\n<p><strong>RSSI<\/strong><\/p>\n<p>RSSI stands for Received Signal Strength Indication as is a measurement of radio signal strength, measure in dBm (decibel-milliwatts). The higher the RSSI value, the stronger the signal.<\/p>\n<p>Signal strength can be affected by many things. Along with the obvious environment affects, such as walls and interference the different chipsets used can give wide variations and hence cannot be guaranteed to indicate whether one Bluetooth device is actually closer than another.<\/p>\n<p>To use RSSI effectively to try to approximate proximity, at least in terms of whether we&#8217;re getting closer to the device or moving further away, we should track multiple samples of RSSI over time. If the signal is getting weaker then we might suggest the device is getting further away (ofcourse taking into account any environment and others forms of interference).<\/p>\n<p>RSSI can be calculated (although it will likely be available from your preferred Bluetooth LE library) using the following formula (although this includes distance as a parameter which is, after all what we&#8217;re after with proximity so unlikely to have).<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\nRSSI = -10n log(d) + A\r\n\r\nwhere \r\n\r\nd is distance\r\nA is txPower\r\nand\r\nn is a signal propagation constant \r\n(for example it might be set to 2 in free space, but \r\nvary in a walled area).\r\n<\/pre>\n<p>In situations where we have RSSI only (i.e. no TX Power) we can approximate proximity using the signal strength by checking the RSSI against the following range of values<\/p>\n<p>RSSI of -50dBm to 0dBm &#8211; very close<br \/>\nRSSI of -90dBm to -50dBm &#8211; medium distance<br \/>\nRSSI of less than -90dBm &#8211; far away<\/p>\n<p>However, as stated, signals may be affected by different forms of interference and also by the chipsets and power used for the radio, so can only be taken as &#8220;guesses&#8221; to proximity.<\/p>\n<p><strong>TX Power<\/strong><\/p>\n<p>If you see the an option on your preferred Bluetooth LE library called txPower which stands for transmitted power (also known as measured power). <\/p>\n<p><em>Note: This doesn&#8217;t seem to be available\/used by all Bluetooth devices. In which case it&#8217;ll be defaulted to zero.<\/em><\/p>\n<p>TX power is used within the previous formula (along with the RSSI value) to help determine distance or proximity estimates. It allows us to take into consideration the actual power of the Bluetooth device as it&#8217;s a calibrated (read-only constant) which indicates the expected RSSI at a distance of 1 metre from the Bluetooth device. So with RSSI and TX Power we can rearrange the previous equation to calculate distance, here&#8217;s a C# implementation of that<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\npublic static double GetProximity(int rssi, int txPower)\r\n{\r\n   const int signalPropagationConstant = 2; \r\n   return Math.Pow(10d, ((double) txPower - rssi) \/ (10 * signalPropagationConstant));\r\n}\r\n<\/pre>\n<p>Obviously when calculating proximity with a 0 txPower the distance will no longer be valid and hence you&#8217;ll have to simply have to use sample RSSI to get a basic idea of signal strength).<\/p>\n<p><strong>References<\/strong><br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/uwp\/devices-sensors\/ble-beacon#gauging-distance\" rel=\"noopener\" target=\"_blank\">Bluetooth LE Advertisements &#8211; Gauging Distance<\/a><br \/>\n<a href=\"https:\/\/iotandelectronics.wordpress.com\/2016\/10\/07\/how-to-calculate-distance-from-the-rssi-value-of-the-ble-beacon\/\" rel=\"noopener\" target=\"_blank\">How to Calculate Distance from the RSSI value of the BLE Beacon<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/22784516\/estimating-beacon-proximity-distance-based-on-rssi-bluetooth-le\" rel=\"noopener\" target=\"_blank\">Estimating beacon proximity\/distance based on RSSI &#8211; Bluetooth LE<\/a><br \/>\n<a href=\"https:\/\/blog.bluetooth.com\/proximity-and-rssi\" rel=\"noopener\" target=\"_blank\">Proximity And RSSI<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post is going to cover aspects of determining proximity with Bluetooth devices and hence covers a couple of key pieces of data. RSSI RSSI stands for Received Signal Strength Indication as is a measurement of radio signal strength, measure in dBm (decibel-milliwatts). The higher the RSSI value, the stronger the signal. Signal strength can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[231],"tags":[],"class_list":["post-6642","post","type-post","status-publish","format-standard","hentry","category-bluetooth"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6642","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=6642"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6642\/revisions"}],"predecessor-version":[{"id":6668,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6642\/revisions\/6668"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=6642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=6642"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=6642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}