<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Bluetooth on dotnet.work</title>
        <link>https://dotnet.work/tags/bluetooth/</link>
        <description>Recent content in Bluetooth on dotnet.work</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en-US</language>
        <managingEditor>dotnet@oles.cloud (Ole Albers)</managingEditor>
        <webMaster>dotnet@oles.cloud (Ole Albers)</webMaster>
        <copyright>Ole Albers</copyright>
        <lastBuildDate>Sat, 27 Feb 2016 12:00:00 +0100</lastBuildDate><atom:link href="https://dotnet.work/tags/bluetooth/index.xml" rel="self" type="application/rss+xml" /><item>
            <title>Detecting Smartphone via Bluetooth on Linux (Raspberry Pi 2)</title>
            <link>https://dotnet.work/blog/detecting-smartphone-via-bluetooth-on-linux-raspberry-pi-2/</link>
            <pubDate>Sat, 27 Feb 2016 12:00:00 +0100</pubDate><author>dotnet@oles.cloud (Ole Albers)</author>
            <guid>https://dotnet.work/blog/detecting-smartphone-via-bluetooth-on-linux-raspberry-pi-2/</guid>
            <description>&lt;p&gt;After &lt;a class=&#34;link&#34; href=&#34;https://dotnet.work/blog/automate-your-synology-surveillancestation-with-some-simple-linux-commands/&#34; &gt;detecting my phone using WiFi&lt;/a&gt; (which does only work under Marshmallow while the phone is loading or the display is enabled) and &lt;a class=&#34;link&#34; href=&#34;https://dotnet.work/blog/tracking-fitbit-presence-under-linux-raspberry-pi-2/&#34; &gt;detecting the fitbit device&lt;/a&gt; I came back to my original task to detect my phone using Bluetooth.&lt;/p&gt;&#xA;&lt;p&gt; &lt;/p&gt;&#xA;&lt;p&gt;While there are many documents out there that describe this on different Linux and even raspberry variants none of those really worked for me. The raspberry 2 (Debian Jessie) seem to be a bit different there.&lt;/p&gt;&#xA;&lt;p&gt;First of all you need a Bluetooth USB dongle. I buyed the Logilink BT00015 (available at &lt;a class=&#34;link&#34; href=&#34;http://www.amazon.com/gp/product/B0096Y2HFW/ref=as_li_tl?ie=UTF8&amp;amp;camp=1638&amp;amp;creative=19454&amp;amp;creativeASIN=B0096Y2HFW&amp;amp;linkCode=as2&amp;amp;tag=derstammti-21&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;amazon.com&lt;/a&gt;, &lt;a class=&#34;link&#34; href=&#34;http://www.amazon.de/gp/product/B0096Y2HFW/ref=as_li_tl?ie=UTF8&amp;amp;camp=1638&amp;amp;creative=19454&amp;amp;creativeASIN=B0096Y2HFW&amp;amp;linkCode=as2&amp;amp;tag=derstammti-21&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;amazon.de&lt;/a&gt; or elsewhere). I would expect that others work, too. But as always: On Linux, drivers can be tricky and it&amp;rsquo;s always good to know working hardware.&lt;/p&gt;&#xA;&lt;p&gt;Before installing drivers it is always a good idea to update everything:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;sudo apt-get update&#xA;sudo apt-get upgrade&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then install the libraries needed for bluetooth&lt;/p&gt;&#xA;&lt;p&gt;sudo apt-get install &amp;ndash;no-install-recommends bluetooth&lt;/p&gt;&#xA;&lt;p&gt;I received an error that some dependencies could not be resolved. I fixed that by entering the following commands:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;sudo dpkg --configure -a&#xA;sudo apt-get install -f&#xA;`Now insert the USB dongle and restart the raspberry`&#xA;sudo shutdown -r now&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To check if the USB-dongle is detected,  enter the following command:&lt;/p&gt;&#xA;&lt;p&gt;lsusb&lt;/p&gt;&#xA;&lt;p&gt;This lists all USB devices. There should be one offering Bluetooth - services&lt;/p&gt;&#xA;&lt;p&gt;Now lets check if the Bluetooth itself works:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;/etc/init.d/bluetooth status&lt;/code&gt;&#xA;The response should now contain the word &amp;ldquo;Running&amp;rdquo;:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;pi@raspberrypi:~ $ /etc/init.d/bluetooth status&#xA;● bluetooth.service - Bluetooth service&#xA; Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled)&#xA; Active: active (running) since Sat 2016-02-27 19:31:45 UTC; 17min ago&#xA; Docs: man:bluetoothd(8)&#xA; Main PID: 7841 (bluetoothd)&#xA; Status: &amp;#34;Running&amp;#34;&#xA; CGroup: /system.slice/bluetooth.service&#xA; └─7841 /usr/lib/bluetooth/bluetoothd&#xA;`Now it&amp;#39;s time to check for devices. Do nothing with your phone right now and enter:`&#xA;hcitool scan&#xA;`This should display all Bluetooth-devices in Range. As you haven&amp;#39;t done anything with your phone yet it should not be displayed there. The output should be something like this:`&#xA;Scanning ...&#xA; 7C:2F:BE:EF:FA:CE Ole&#xA; 00:04:BE:EF:FA:CE SHIELD&#xA; B8:86:BE:EF:FA:CE Fette Glotze&#xA; 88:53:BE:EF:FA:CE TOMATO-PC&#xA; 48:44:BE:EF:FA:CE TVBluetooth&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; &lt;/p&gt;&#xA;&lt;p&gt;(I modified the MAC addresses. I am not absolutely sure if anyone could do evil things using the MACs, but I prefer not to find that out :) )&lt;/p&gt;&#xA;&lt;p&gt;Now put your phone into discovery mode. On Android Marshmallow you just have to enter your Bluetooth-settings for this. Then re-scan your devices. There should be one more, now:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;hcitool scan&#xA;&#xA;7C:2F:BE:EF:FA:CE Ole&#xA;00:04:BE:EF:FA:CE SHIELD&#xA;B8:86:BE:EF:FA:CE Fette Glotze&#xA;88:53:BE:EF:FA:CE TOMATO-PC&#xA;48:44:BE:EF:FA:CE TVBluetooth&#xA;&#xA;F8:95:C7:H0:0H:0H G4&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now just note your Mac-Address. We will &lt;strong&gt;not&lt;/strong&gt; pair our device. That takes a few steps and additional packages and additional problems. Pairing is not needed once we know the mac-address.&lt;/p&gt;&#xA;&lt;p&gt;Now we cam just check the presence by using the info command. Simply leave your Bluetooth-settings on the phone and enter&#xA;&lt;code&gt;sudo hcitool info F8:95:C7:H0:0H:0H&lt;/code&gt;&#xA;Event though your phone isn&amp;rsquo;t in discovery-mode anymore you will get some status information like the device name:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Requesting information ...&#xA; BD Address: F8:95:C7:H0:0H:0H&#xA; Device Name: G4&#xA; LMP Version: 4.1 (0x7) LMP Subversion: 0x6109&#xA; Manufacturer: Broadcom Corporation (15)&#xA;`if you turn off Bluetooth on your phone and re-enter that command you will receive a different response:`&#xA;Requesting information ...&#xA;Can&amp;#39;t create connection: Input/output error&#xA;`So that&amp;#39;s it. Just use the good old grep in your bash-script to check whether the phone is there or not:`&#xA;if hcitool info F8:95:C7:H0:0H:0H | grep -q &amp;#39;Device Name&amp;#39;; then&#xA; // Do whatever you like if you found it&#xA;fi&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Again: Have fun :)&lt;/p&gt;&#xA;</description>
        </item></channel>
</rss>
