iPhone Remote Control - For my Christmas lights
Last weekend I was digging through the attic to get Christmas lights. It was time to start fixing the ones that are not working anymore. In the container of lights I have these boxes that plug into the wall and allow me to turn the lights on and off with a remote control. On the outside of the box it says “Plug-N-Power”. I think I bought them over 20 years ago.
Plug-N-Power is still around today. You might know it as X-10. After all of these years they use the same protocol that works over your house wiring.
I always get a chuckle when I look at those boxes because I can remember when I built a circuit from a Radio Electronics magazine. It was supposed to send Plug-N-Power signals over house wiring from a Commodore 64. I wanted to build it so I could create a program on my Commodore to control my parents Christmas lights.
It was a dicey circuit since it was mixing 110 AC with the “user port” of the Commodore. I started working on it - I think around October of - hmm I think it was 1989. It took me until right before Thanksgiving to finish it. I was in a hurry, and I was busy with school at the time too. The production quality of the hardware…well…lets say it was pretty bad - and I knew it.
I had this rule with any 110 circuit I built. I would use a long extension cord, and hide inside the house - flip a switch to turn it on. That way if something went really bad, I was protected from shrapnel if the thing blew up.
Good thing I did it this time. I rolled out the extension cord, and plugged everything in (With the switch off of course). Got inside the house, and got my older brother in the room so he could watch too. I was hoping that when I flipped the switch nothing would happen.
I was wrong - flipped the switch and a huge arc came out of the circuit board, and then a giant bang….a ring of smoke went up into the air. My brother and I couldn’t stop laughing. When I looked at the board, half of the board was missing. I found resistors, capacitors all over the driveway in pieces.
Even though I was laughing I was too scared to try again. I figured if I was able to to get the thing working I would be afraid to leave it running in my parents house.
Back to today. I have been thinking hard about how the iPhone fits into our product line, and possibly creating some remote administration apps for it. Not because I like the iPhone, but we have actually received quite a few emails requesting different types of remote admin iPhone apps.
When I learn a new platform or language I like to come up with a fun project that is quick to build, but helps me learn the concepts required. I started thinking…hmm…I wonder what type of Plug-N-Power stuff is out there now…wonder how hard would it be to get my iPhone to send signals to them - and control my Christmas lights with it.
I did my research, and I came up with a plan. For it to work I would need to build three things:
1. A PHP script that would work with MySQL to keep track of the Christmas lights (Like Tree, Santa out Front, etc), and their status (On or Off).
2. A computer that would send the signals to the X 10 devices by polling PHP script on a web server, and take action on the XML generated by the php script.
3. An iPhone application that would send data to the PHP application, and be able to render the light descriptions, and allow me to change status by clicking an on or off button.
(The A-Team theme song was going off in my head at the time…and I could hear Hannibal saying, “I love it when a plan comes together”)
The first part was easy. PHP is a breeze to use, and I was able to put something together in an hour.
The second part was a little more difficult. I found that to do this I needed something called “FireCracker” from X10. It cost me $39, and came with a remote control, and another lamp module - a pretty good deal. Here is what it looks like:
Along with the lamp module, wireless receiver, and my iPhone:
The FireCracker device plugs into your serial port. It in turn sends wireless signals to an X10 wireless receiver (Included in the $39 deal) that plugs into the wall…and it actually sends the signals to the X10 device. A side note here - Notice how they are not allowing 110AC to come near the computer!?! Smart idea!
Normally you use an X10 App to control your devices and lights, but I wanted to control this with my own code. After searching I found a free API that let me turn a light on or off using a simple C++ call. After a few hours of coding I had an application that would poll my webserver. The webserver in turn would return an XML feed generated by my PHP script, and then finally my C++ app would turn a light on or off based on what was in the XML feed. After a few tries I got it to work. I did some testing by manually updating the database on the webserver…lights on….lights off…beautiful!
Now to the tough part. Writing the app on the iPhone. I had never written anything for the Mac or the iPhone. I have peeked at Cocoa (The main language used to develop for the iPhone & Mac)…and it is a very strange looking language. I went to the bookstore and got every book I could find on it. After a few days of reading and experimenting I was ready to write my app. I hated Cocoa at first, but after I was finished I was jealous that I couldn’t use this beautiful dev environment to create windows apps.
About 2 days later I had a fairly functional application. A couple more days and I had it nice and polished with an icon and all.
Here is the icon on my home screen of my iPhone (It is the blue Christmas light..sorry for the bad shots)
Once you click on the blue Christmas light, it hits a webserver that pulls down XML and fills out a list of lights to control:
I have my wreath on the door, the garland on the stairs, Santa out front…and our tree on the list. To turn one of them on or off, you simply make your selection:
As you can see my tree is turned off. I press the button, and boom
And now the tree is lit.
Pictures can’t show it all…so I took a video too:
There is some delay between the time I turn off the lights, but that is because I am polling every 15 seconds. If I spent more time on it I could create a solution that was almost instant.
Now I will have something really cool to talk about at Thanksgiving dinner.
Popularity: 1%
Written by intelliadmin. Read more great feeds at is source WEBSITE
no comments.
Read more articles on christmas and otherSoftware and iPhone.
- [+] Digg: Feature this article
- [+] Del.icio.us: Bookmark this article
- [+] Furl: Bookmark this article




















