I am trying to figure out how I control a Software Defined Radio over a network, and stream the received baseband samples from my remote hardware back to the gnuradio.

What I'm trying to do here is, this Python code should be able to output a user selectable waveform which can be a CW tone, Broadband Noise, or an arbitrary waveform read from a file containing I/Q values.

So I searched on the internet and the closest thing that I found was the BorIP and unfortunately couldn't get it set-up on my machine because the instructions I found were not helpful (at least for a beginner like me).

I created the Python web server using this script (which I found online):

    import http.server
import socketserver

PORT = 8080
Handler = http.server.SimpleHTTPRequestHandler

with socketserver.TCPServer(("", PORT), Handler) as httpd:
    print("serving at port", PORT)

But didn't know how to merge the generated gnuradio python code into the Python web server.

  • $\begingroup$ Very helpful, thank you! Works well for me. $\endgroup$
    – user20933
    Oct 27, 2021 at 10:06

1 Answer 1


GNU Radio Companion (GRC) generates Python code that is something like this (not exact text). (Make sure you chose the "No GUI" option in GRC.)

class my_block(gr.top_block):
    # ...

def main():
    tb = my_block()

if __name__ == '__main__':

You can just import this as a module in your Python program (the if __name__ check will skip running the code that wouldn't be appropriate). Once you've done that, the way you use it is to just create the top block and call tb.start(). This will start the flow graph without also waiting for it to finish, which is exactly what you want when you have a separate main loop like a web server.

import my_block

tb = my_block.my_block()

When you're shutting down, do this to stop the GNU Radio threads:


Then you can also use the generated methods (a getter and setter per GRC "Variable") to change parameters while the flow graph is running. For example, if you have a "Variable" block in GRC with ID freq, then you can use freq in other blocks' parameters, and GRC will generate a getter and setter method like this:

def get_freq(self):
    return self.freq

def set_freq(self, freq):
    self.freq = freq

And so from your controlling application, you call these methods, like tb.set_freq(123e6) to change the frequency to 123 MHz, for example.

There's a lot more that can be said about how to go beyond what GRC generates for you (which would best be asked as separate questions), but this is how you get started with integrating a GNU Radio flow graph into a larger program.

I would recommend expecting to eventually stop using GRC's code generation and write your own Python code. This is because GRC has quite a few limitations in what you can do with it — for example, if you want to decide at runtime which type of signal source block to create, you can't do that in GRC but it's easy when you write your own Python. You can always use GRC to generate examples to copy from, when you're unsure how to configure a block.

  • $\begingroup$ Thank you so much Kevin for taking time and answering my question. Again, I am a real begginer when it comes to python or programming, but definitely I will do my best to figure this out and what I can do. $\endgroup$
    – Hadad
    Jul 9, 2019 at 22:17
  • $\begingroup$ Kevin, I would be so grateful if you elaborate more on your statement " use the generated methods (a getter and setter per GRC "variable") to change parameters" ... I just got the time to work on this part. If you have/can refer me to an example that would be great! $\endgroup$
    – Hadad
    Jul 17, 2019 at 0:52
  • 1
    $\begingroup$ @Hadad I've added an example of that. If you still need to know more, please post a new question, and make sure to be specific about what you want to do and what you have so far (show the code that sets up tb and what effect you want to have on the flow graph, and so on). $\endgroup$
    – Kevin Reid AG6YO
    Jul 17, 2019 at 2:24
  • $\begingroup$ Kevin, that was very helpful. Thanks a lot. $\endgroup$
    – Hadad
    Jul 17, 2019 at 16:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .