Skip to content

Instantly share code, notes, and snippets.

@kylekyle
Last active May 7, 2018 12:46
Show Gist options
  • Save kylekyle/d8507538a6ad4f961b20d572f50500bb to your computer and use it in GitHub Desktop.
Save kylekyle/d8507538a6ad4f961b20d572f50500bb to your computer and use it in GitHub Desktop.
A minimal rfcat replay script for a garage door opener
#!/usr/bin/python
import rflib
import bitstring
rfcat = rflib.RfCat()
rfcat.setFreq(314850000)
# AM On/Off Keying
rfcat.setMdmModulation(rflib.MOD_ASK_OOK)
# in audacity, out biggest pulse is about
# 20 samples wide in a 440000 Hz wavefile
pulse_width = 20.0
sample_rate = 44000.0
# set the baudrate
rfcat.setMdmDRate(1.0/(pulse_width/sample_rate))
# easier to just use ASCII for now, then convert to bytes later
data = '01010101010101011100000000000000'
clocked_data = ''.join(['1110' if b == '1' else '1000' for b in data])
# there is a preamble before the data
clock_data_with_preamble = '00000000%s' % clocked_data
# convert our binary ASCII string to bytes
packet = bitstring.BitArray(bin=clock_data_with_preamble).tobytes()
# not actually sure why the repeat parameter is necessary ...
rfcat.RFxmit(packet, repeat=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment