Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions decode_os433.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

from gnuradio import gr
import gr_queue
from gnuradio import blks2
from gnuradio.analog.am_demod import am_demod_cf
from gnuradio.filter.rational_resampler import rational_resampler_fff
from gnuradio.filter import firdes
from gnuradio.filter import freq_xlating_fir_filter_ccc
from gnuradio.blocks import message_sink
from gnuradio import audio
from gnuradio.gr import firdes
import osmosdr

# Sensors transmit on 433.9MHz
Expand All @@ -30,7 +33,7 @@ class rtlsdr_am_stream(gr.top_block):
Optionally plays the audio out the speaker.
"""

def __init__(self, center_freq, offset_freq, decimate_am=1, play_audio=False):
def __init__(self, center_freq, offset_freq, decimate_am=1, play_audio=False, source=""):
"""Configure the RTL-SDR and GNU Radio"""
super(rtlsdr_am_stream, self).__init__()

Expand All @@ -39,20 +42,20 @@ def __init__(self, center_freq, offset_freq, decimate_am=1, play_audio=False):
output_rate = audio_rate / float(decimate_am)
self.rate = output_rate

self.osmosdr_source = osmosdr.source_c("")
self.osmosdr_source = osmosdr.source(source)
self.osmosdr_source.set_center_freq(freq)
self.osmosdr_source.set_sample_rate(device_rate)

taps = firdes.low_pass(1, device_rate, 40000, 5000, firdes.WIN_HAMMING, 6.76)
self.freq_filter = gr.freq_xlating_fir_filter_ccc(25, taps, -freq_offs, device_rate)
self.freq_filter = freq_xlating_fir_filter_ccc(25, taps, -freq_offs, device_rate)

self.am_demod = blks2.am_demod_cf(
self.am_demod = am_demod_cf(
channel_rate=audio_rate,
audio_decim=1,
audio_pass=5000,
audio_stop=5500,
)
self.resampler = blks2.rational_resampler_fff(
self.resampler = rational_resampler_fff(
interpolation=1,
decimation=decimate_am,
)
Expand Down Expand Up @@ -210,14 +213,17 @@ def hex(self):
metavar='NAME', help='Log readings to <NAME><CHANNEL>.csv')
parser.add_option('-a', '--audio', action='store_true', dest='audio',
help="Play AM-demodulated signal to the speakers")
parser.add_option('-s', '--source', type='string', dest='source',
help="SDR Source to use")
(options, args) = parser.parse_args(sys.argv[1:])

logfiles = {}
if options.log:
for channel in range(1, 3+1):
logfiles[channel] = open("{0}{1}.csv".format(options.log, channel), 'at')

stream = rtlsdr_am_stream(freq, freq_offs, decimate_am=2, play_audio=options.audio)
source = options.source if options.source else ""
stream = rtlsdr_am_stream(freq, freq_offs, decimate_am=2, play_audio=options.audio, source=source)
stream.start()
unit = 'F'
for packet in decode_osv1(stream):
Expand Down
3 changes: 2 additions & 1 deletion gr_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


from gnuradio import gr
from gnuradio.blocks import message_sink as gr_message_sink
import gnuradio.gr.gr_threading as _threading
import numpy

Expand Down Expand Up @@ -77,7 +78,7 @@ def __init__(self, vlen=1):
)
#create message sink
self._msgq = gr.msg_queue(4)
message_sink = gr.message_sink(self._item_size*self._vlen, self._msgq, False) #False -> blocking
message_sink = gr_message_sink(self._item_size*self._vlen, self._msgq, False) #False -> blocking
#connect
self.connect(self, message_sink)

Expand Down