Sunday, February 27, 2022

Controlling remote control blinds with a RaspberryPi (Draft)

I recently installed electric blinds in my house because there were certain windows that were difficult to reach. The blinds came with a remote, but I wanted to take them a step further and make them wifi enabled. It would have been somewhat simple to attach an ESP32 to the circuitry inside the blinds. But I figured it would be less invasive, and more reasonable to create a wifi connected remote

The back of the remote says that it communicates at 433.92 MHz, which is a really common frequency for lowpower/bandwidth signals. I also happened to have a few serial transmitters that operate at this frequency, and figured I might be able to use one of these. 

TODO: Example of 433.92 transmitter

The first step in this project was to figure out the modulation, and protocol used by these blinds. For this, I bought myself a software defined radio USB device (amazon). With this device, I can specify a frequency, and sniff the exact signal being sent by the remote. Universal Radio Hacker is a simple to use, but useful tool that interfaced with the SDR. This is what I got:

TODO: Image of remote signal

I realized looking at this signal, that the remote uses OOK modulation. Which is exactly what the transmitters I had used. I knew then I could make this work with  what I had on hand.

Once I had this signal captured, I was able to measure the on/off time for high and low values.  It also appeared as though the remote would repeat the same pattern 6 times, and each repeat would start with a long high then low value. I wrote some code in C# that ran on a raspberry pi to duplicate this exact signal, using the SDR to debug any differences or inconsistencies. After a few adjustments, I ran my code and the blinds responded! I was so excited I had proven this will work.

The first iteration of the code would step the blinds down once per second. Oddly enough, the blinds only seemed to respond every couple seconds, but I was definitely transmitting. After further investigation, I discovered the problem. RaspberryPis do not use a real time operating system, meaning processes that are running will be preempted by the OS, and paused to allow other processes a slice of time. The code I wrote was very basically bit banging the GPIO pin connected to the transmitter. Which meant every few milliseconds the process doing the transmission would pause. This totally threw off the timing of the transmitted signal, causing the blinds not to recognize the command. Every so often the process would get lucky and transmit a full signal. But it was uncommon. There are a few ways I could have prevented the OS from preempting my process (configuring one core to only run my process, writing a kernel driver, installing an RTOS on the raspberrypi). But all of these were somewhat complicated to implement, and would negatively impact the usefulness of my raspberrypi. I ported my code to C++ running on an ESP32, and it started to work perfectly.

To reverse engineer the protocol, I captured multiple commands sent by the remote. The blinds have 5 channels, and 5 commands (up, down, open, close, stop). Comparing each of these signals, it was easy to determine which bits were the channel, and which were the command. The signal also included a CRC for each of these values. 

I was able to get each of these commands/channels working. I connected the ESP32 to homeassistant, and now I am able to open and close all the electric blinds from my phone!  C++ implenetation of the protocol

 

1 comment:

  1. Here's a state-by-state examination of the place the country stands on sports playing, as of September 2022. And remember, if you stay in a state the place sports playing is authorized, a glance at|try} SportsLine for professional predictions. The poker bonus is unlocked at a rate of $1 for 바카라사이트 each 30 Ignition Miles earned, that are garnered when exiting a poker cash sport or ending a poker event. The wagering requirement is a 40x rollover, and the minimal deposit required to set off the deposit bonus is $45. Slots Empire treats you like royalty with a 220% match bonus in your first deposit on the on line casino. If you make your first deposit by way of NeoSurf, Crypto, or Flexepin, you get an extra 20%.

    ReplyDelete