{"id":825,"date":"2012-03-05T14:16:28","date_gmt":"2012-03-05T06:16:28","guid":{"rendered":"http:\/\/www.computersolutions.cn\/blog\/?p=825"},"modified":"2012-03-05T14:16:28","modified_gmt":"2012-03-05T06:16:28","slug":"bluetooth-notes-for-debian-linux","status":"publish","type":"post","link":"https:\/\/www.computersolutions.cn\/blog\/2012\/03\/bluetooth-notes-for-debian-linux\/","title":{"rendered":"Bluetooth notes for Debian\/ Linux"},"content":{"rendered":"<p>Some reminder notes for myself for playing around with Bluetooth adaptors.<\/p>\n<p>Note that bluetooth seems to be incredibly flaky &#8211; at least from my tests.<br \/>\nI would often get timeouts and failures.  Results will depend on the radio environment around you&#8230;<br \/>\nPlus apparently the bluetooth adaptors I have all have the same mac address, so thats also an issue if you encounter the same and have > 1 plugged into various computers&#8230;  Oh well, at least they were cheap!<\/p>\n<p>Did some post mortem testing with a T series Thinkpad, seemed better, but still not 100% &#8211; I guess thats why people just don&#8217;t use it.<\/p>\n<p>Install bluetooth &#8211; <\/p>\n<p><code>apt-get install bluez-utils bluetooth<\/code><\/p>\n<p>plug in a usb bluetooth adaptor<br \/>\nreboot <\/p>\n<p>This will install some useful bluetooth tools.<br \/>\nhcitool, hciconfig, rfcomm are the basic command line bluetooth tools we&#8217;ll be using.<\/p>\n<p>Hopefully at this point your device is recognized &#8211; <\/p>\n<p><code>hcitool dev<\/code><\/p>\n<p>This should return the mac address of the bluetooth adaptor:<\/p>\n<p><code># hcitool dev<br \/>\nDevices:<br \/>\n\thci0\t00:1F:81:00:08:30<\/code><\/p>\n<p>If the address is 00:00:00:00:00:00, then its not setup, check dmesg and see what kind of device you have.<\/p>\n<p>Heres mine &#8211; <\/p>\n<p><code>lsusb<br \/>\nBus 001 Device 003: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)<br \/>\n<\/code><\/p>\n<p>And a grep of ooth (as could be BlueTooth or Bluetooth or bluetooth&#8230;) from dmesg<\/p>\n<p><code><br \/>\ndmesg | grep ooth<br \/>\n[    4.845001] Bluetooth: Core ver 2.15<br \/>\n[    4.845130] Bluetooth: HCI device and connection manager initialized<br \/>\n[    4.845132] Bluetooth: HCI socket layer initialized<br \/>\n[    4.891477] Bluetooth: Generic Bluetooth USB driver ver 0.6<br \/>\n[    8.940263] Bluetooth: L2CAP ver 2.14<br \/>\n[    8.940264] Bluetooth: L2CAP socket layer initialized<br \/>\n[    8.943819] Bluetooth: RFCOMM TTY layer initialized<br \/>\n[    8.943822] Bluetooth: RFCOMM socket layer initialized<br \/>\n[    8.943823] Bluetooth: RFCOMM ver 1.11<br \/>\n[    8.990134] Bluetooth: BNEP (Ethernet Emulation) ver 1.3<br \/>\n[    8.990135] Bluetooth: BNEP filters: protocol multicast<br \/>\n[    9.298370] Bluetooth: SCO (Voice Link) ver 0.6<br \/>\n[    9.298372] Bluetooth: SCO socket layer initialized<br \/>\n<\/code><\/p>\n<p>If you don&#8217;t get a valid mac address, reboot, as that seemed to work for me.<br \/>\nYes, its a hassle, but I didn&#8217;t delve too deeply into what modules needed to load.<br \/>\nIf you don&#8217;t want to reboot I&#8217;ve modprobed for bluetooth and have the modules below post boot<\/p>\n<p>You can try loading those with modprobe <module><\/p>\n<p><code> lsmod | grep bluetooth<br \/>\nbluetooth              41827  9 sco,bnep,rfcomm,l2cap,btusb<br \/>\nrfkill                 13044  2 bluetooth<br \/>\n<\/code><\/p>\n<p>You can also use hciconfig to list the name of the device (this is what you&#8217;ll see listed in another device if you enable discovery&#8230;)<\/p>\n<p><code>hciconfig -a name<br \/>\nhci0:\tType: BR\/EDR  Bus: USB<br \/>\n\tBD Address: 00:1F:81:00:08:30  ACL MTU: 1021:4  SCO MTU: 180:1<br \/>\n\tUP RUNNING PSCAN ISCAN<br \/>\n\tRX bytes:3551 acl:52 sco:0 events:140 errors:0<br \/>\n\tTX bytes:1243 acl:50 sco:0 commands:53 errors:7<br \/>\n\tFeatures: 0xff 0x3e 0x09 0x76 0x80 0x01 0x00 0x80<br \/>\n\tPacket type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3<br \/>\n\tLink policy: RSWITCH HOLD SNIFF PARK<br \/>\n\tLink mode: SLAVE ACCEPT<br \/>\n\tName: 'Accel-OB2'<br \/>\n\tClass: 0x000000<br \/>\n\tService Classes: Unspecified<br \/>\n\tDevice Class: Miscellaneous,<br \/>\n\tHCI Version: 2.0 (0x3)  Revision: 0x44<br \/>\n\tLMP Version: 2.0 (0x3)  Subversion: 0x3<br \/>\n\tManufacturer: Cambridge Silicon Radio (10)<br \/>\n<\/code><\/p>\n<p>Assuming the above is working, hcitool dev gives you a mac address, then hcitool scan should give a list of nearby bluetooth devices.<br \/>\nSuggest make something discoverable &#8211; eg a closeby desktop with bluetooth for testing.<\/p>\n<p><code>hcitool scan<br \/>\nScanning ...<br \/>\n\t00:1E:52:EC:A5:50\tapple\u2019s iMac<br \/>\n<\/code>\t<\/p>\n<p>As you can see I have a device close by<br \/>\nLets get some info about it<\/p>\n<p><code># hcitool info 00:1E:52:EC:A5:50<br \/>\nRequesting information ...<br \/>\n\tBD Address:  00:1E:52:EC:A5:50<br \/>\n\tDevice Name: apple\u2019s iMac<br \/>\n\tLMP Version: 2.0 (0x3) LMP Subversion: 0x7ad<br \/>\n\tManufacturer: Cambridge Silicon Radio (10)<br \/>\n\tFeatures: 0xff 0xff 0x8f 0xfe 0x9b 0xf9 0x00 0x80<br \/>\n\t\t<3-slot packets> <5-slot packets> <encryption> <slot offset><br \/>\n\t\t<timing accuracy> <role switch> <hold mode> <sniff mode>\n\t\t<park state> <RSSI> <channel quality> <SCO link> <HV2 packets><br \/>\n\t\t<HV3 packets> <u-law log> <A-law log> <CVSD> <paging scheme>\n\t\t<power control> <transparent SCO> <broadcast encrypt><br \/>\n\t\t<EDR ACL 2 Mbps> <EDR ACL 3 Mbps> <enhanced iscan><br \/>\n\t\t<interlaced iscan> <interlaced pscan> <inquiry with RSSI><br \/>\n\t\t<extended SCO> <EV4 packets> <EV5 packets> <AFH cap. slave><br \/>\n\t\t<AFH class. slave> <3-slot EDR ACL> <5-slot EDR ACL><br \/>\n\t\t<AFH cap. master> <AFH class. master> <EDR eSCO 2 Mbps><br \/>\n\t\t<EDR eSCO 3 Mbps> <3-slot EDR eSCO> <extended features><br \/>\n<\/code><\/p>\n<p>Ping it<\/p>\n<p><code>l2ping  00:1E:52:EC:A5:50<\/p>\n<p>Ping: 00:1E:52:EC:A5:50 from 00:1F:81:00:08:30 (data size 44) ...<br \/>\n44 bytes from 00:1E:52:EC:A5:50 id 0 time 17.76ms<br \/>\n44 bytes from 00:1E:52:EC:A5:50 id 1 time 31.87ms<br \/>\n44 bytes from 00:1E:52:EC:A5:50 id 2 time 23.92ms<br \/>\n<\/code><\/p>\n<p>Lets try to connect to it<\/p>\n<p><code><br \/>\nhcitool cc  00:1E:52:EC:A5:50<br \/>\nhcitool auth  00:1E:52:EC:A5:50<br \/>\n<\/code><\/p>\n<p>&#8211; For auth to work, you&#8217;ll need to setup a pincode file in  \/var\/lib\/bluetooth\/[mac address of the bluetooth adaptor inside your computer]\/pincodes<br \/>\nAdd the mac address of the device you want to connect to, and the pincode e.g.<\/p>\n<p><code>cat \/var\/lib\/bluetooth\/00:1F:81:00:08:30\/pincodes<\/p>\n<p>#mac address of device connecting to,   pin to use when connecting<br \/>\n00:1E:52:EC:A5:50 0000<\/code><\/p>\n<p>If you want to be able to see your computer from another device, make it visible &#8211;<br \/>\nMake our computer visible to a bluetooth scan<br \/>\n<code>hciconfig hci0 piscan<\/code><\/p>\n<p>We can also setup a serial connection to our bluetooth device we want to connect to<br \/>\nrfcomm sets up  a virtual serial port connection on the hci port specified.  Then you can access the device via a serial connection &#8211; eg for gnokii or similar.<\/p>\n<p><code>rfcomm connect 0 00:1E:52:EC:A5:50<\/code><\/p>\n<p>Assuming you&#8217;ve connected to the device, and setup an rfcomm serial connection, you can use gnokii to query the device.<br \/>\nGnokii is mostly for Nokia phones, but you can use AT commands to connect to other devices, such as iPhones etc.<br \/>\nFor my test purposes, I needed to assist with integrating SMS to PHP, so was looking at setting up a bluetooth connection to a phone, then querying that for sms&#8217;s every 30 seconds or so, then passing that to a db or php script.  Gnokii was the second part of that equation, as it can do some of that without too much headache.<\/p>\n<p> (in gnokii &#8211; get the phone details)<br \/>\n <code>gnokii --shell 2> \/dev\/null<\/p>\n<p> > --identify<\/p>\n<p> #(in gnokii - get the first sms in the phone)<br \/>\n > --getsms IN 1<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some reminder notes for myself for playing around with Bluetooth adaptors. Note that bluetooth seems to be incredibly flaky &#8211; at least from my tests. I would often get timeouts and failures. Results will depend on the radio environment around you&#8230; Plus apparently the bluetooth adaptors I have all have the same mac address, so [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[25,4],"tags":[386,387,389,388],"class_list":["post-825","post","type-post","status-publish","format-standard","hentry","category-technical-mumbo-jumbo","category-useful-info","tag-bluetooth","tag-gnokii","tag-hci","tag-sms"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/comments?post=825"}],"version-history":[{"count":1,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/825\/revisions"}],"predecessor-version":[{"id":826,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/825\/revisions\/826"}],"wp:attachment":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/media?parent=825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/categories?post=825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/tags?post=825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}