From 29eed7f924d0998dd3e486d581bd493df82048f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Thu, 27 Dec 2018 21:23:59 +0100 Subject: [PATCH 1/2] --- amazon_yeelight.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 amazon_yeelight.py diff --git a/amazon_yeelight.py b/amazon_yeelight.py new file mode 100644 index 0000000..7c130cd --- /dev/null +++ b/amazon_yeelight.py @@ -0,0 +1,21 @@ +from scapy.all import * +from yeelight import Bulb + +MAC_ADDRESS = 'ac:63:be:52:8b:4a' # enter Dash Button's MAC Address here. + +on = False +b = Bulb('192.168.2.240') + +def detect_button(pkt): + print(pkt[Ether].src) + if pkt.haslayer(DHCP) and pkt[Ether].src == MAC_ADDRESS: + global on + print("Button Press Detected") + if on: + b.turn_off() + else: + b.turn_on() + on = on ^ True + #Do stuff + +sniff(prn=detect_button, filter="(udp and (port 67 or 68))", store=0) From eaad409a8a963969e4ce44156be36fac31972622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Thu, 27 Dec 2018 21:44:07 +0100 Subject: [PATCH 2/2] Simplify toggle --- amazon_yeelight.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) mode change 100644 => 100755 amazon_yeelight.py diff --git a/amazon_yeelight.py b/amazon_yeelight.py old mode 100644 new mode 100755 index 7c130cd..119d7a1 --- a/amazon_yeelight.py +++ b/amazon_yeelight.py @@ -1,9 +1,9 @@ +#!/bin/env python from scapy.all import * from yeelight import Bulb MAC_ADDRESS = 'ac:63:be:52:8b:4a' # enter Dash Button's MAC Address here. -on = False b = Bulb('192.168.2.240') def detect_button(pkt): @@ -11,11 +11,6 @@ def detect_button(pkt): if pkt.haslayer(DHCP) and pkt[Ether].src == MAC_ADDRESS: global on print("Button Press Detected") - if on: - b.turn_off() - else: - b.turn_on() - on = on ^ True - #Do stuff + b.toggle() sniff(prn=detect_button, filter="(udp and (port 67 or 68))", store=0)