naj1024 / pyspectrum

Python based spectrum analyser with web UI and sdr input
MIT License
23 stars 5 forks source link

scanning frequency band #15

Closed Ganesh202 closed 4 months ago

Ganesh202 commented 4 months ago

if i want to scan or sweep the frequency band in certain frequency range example(2.4ghz -2.5ghz)for that in which python file or any other file i need to change the code and where

thank you

naj1024 commented 4 months ago

python or web? You could do this from the rest interface handled in FlaskInterface.py

In webUi/webroot/main.js has incrementCf(divisor) which is used to step the frequency in 1/10 or 1/4 of the sampleRate tied to the cf1+- or cf+-4 buttons. The rest endpoint is tuning/frequency. So something that called that from the web could step across a band.

In the python the rest interface that the incrementCf calls is handled by FlaskInterface.py, which populates the dictionary self._update. This is then picked up in pyspectrum.py in the function sync_state(). The 'frequency' dictionary item in shared_update (self._update in FlaskInterface.py) then calls the appropriate set_centre_frequency_hz() of the device. Some house keeping keeps the state correct between the UI and the SDR.

The sync_state() function in pyspectrum.py is called from the main loop in main() in pyspectrum.py. You could call this with your own values in the dictionary with 'frequency' set. Maybe every second. This is the main loop for getting samples so if you stall or take too long you will see problems in the UI.

To protoype, add something in the main loop that prints to the console every two seconds and calls sync_state() with the dictionary set correctly and see what happens, just copy the existing sync_state() call and set the dictionary item for 'frequency'. Print the dictionary out in sync_state() to see what to provide for the frequency.

e.g. in sync_state()

      if 'frequency' in shared_update:
            freq = shared_update['frequency']
            print(f"New frequency {freq}")

gives: New frequency {'value': 434170000, 'conversion': 0}

Ideally you would want this in the web ui, but that is a bit more complicated :(

Ganesh202 commented 4 months ago

i want the output spectrum window appear when i run program in any python environment(visual studio) and i don't want in web how should i do that ??

naj1024 commented 4 months ago

This is probably not the analyser you want then, it is predicated on being a web interface. If you have a local display, like matplotlib then you would also need some sort of control as well.

However in pyspectrim.py there is a function send_to_ui() which takes in the spectrum data and sends it to the UI queue. If you want to try and use something like matplotlib for a local display then this is the place to do it.