Python Forum
How to control flowgraph variables from a Webserver?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to control flowgraph variables from a Webserver?
#1
I have a simple "dial tone" GRC application that I am running through a simple python webserver, when I run this application and call the freq method I have to set the variable value before running the script like this:

tb.set_samp_rate(32e3)
So, what I am wondering about is if I can have some sort of dynamic button or slider on my webserver page that I can use to adjust the parameter while the program is running. Meaning, to control the variables in realtime of a GNU Radio Flowgraph (like Sampling Rate, Center Frequency, Demodulator type etc.) from a Webpage.

Is that possible?

Here is my webserver script:

import SimpleHTTPServer
import SocketServer
from dial_tone_modified import dial_tone_modified

tb = dial_tone_modified()

tb.set_samp_rate(32e3)

tb.start()

PORT = 8000

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print("Server at PORT ",PORT)
httpd.serve_forever()

tb.stop()
tb.wait()
And here is my GRC python code:

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: Dial Tone Modified
# Generated: Mon Jul 15 11:15:28 2019
##################################################


from gnuradio import analog
from gnuradio import audio
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser



class dial_tone_modified(gr.top_block):

    def __init__(self):
        gr.top_block.__init__(self, "Dial Tone Modified")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate_0 = samp_rate_0 = 32000
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        self.blocks_add_xx = blocks.add_vff(1)
        self.audio_sink = audio.sink(32000, '', True)
        self.analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 440, .4, 0)
        self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 350, .4, 0)
        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 0.005, -42)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx, 2))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx, 0))
        self.connect((self.analog_sig_source_x_1, 0), (self.blocks_add_xx, 1))
        self.connect((self.blocks_add_xx, 0), (self.audio_sink, 0))

    def get_samp_rate_0(self):
        return self.samp_rate_0

    def set_samp_rate_0(self, samp_rate_0):
        self.samp_rate_0 = samp_rate_0

    def get_samp_rate(self):
        return self.samp_rate

    def set_samp_rate(self, samp_rate):
        self.samp_rate = samp_rate
        self.analog_sig_source_x_1.set_sampling_freq(self.samp_rate)
        self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)


def main(top_block_cls=dial_tone_modified, options=None):
    
    tb = dial_tone_modified()
    tb.start()
    try:
        raw_input('Press Enter to quit: ')
    except EOFError:
        pass
    tb.stop()
    tb.wait()
 

if __name__ == '__main__':
    main()
Reply


Messages In This Thread
How to control flowgraph variables from a Webserver? - by Hadad - Jul-18-2019, 04:46 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020