Controlling LIFX without Internet
My latest project has involved controlling LIFX bulbs at a location without Internet service. Since LIFX bulbs don’t support “ad hoc mode”, my approach was to use a Raspberry Pi to serve as an access point, creating an “infrastructure mode” network. It just so happens that this network’s uplink port will be permanently down!
I started out by following this tutorial to turn the Pi into an access point. Everything went well, except for getting hostapd to run at startup. I “solved” this problem in a hackish way by creating a file /etc/cron.d/wifi with the following entry:
@reboot   root    service hostapd start >> /var/log/wifiThat certainly isn’t the right way to do it, but it works!
With that fixed, everything was working great, as long as Ethernet was connected. However, if I booted the Pi with the Ethernet cable unplugged, the Wifi network no longer worked! I spotted this in the syslog:
Sep  1 00:52:17 raspberrypi dhcpd: No subnet declaration for wlan0 (169.254.141.200).
Sep  1 00:52:17 raspberrypi dhcpd: ** Ignoring requests on wlan0.  If this is not what
Sep  1 00:52:17 raspberrypi dhcpd:    you want, please write a subnet declaration
Sep  1 00:52:17 raspberrypi dhcpd:    in your dhcpd.conf file for the network segment
Sep  1 00:52:17 raspberrypi dhcpd:    to which interface wlan0 is attached. **
Sep  1 00:52:17 raspberrypi dhcpd:
Sep  1 00:52:17 raspberrypi dhcpd:
Sep  1 00:52:17 raspberrypi dhcpd: Not configured to listen on any interfaces!Ugh! What was going on? A bit earlier in the log, I found this:
Sep  1 00:48:53 raspberrypi dhcpcd[2504]: wlan0: using IPv4LL address 169.254.141.200
Sep  1 00:48:53 raspberrypi dhcpcd[2504]: wlan0: adding route to 169.254.0.0/16This was being done by the DHCP client daemon, which I didn’t need, since I only needed the Pi to be a DHCP server, not a client. So, I fixed the problem with:
sudo update-rc.d dhcpcd disableand then everything worked great!
To actually control the LIFX bulbs, I’m using the Haskell library and command-line program that I’m currently writing. Installing Haskell on the Pi was easy; just sudo apt-get install haskell-platform. However, it turns out that I made a bit of a mistake by using Raspbian Wheezy instead of Raspbian Jessie. Wheezy has a version of ghc which doesn’t support ghci, and therefore doesn’t support Template Haskell. This somewhat limited the selection of packages from Hackage that I could use in my Haskell LIFX library. So, for the moment, I cut out the offending packages, although I think the long-term solution is to upgrade to Jessie.
I then used crontab -e to install the following in the pi user’s crontab:
15 17 * * * /home/pi/src/lifx/dist/build/lifx/lifx on -i 0225cd
20 6 * * * /home/pi/src/lifx/dist/build/lifx/lifx off -i 0225cd
47 19 * * * /home/pi/src/lifx/dist/build/lifx/lifx on -i 02b95f
11 23 * * * /home/pi/src/lifx/dist/build/lifx/lifx off -i 02b95fThere! I can now automate my LIFX bulbs without needing “the cloud.” The only finishing touch was to add a RasClock realtime clock to the Pi, so that it could maintain the current time without access to NTP.