Skip to content

Instantly share code, notes, and snippets.

@kellbot
Created April 22, 2016 18:38
Show Gist options
  • Save kellbot/1dcd1ad8a7ec04148d38c18275a55bb8 to your computer and use it in GitHub Desktop.
Save kellbot/1dcd1ad8a7ec04148d38c18275a55bb8 to your computer and use it in GitHub Desktop.
from scapy.all import *
from lifxlan import *
import sys
from copy import copy
from time import sleep, time
#find all our lights
lifx = LifxLAN()
bulbs = lifx.get_lights()
#Find the bulb we want
for bulb in bulbs:
if bulb.mac_addr == 'your:bulb:mac:address:here':
target_bulb = bulb
#detect ARP packet from button
def arp_display(pkt):
if pkt[ARP].op == 1: #who-has (request)
if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
if pkt[ARP].hwsrc == 'your:button:mac:address:here': # Huggies
breathe_light(target_bulb)
print "Pushed Huggies"
else:
print "ARP Probe from unknown device: " + pkt[ARP].hwsrc
#fade the bulb in and out
def breathe_light(bulb):
half_period_ms = 1500
duration_secs = 30
print("Breathing...")
#turn the bulb on
bulb.set_power(1)
try:
start_time = time()
while True:
cyan = [29814, 65535, 65535, 3500]
half_bright = int(cyan[2]/2)
dim_cyan = [29814, 65535, half_bright, 3500]
bulb.set_color(cyan, half_period_ms, rapid=True)
sleep(half_period_ms/1000.0)
bulb.set_color(dim_cyan, half_period_ms, rapid=True)
sleep(half_period_ms/1000.0)
if time() - start_time > duration_secs:
raise KeyboardInterrupt
except KeyboardInterrupt:
print("Leaving bulb on")
bulb.set_color( [29814, 65535, 65535, 3500])
print sniff(prn=arp_display, filter="arp", store=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment