After acquiring and repairing a "new" TV - sans remote control - I decided to improve my A/V setup with some custom automation, a-la-ESP8266 hosting a webserver to provide a phone-based remote control.
I spent some time researching IR protocols - how they work, differences between brands, etc - and decided that this should be quite possible. For those curious, IR for remote controls is usually modulated in the 30-50khz range with a 30% or so duty cycle. Unfortunately, the software PWM implementation available to me on the ESP-01 module can only reach 1Khz, which is not even close to sufficient. With rather limited GPIO options - and a desire to avoid external hardware as much as possible - I started exploring.
My devices - an odd hodgepodge of whatever was cheap - include Sony, LG, and Apple components (OK, maybe not so much 'cheap' on the last one, but you get the point). These have IR modulations of 38Khz, 38.2Khz, and 40Khz respectively. Though lacking a sufficiently-powerful PWM, the ESP-01 module DOES have a UART that can operate pretty quickly....
After running some numbers, I determined that I could configure the UART in 7N1 mode - that is 7 data bits, no parity, and 1 stop bit. There's also a start bit, so each data frame looks something like this: 0xxxxxxx1 - I fill in the seven "x"s with whatever I want - for my purposes, I chose 0x24, so my full frame looks like: 001001001 - if I transmit this at a baud rate of 114667, I get a pin modulating in a pretty-darn-passable impersonation of a 38.2Khz 30% PWM signal. If I change the baud to 120K, I've got a pretty good 40Khz signal, too.
The hardware is pretty straightforward: The ESP-01 module itself, a cannibalized USB power-only cable from who-knows-what, a 3.3V linear regulator so as to not fry my ESP module, 3 IR LEDs (one for each device I want to control) with a current-limiting resistor, and a MOSFET for switching them on and off (along with a gate resistor, just for safety - though depending on the hardware behind the UART, which I haven't bothered looking up, that may or may not be necessary).
The software is less straightforward: once embedded, I really don't want to have to take it out in order to change something if I get a different blu-ray player, or want it to control another device. I've never actually developed on an ESP8266 before, despite owning several and reading a number of projects. I'll just check to se--- yep, there's a library for OTA updates. Great. OK, well, I want the buttons to work just like a remote: press it to start sending the signal, hold it down and the signal should repeat. That kind of prohibits a simplistic approach of just using links with GET parameters embedded, may some sort of AJAX or websocke-- yep, there's a websockets library. OK. What's this about inlining all the HTML to output? That's kind of a nightmare, isn't it? What if I could use some sort of filesy- oh, SPIFFS. Neat. I don't want to deal with assigning a static IP to the ESP, can I -- Oh, mDNS. Wait, is there a library for friggin' everything? Apparently.
The actual software development was a little bit annoying - I had to research the codes my remote(s) would send so I could simulate them all, and understand the protocols: my appleTV, though using the same modulation scheme as NEC encoding, doesn't follow the whole spec - it does whatever it wants, pretty arbitrarily, with the bits. The LG tv is pretty good: follows spec AND publishes its remote codes in the manual! Very nice. Sony, of course, had to roll their own scheme entirely - but it's not too bad to implement. There are libraries for remote controls, but given how I want mine to function I think it'll just be easier to write my own. The general operation looks something like this:
The initial HTTP request on the ESP redirects...
Read more »