{"id":605,"date":"2017-07-11T21:31:58","date_gmt":"2017-07-11T21:31:58","guid":{"rendered":"https:\/\/test.warrensoft.co.uk\/wp-test\/home-hub\/?p=605"},"modified":"2018-12-08T07:29:27","modified_gmt":"2018-12-08T07:29:27","slug":"controller-amazon-dash-button","status":"publish","type":"post","link":"https:\/\/test.warrensoft.co.uk\/wp-test\/2017\/07\/11\/controller-amazon-dash-button\/","title":{"rendered":"Controller &#8211; Amazon Dash Button"},"content":{"rendered":"<p>The Amazon Dash is a self-contained WiFi enabled remote control button, available to Amazon Prime members, that we can interface with our home hub as an Impulse button. \u00a0The advantage is that we don&#8217;t require physical wiring or additional electronics &#8211; we just\u00a0<em>sniff<\/em> the network looking for the signature mac address of the button. The beauty of this adaptation is that we can implement hybrid Impulses, that respond to either fixed buttons connected to GPIO pins, or dash buttons free floating on the network.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-606\" src=\"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-content\/uploads\/2017\/07\/dash-e1498890739560-300x128.jpg\" alt=\"\" width=\"300\" height=\"128\" srcset=\"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-content\/uploads\/2017\/07\/dash-e1498890739560-300x128.jpg 300w, https:\/\/test.warrensoft.co.uk\/wp-test\/wp-content\/uploads\/2017\/07\/dash-e1498890739560-768x328.jpg 768w, https:\/\/test.warrensoft.co.uk\/wp-test\/wp-content\/uploads\/2017\/07\/dash-e1498890739560-1024x438.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>The process to configure the button, without actually committing yourself to the repeated purchase, is well documented elsewhere. The key piece of information we require is the button&#8217;s mac address. \u00a0I was able to glean this from my router log, or you can try the python test program sniff_test.py below.<\/p>\n<pre>import socket\r\nimport struct\r\nimport binascii\r\n\r\nmac_dict = {}\r\n\r\nRAW_SOCKET = socket.socket(\r\n socket.AF_PACKET,\r\n socket.SOCK_RAW,\r\n socket.htons(0x0003))\r\n\r\nwhile True:\r\n    packet = RAW_SOCKET.recvfrom(2048)\r\n    ethernet_header = packet[0][0:14]\r\n    ethernet_detailed = struct.unpack(\"!6s6s2s\", ethernet_header)\r\n\r\n    arp_header = packet[0][14:42]\r\n    arp_detailed = struct.unpack(\"2s2s1s1s2s6s4s6s4s\", arp_header)\r\n\r\n    ethertype = ethernet_detailed[2]\r\n    opcode = arp_detailed[4]\r\n    if ethertype == '\\x08\\x00' and opcode == '\\x00\\x00':\r\n        mac_address = (\r\n         ':'.join(s.encode('hex')\r\n         for s in binascii.hexlify(ethernet_detailed[1]).decode('hex')))\r\n         if mac_address in mac_dict:\r\n             mac_dict[mac_address] += 1\r\n         else:\r\n             mac_dict[mac_address] = 1\r\n \r\n        if mac_dict[mac_address] &lt; 5:\r\n            print \"Source MAC: \", mac_address, mac_dict[mac_address]<\/pre>\n<p>Run the test program with the following command:<\/p>\n<pre>sudo python\u00a0sniff_test.py<\/pre>\n<p>and you should see a list of mac addresses from devices on your network. Wait a while to hoover up non-dash packets then press the button, and look for a different mac address. You may see double entries for the dash, but don&#8217;t worry as this will be handled by our existing software debounce routine.<\/p>\n<p>Once we have discovered the mac address we need to add it to the existing impulse configuration.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-617\" src=\"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-content\/uploads\/2017\/07\/DualImpulse-300x252.png\" alt=\"\" width=\"300\" height=\"252\" srcset=\"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-content\/uploads\/2017\/07\/DualImpulse-300x252.png 300w, https:\/\/test.warrensoft.co.uk\/wp-test\/wp-content\/uploads\/2017\/07\/DualImpulse.png 490w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>The sniffing is performed by a separate thread in the hub main program. Download the\u00a0new main_sched py file:<\/p>\n<pre>wget -O \/usr\/local\/bin\/code\/controller\/main_sched.py http:\/\/www.warrensoft.co.uk\/home-hub\/code\/controller\/dash\/main_sched.py<\/pre>\n<p>and a revised impulse processor:<\/p>\n<pre>wget -O \/usr\/local\/bin\/code\/controller\/impulses.py http:\/\/www.warrensoft.co.uk\/home-hub\/code\/controller\/dash\/impulses.py<\/pre>\n<p>and restart the controller to use the modified files.<\/p>\n<p>Now you should be able to enjoy remote control for any of the devices in your hub.<\/p>\n<p>In the next post I will look at backing up the hub database.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Amazon Dash is a self-contained WiFi enabled remote control button, available to Amazon Prime members, that we can interface with our home hub as an Impulse button. \u00a0The advantage is that we don&#8217;t require physical wiring or additional electronics &#8211; we just\u00a0sniff the network looking for the signature mac address of the button. The &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/test.warrensoft.co.uk\/wp-test\/2017\/07\/11\/controller-amazon-dash-button\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Controller &#8211; Amazon Dash Button&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-605","post","type-post","status-publish","format-standard","hentry","category-hub-software"],"_links":{"self":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/605","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/comments?post=605"}],"version-history":[{"count":16,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/605\/revisions"}],"predecessor-version":[{"id":704,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/605\/revisions\/704"}],"wp:attachment":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/media?parent=605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/categories?post=605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/tags?post=605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}