Shop OBEX P1 Docs P2 Docs Learn Events
Web Clicker: Internet Remote Control — Parallax Forums

Web Clicker: Internet Remote Control

Nick McClickNick McClick Posts: 1,003
edited 2011-01-20 19:31 in Robotics
The Web Clicker is a web server & IR transceiver based on a Propeller Platform USB and E-Net Module. You can record any IR command and play it back via an AJAX web interface or just by requesting a URL. It works great from a cell phone and it's especially handy for home automation projects. Here's a little demo;
4970922095_b4b075eb52.jpg

FAQ
What can I do with it?
The Web Clicker can control any IR device (TV, DVD, Stereo, etc) simply by requesting a URL. There's also an AJAX based control page so you can use it with a web browser, like on your iPhone or computer.

The Web Clicker is awesome for home automation projects because of it's ease of implementation - just request a URL and you'll generate an IR signal or trigger a series of IR signals

Why?
I built the web clicker mostly for home automation - I have a MythTV DVR that uses an RF remote. Now, I've set it up so when I push the power button on the remote, the DVR makes a page request to the Web Clicker and it generates the correct IR signal.

How?
The Web Clicker is a Propeller Platform USB and E-Net Module, and a very basic IR circuit. Web server code is based on PropTCP, by Harrison Pham, and I wrote a custom object (Magic IR) for capturing and playing back IR signals.

I started researching IR control schemes - after a few days of work, I decided it would be better to code my own IR recorder - this way it's compatible with any TV without having to look through a huge code list. It's like a learning remote that has greater than 100ns accuracy & unlimited storage capacity.

I'm using a 38kHz IR receiver, which is the most common (95% of devices). If your devices uses another frequency, it's easy to use a different IR receiver.

All the software & hardware is available under the MIT license, which is essentially public domain.

Using it
I'll get into using it in a bit, but here's the big picture;
  1. Enter the webserver address into your browser
  2. Hit 'Record' to capture IR commands
  3. Initiate playback either by:

The Circuit
The schematic for the Propeller Platform USB is here (pdf), and the E-net module schematic is here (pdf).

In addition to the E-Net and Propeller Platform, you'll also need to build a simple IR transmit / receive circuit. Here it is;
4946056641_d2f838cc27_o.png

I'm using the wrong symbol for an IR receiver, but it's the device at U1. Hopefully it doesn't look too complicated - you just hook the long lead of the LED to P11, the short leg to ground. Hook up the first pin of the IR receiver (the pin on the left when the dome is facing up) to P12, the middle pin to ground, and the 3rd pin to V33. Here the circuit is on a ProtoPlus.
4948901812_8381fe8b1d.jpg

The Software
Grab the code
Download all the code here, copy to your desktop and unzip it.

Edit the settings
The webserver IP stuff needs to be set up. First, download the Propeller Tool, then open up Top_object.spin. Towards the beginning, you'll see where the IP settings are;
4948459739_b68a2e3a51.jpg
Change them if necessary, connect the Propeller Platform USB, save the file and hit F11 to program the Propeller Platform.
  • mac_addr doesn't really matter, you should be able to keep it as is
  • ip_addr The Web Clicker doesn't use DHCP, just pick an IP address on your local network that isn't being used.
  • IP_subnet probably 255.255.255.0. If that doesn't work, take a look at your PC and see what the subnet setting is - use the same setting on the Web Clicker
  • ip_gateway IP address of your router
  • ip_dns IP address of your router
That's it! Your Web Clicker is ready to go. Now, just connect to your network.

Home Automation-ing
In your web browser, type in the IP address you set in the previous step. You'll get this web interface;
4949048192_c747234863.jpg

Code Capture
Here's how it works; Type a code name (maybe 'Power', or 'Vol+', or whatever makes sense) in the box, then click on the 'Start Recording' button. put your IR remote up to the IR receiver and push the button. The command will be stored and the command list will dynamically be updated. To play that code via the web interface just click on the 'Play Code' link next to the command name. To clear the commands, click on the 'Clear Commands' link.

Scripting
Once the command has been recorded, you can easily script it. In Linux / Mac, you just need to make a page request to the web clicker to send the IR;
wget 192.168.1.252/exec.cgi?0- >> /dev/null 2>&1
Will execute the first command on the list (Power on my Web Clicker)
wget 192.168.1.252/exec.cgi?1- >> /dev/null 2>&1

Will execute the second command, and so on. Change the number after the ? in the url to execute a different command. The >> /dev/null 2>&1 redirects the program output (and any error codes) to the trash - this is for non-interactive scripting.

If you're using curl, the command is almost the same;
curl --url 192.168.1.252/exec.cgi?1- >> /dev/null 2>&1
You could associate this command with a LIRC input, a chron job, or whatever else. I don't know how to script in windows, but you can download wget for Windows & that's probably the first step.

Next Steps
Once your Web Clicker is up and running, you'll probably want to tweak it / play with it! Here are a few ideas to get you started;

Local File Storage
The Propeller Platform USB has a microSD / microSDHC card slot so you can add up to 32GB of local file storage. You could serve MP3's, pictures or whatever else. You could also use the SD card for data logging. To start playing with the SD card, grab the fsrw object.

Multiple IR transmissions with a single command
Take a look at the source code - towards the top, there's a section of 'Elseif', which tell the Web Clicker what to do when a command request is received. You can make the device do anything in response to a command, including sending several IR blasts.

Controlling a motor, switch, light, or anything else
Why not use the Web Clicker to turn on a motor, change a light, play back a wav file or something else? It's the same process as adding multiple IR transmissions - look at the code with the Elseif commands - instead of playcommand(x), change it to your newly created method.

That's it!

Development Notes
I learned a lot about the Propeller & PASM doing this project, I thought I'd share my experiences developing it;

Firmware: IR Transmit / Receive
I started by grabbing a few objects from the Propeller Object Exchange that were created for IR receive / transmit. I quickly ran into a problem: my downstairs TV is a JVC, and my upstairs TV is a Sharp. Neither used the RC5 remote control format or the SIRCS format. After extended google-ing, I found some documentation on JVC's format;
web_remote_bg1.jpg
(from Davshomepage)

This looked easy enough, although you need to invert it because the IR receiver goes low when it senses an IR signal. I implemented a basic signal recorder in SPIN: It would wait until the signal went low, then test each 'cell', recording the bit value. I ran into some problems with this approach — I'm pretty sure SPIN is too slow to catch all the transitions (I would put it in a loop, wait for a transition, then do a few tests on the transition length & how many transitions had been received), and playing back the code wouldn't activate the TV. Another problem was the repeat portion of the code. It would broadcast the whole code once, then wait 30-40ms and re-broadcast a portion of the code.

I knew it was time to switch to assembly, but on reflection, I decided to implement something more generic. I wanted to be able to control multiple devices without understanding their (possibly undocumented) signal format. I built a generic capture object in Propeller Assembly.
web_remote_bg2.png

Click on the link above to see the full code with documentation. It is built to wait until the IR pin goes low, start a timer and note every transition time into a series of longs (32-bit values). I've uploaded the object to the Object Exchange for others to use. Development took a while, but using ViewPort helped a lot. It also was useful using my camera to see when the IR LED was firing. Because the playback loop only requires a few instructions, that was done in SPIN and should be fast enough for nearly all IR codes.

This worked to record IR commands and play them back. Now the webserver.

Firmware: Webserver
I started with PropTCP by Harrison Pham. His code is easy to use. I started with his AJAX server demo and modified it until I could get an LED to blink. Once I figured out how to get any arbitrary command running from a CGI request, I was ready to go. I implemented a few methods;
  • storecommand, start a new cog and record the code received
  • sendcode, transmit an IR command stored at a specific location
  • showcodes, generate HTML displaying currently stored commands
  • clearcommand, clear all the currently stored commands
For ease of coding, I designed it so when the browser requests exec.cgi, it will execute the IR command in the URL string. /exec.cgi?1- would execute the first stored command, the - (minus) served as the end of line character. This also makes it easy to script IR commands on a PC. Just request exec.cgi?x- and that command will run. Requesting stor.cgi started the storecommand method. And showcodes ran when the browser requested stor.cgi. That HTML is updated asynchronously (ajax).

Also, PropTCP takes about 16kB, leaving you with 16kB left for your program. This is a pretty large memory requirement, but you can get around that (somewhat) by using the SD card to store codes, files, etc.

Firmware: HTML & Javascript
The HTML & Javascript are built into the firmware, although they coudl also be stored on an SD card. The starting point for the code was Harrison's demo, that got me started and I changed the code to fit my needs. On the Propeller, characters are stored in bytes — each byte stores 1 character. Text strings are zero-terminated, that's why you see a 'byte 0' at the end of each set of lines. To use a set of lines, you refer to the address where the text is stored. sock[1].str(@ajax) will return the text stored starting at label 'ajax' all they way until it reaches a zero byte.

The Javascript consists of 3 functions;
  • dupdate, runs onload and updates every 500ms running the ajax function,
  • ajax, updates the listing of stored commands,
  • newcomm, stores a new command
Each of those functions makes a page request, and the webserver watches for the page request, executing a command based on it.

The HTML is pretty basic. Again, it's stored as a text string, just like the Javascript and it displays the result of the javascript and a basic UI. There's plenty of room to pretty things up, but the UI is functional.

Comments

  • eod_punkeod_punk Posts: 146
    edited 2010-09-09 05:13
    Very cool Nick, makes me want to work some more on my IR project. What kind of range are you getting out of your IR LED? I opted for using an IR bug for my project and those might go an inch or so.
  • Nick McClickNick McClick Posts: 1,003
    edited 2010-09-09 08:52
    One thing I like about the dumb approach is that it reduces the complexity of IR. It does take more memory & time to setup, though.

    I get a few feet of range from the IR LED - it's just a narrow beam - it has to be pointed at the device. You can get different IR LED's with different widths.
  • Nick McClickNick McClick Posts: 1,003
    edited 2010-09-13 10:06
    Here's a second demo video.

    Also, the Web Clicker was up on Lifehacker & Hackaday!
  • KaosKiddKaosKidd Posts: 296
    edited 2010-10-25 08:33
    Nick;
    This is an awesome project! And thanks for sharing!

    KK
    (Fred)
  • Coder96Coder96 Posts: 42
    edited 2010-10-25 10:23
    If you wanted to save space on the prop. You could set it up so the controlling device sends the IR codes to the prop.
  • alelogmanalelogman Posts: 1
    edited 2010-11-06 01:01
    Hi Nick McClick,
    Thanks for sharing the info on the project. It's amazing, some people got lot of dnb
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2010-11-06 13:30
    WOW before viewing your program I had no idea where to start on ethernet programming. Now I am able to modify your code for my own programs. I've also now added you to my list of Propeller-legends. :-)

    Thanks a lot!!
  • mahuromahuro Posts: 8
    edited 2010-11-23 06:15
    Hi Nick

    Great work I am looking round the forums for NET proggraming and maybe you'll be able to make a suggestion ?

    I am new to the Parallax and spin ... I can see from reading around the posts that web access is feasible from the Parallax chip ... Can anyone with experience on this let me know if the following idea is possible, please ????:

    Can the parallax, contact a FLASH server ( HTTP server broadcasting flash animations), download the some clips and stream to an attached LCD display ??? is that feasible ?? I need it for a project at Uni ... and if its possible I'll buy the chip and tools ..( just don't want to spend my money if there is no chance !!!)

    You think the Web clicker could be reversed so the Paralleax with an Ethernet shield could inquire a flash server and then stream a video clip from the server ??

    Many thanks !!

    Mahuro.
  • lardomlardom Posts: 1,659
    edited 2010-12-24 15:22
    Nick McClick! I have to subscribe to this one. Internet control has been on my mind. Thanks.
  • Nick McClickNick McClick Posts: 1,003
    edited 2010-12-29 01:45
    @mahuro - I didn't get far on the request side - I tried following Harrison's Telnet client examples, but it didn't work for me.

    However, if Harrison could do it with his telnet client, it is possible. Grabbing a file and streaming it to an LCD is a different story - that can get complicated.
  • CalegariCalegari Posts: 1
    edited 2011-01-20 19:31
    Hi, i just assembled this project and works pretty good.

    I only have one problem, when i power off the webclicker all the recorded commands are lost, in order to make it save and do not lose the commands, what do i need to do? Save everything within the microSD?
    How can i do that? I know that i need the fsrw obj, but im kinda lost, any tips?

    Thanks!
Sign In or Register to comment.