{"id":265,"date":"2007-01-29T21:07:26","date_gmt":"2007-01-29T21:07:26","guid":{"rendered":"http:\/\/beta.robertprice.co.uk\/robblog\/2007\/01\/programming_bluetooth_using_python-shtml\/"},"modified":"2007-01-29T21:07:26","modified_gmt":"2007-01-29T21:07:26","slug":"programming_bluetooth_using_python-shtml","status":"publish","type":"post","link":"https:\/\/www.robertprice.co.uk\/robblog\/programming_bluetooth_using_python-shtml\/","title":{"rendered":"Programming Bluetooth Using Python"},"content":{"rendered":"<p>\nI discovered the <a href=\"http:\/\/org.csail.mit.edu\/pybluez\/\">pybluez<\/a> project that brings bluetooth connectivity to <a href=\"http:\/\/www.python.org\/\">Python<\/a> today. It&#8217;s been around for a while and is compatible with both Windows (running XP) and Linux (running the bluez stack).\n<\/p>\n<p>\nI installed it using the ready made windows installer and it ran first time. It&#8217;s very simple and easy to use.\n<\/p>\n<p>\nI tweaked the example inquiry.py file by Albert Huang and set it up to show all the services on nearby devices.\n<\/p>\n<p>\nHere&#8217;s the code&#8230;\n<\/p>\n<div class=\"code\"><code>import bluetooth<br \/>\nprint \"looking for nearby devices...\"<br \/>\nnearby_devices = bluetooth.discover_devices(lookup_names = True, flush_cache = True, duration = 20)<br \/>\nprint \"found %d devices\" % len(nearby_devices)<br \/>\nfor addr, name in nearby_devices:<br \/>\nprint \"  %s - %s\" % (addr, name)<br \/>\nfor services in bluetooth.find_service(address = addr):<br \/>\nprint \"       Name:        %s\" % (services[\"name\"])<br \/>\nprint \"       Description: %s\" % (services[\"description\"])<br \/>\nprint \"       Protocol:    %s\" % (services[\"protocol\"])<br \/>\nprint \"       Provider:    %s\" % (services[\"provider\"])<br \/>\nprint \"       Port:        %s\" % (services[\"port\"])<br \/>\nprint \"       Service id:  %s\" % (services[\"service-id\"])<br \/>\nprint \"\"<br \/>\nprint \"\"<br \/>\n<\/code><\/div>\n<p>\nHere&#8217;s a quick run through of the code.\n<\/p>\n<p>\nFirstly we need to import the bluetooth class to give us access to all that lovely bluetooth functionality.\n<\/p>\n<p>\nWe now look for nearby devices using <code>bluetooth.discover_devices<\/code>. I&#8217;m adding a few parameters as well. <code>lookup_names<\/code> is set to <code>True<\/code> so we can get the devices names instead of the just their addresses, and <code>flush_cache<\/code> is also set to <code>True<\/code> to make sure we always look for fresh information. Finally we set <code>duration<\/code> to 20, meaning we look for devices for up to 20 seconds. This is a bit excessive, but useful when testing.\n<\/p>\n<p>\nWe should have a list of devices now, assuming some were found, so we now loop over them.\n<\/p>\n<p>\nWe print out the name and address then look for services offered by the device by calling the <code>bluetooth.find_service<\/code> method and passing in the device&#8217;s address.\n<\/p>\n<p>\nThis returns a list of dictionaries describing the services available. We iterate over this and print out details.\n<\/p>\n<p>\nThat&#8217;s the code, now here&#8217;s a few results. I ran this on the train home and discovered 7 active bluetooth devices offereing a variety of services. I won&#8217;t bore you with them all, so here&#8217;s the entry for my <a href=\"http:\/\/www.nokia.com\/n93\">Nokia N93<\/a>.\n<\/p>\n<div class=\"code\">\n<pre>\nPerl - 00:16:BC:30:D8:76\nName:        AVRCP Target\nDescription: Audio Video Remote Control\nProtocol:    L2CAP\nProvider:    Symbian Software Ltd.\nPort:        23\nService id:  None\nName:        Hands-Free Audio Gateway\nDescription:\nProtocol:    RFCOMM\nProvider:    None\nPort:        28\nService id:  None\nName:        Headset Audio Gateway\nDescription:\nProtocol:    RFCOMM\nProvider:    None\nPort:        29\nService id:  None\nName:        SyncMLClient\nDescription:\nProtocol:    RFCOMM\nProvider:    None\nPort:        10\nService id:  None\nName:        OBEX File Transfer\nDescription:\nProtocol:    RFCOMM\nProvider:    None\nPort:        11\nService id:  None\nName:        Nokia OBEX PC Suite Services\nDescription:\nProtocol:    RFCOMM\nProvider:    None\nPort:        12\nService id:  None\nName:        SyncML DM Client\nDescription:\nProtocol:    RFCOMM\nProvider:    None\nPort:        13\nService id:  None\nName:        Nokia SyncML Server\nDescription:\nProtocol:    RFCOMM\nProvider:    None\nPort:        14\nService id:  None\nName:        OBEX Object Push\nDescription:\nProtocol:    RFCOMM\nProvider:    None\nPort:        9\nService id:  None\nName:        Dial-Up Networking\nDescription:\nProtocol:    RFCOMM\nProvider:    None\nPort:        2\nService id:  None\nName:        Imaging\nDescription:\nProtocol:    RFCOMM\nProvider:    None\nPort:        15\nService id:  None\n<\/pre>\n<\/div>\n<p>\nAs you can see it offers a lot of interesting services, but two have caught my eye and call for a bit more investigation later.\n<\/p>\n<p>\nFirstly there is the Imaging service on port 15. I wonder what that does? Does it take input from a remote camera?\n<\/p>\n<p>\nSecondly there is AVRCP Target the Audio Visual Remote Control Target from Symbian. I wonder if this means I can use a seperate bluetooth device to control my Nokia N93 when it&#8217;s playing back video?\n<\/p>\n<p>\nA quick google reveals a (confidential?) <a href=\"http:\/\/www.bluetooth.com\/NR\/rdonlyres\/0CD6930C-302E-4BB8-ACA8-199066B47ADE\/922\/AVRCPSpecv10.pdf\">specification document for AVRCP<\/a>&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I discovered the pybluez project that brings bluetooth connectivity to Python today. It&#8217;s been around for a while and is compatible with both Windows (running XP) and Linux (running the bluez stack). I installed it using the ready made windows installer and it ran first time. It&#8217;s very simple and easy to use. I tweaked &hellip; <a href=\"https:\/\/www.robertprice.co.uk\/robblog\/programming_bluetooth_using_python-shtml\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Programming Bluetooth Using Python&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[2],"tags":[38,45,53],"class_list":["post-265","post","type-post","status-publish","format-standard","hentry","category-dev","tag-mobile","tag-nokia","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Programming Bluetooth Using Python - Robert Price<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.robertprice.co.uk\/robblog\/programming_bluetooth_using_python-shtml\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Programming Bluetooth Using Python - Robert Price\" \/>\n<meta property=\"og:description\" content=\"I discovered the pybluez project that brings bluetooth connectivity to Python today. It&#8217;s been around for a while and is compatible with both Windows (running XP) and Linux (running the bluez stack). I installed it using the ready made windows installer and it ran first time. It&#8217;s very simple and easy to use. I tweaked &hellip; Continue reading &quot;Programming Bluetooth Using Python&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.robertprice.co.uk\/robblog\/programming_bluetooth_using_python-shtml\/\" \/>\n<meta property=\"og:site_name\" content=\"Robert Price\" \/>\n<meta property=\"article:published_time\" content=\"2007-01-29T21:07:26+00:00\" \/>\n<meta name=\"author\" content=\"rob\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/programming_bluetooth_using_python-shtml\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/programming_bluetooth_using_python-shtml\\\/\"},\"author\":{\"name\":\"rob\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"headline\":\"Programming Bluetooth Using Python\",\"datePublished\":\"2007-01-29T21:07:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/programming_bluetooth_using_python-shtml\\\/\"},\"wordCount\":377,\"keywords\":[\"Mobile\",\"Nokia\",\"Python\"],\"articleSection\":[\"Dev\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/programming_bluetooth_using_python-shtml\\\/\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/programming_bluetooth_using_python-shtml\\\/\",\"name\":\"Programming Bluetooth Using Python - Robert Price\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\"},\"datePublished\":\"2007-01-29T21:07:26+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/programming_bluetooth_using_python-shtml\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/programming_bluetooth_using_python-shtml\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/programming_bluetooth_using_python-shtml\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Programming Bluetooth Using Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\",\"name\":\"Robert Price\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\",\"name\":\"rob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"caption\":\"rob\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Programming Bluetooth Using Python - Robert Price","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.robertprice.co.uk\/robblog\/programming_bluetooth_using_python-shtml\/","og_locale":"en_GB","og_type":"article","og_title":"Programming Bluetooth Using Python - Robert Price","og_description":"I discovered the pybluez project that brings bluetooth connectivity to Python today. It&#8217;s been around for a while and is compatible with both Windows (running XP) and Linux (running the bluez stack). I installed it using the ready made windows installer and it ran first time. It&#8217;s very simple and easy to use. I tweaked &hellip; Continue reading \"Programming Bluetooth Using Python\"","og_url":"https:\/\/www.robertprice.co.uk\/robblog\/programming_bluetooth_using_python-shtml\/","og_site_name":"Robert Price","article_published_time":"2007-01-29T21:07:26+00:00","author":"rob","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rob","Estimated reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.robertprice.co.uk\/robblog\/programming_bluetooth_using_python-shtml\/#article","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/programming_bluetooth_using_python-shtml\/"},"author":{"name":"rob","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"headline":"Programming Bluetooth Using Python","datePublished":"2007-01-29T21:07:26+00:00","mainEntityOfPage":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/programming_bluetooth_using_python-shtml\/"},"wordCount":377,"keywords":["Mobile","Nokia","Python"],"articleSection":["Dev"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/www.robertprice.co.uk\/robblog\/programming_bluetooth_using_python-shtml\/","url":"https:\/\/www.robertprice.co.uk\/robblog\/programming_bluetooth_using_python-shtml\/","name":"Programming Bluetooth Using Python - Robert Price","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website"},"datePublished":"2007-01-29T21:07:26+00:00","author":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"breadcrumb":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/programming_bluetooth_using_python-shtml\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.robertprice.co.uk\/robblog\/programming_bluetooth_using_python-shtml\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.robertprice.co.uk\/robblog\/programming_bluetooth_using_python-shtml\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.robertprice.co.uk\/robblog\/"},{"@type":"ListItem","position":2,"name":"Programming Bluetooth Using Python"}]},{"@type":"WebSite","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website","url":"https:\/\/www.robertprice.co.uk\/robblog\/","name":"Robert Price","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.robertprice.co.uk\/robblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5","name":"rob","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","caption":"rob"}}]}},"_links":{"self":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/comments?post=265"}],"version-history":[{"count":0,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/265\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/media?parent=265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/categories?post=265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/tags?post=265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}