{"id":9839,"date":"2020-06-27T21:52:46","date_gmt":"2020-06-28T04:52:46","guid":{"rendered":"https:\/\/www.apolonio.com\/blog\/?p=9839"},"modified":"2020-06-27T21:52:46","modified_gmt":"2020-06-28T04:52:46","slug":"bluetooth-rabbit-hole-again","status":"publish","type":"post","link":"https:\/\/www.apolonio.com\/blog\/?p=9839","title":{"rendered":"Bluetooth Rabbit Hole Again"},"content":{"rendered":"\n<p>Trying to loop back in to zoneminder but my mind got distracted by Bluetooth again.<\/p>\n\n\n\n<p>This time trying to get python to talk back and forth with my BLE device.<\/p>\n\n\n\n<p>Learned a lot today, biggest was that something is wrong when running it from CentOS, and things work right when running from a Raspberry Pi 0 W.<\/p>\n\n\n\n<p>So if you are following this, do it from a Pi.<\/p>\n\n\n\n<p>Run the following command from your pi<\/p>\n\n\n\n<p>gatttool -b ff:ff:c1:aa:bb:cc -I<\/p>\n\n\n\n<p>Replace the MAC with whatever your MAC is for your device.<\/p>\n\n\n\n<p>Bah, this is going to take too long here is the code.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/usr\/bin\/python3\nimport pygatt\nfrom binascii import hexlify\n\nadapter = pygatt.GATTToolBackend()\n\ndef handle_data(handle, value):\n   print(\"Received data: %s\" % hexlify(value))\n\ntry:\n   adapter.start()\n   device = adapter.connect('ff:ff:c1:aa:bb:cc')\n   print(\"Device Connected\")\n   device.subscribe(\"0000ffe1-0000-1000-8000-00805f9b34fb\",callback=handle_data,indication=False,wait_for_response=False)\n   command = input(\"# \")\n   while (command != \"q\"):\n      print (command)\n      if (command == \"a\"):\n         #char-write-cmd 0x0b 01\n         device.char_write(\"00002a06-0000-1000-8000-00805f9b34fb\",bytearray([0x01,0x01]),wait_for_response=False)\n      if (command == \"b\"):\n         #char-write-cmd 0x0b 00\n         device.char_write(\"00002a06-0000-1000-8000-00805f9b34fb\",bytearray([0x00,0x00]),wait_for_response=False)\ncommand = input(\"# \")\n\nfinally:\n   adapter.stop()<\/pre>\n\n\n\n<p>Weight: 313.6<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Trying to loop back in to zoneminder but my mind got distracted by Bluetooth again. This time trying to get python to talk back and forth with my BLE device. Learned a lot today, biggest was that something is wrong &hellip; <a href=\"https:\/\/www.apolonio.com\/blog\/?p=9839\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,11,3,12,9],"tags":[],"class_list":["post-9839","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi","category-technical","category-training","category-virtualization","category-weighin"],"_links":{"self":[{"href":"https:\/\/www.apolonio.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/9839","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.apolonio.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.apolonio.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.apolonio.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.apolonio.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9839"}],"version-history":[{"count":1,"href":"https:\/\/www.apolonio.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/9839\/revisions"}],"predecessor-version":[{"id":9840,"href":"https:\/\/www.apolonio.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/9839\/revisions\/9840"}],"wp:attachment":[{"href":"https:\/\/www.apolonio.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9839"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.apolonio.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9839"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.apolonio.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}