naj1024 / pyspectrum

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

Error programm not work #7

Closed Lucstay11 closed 1 year ago

Lucstay11 commented 1 year ago

Traceback (most recent call last): File "/home/pi/pyspectrum/src/SpectrumAnalyser.py", line 692, in <module> main() File "/home/pi/pyspectrum/src/SpectrumAnalyser.py", line 74, in main configuration, snap_configuration, thumbs_dir = setup() File "/home/pi/pyspectrum/src/SpectrumAnalyser.py", line 334, in setup configuration.input_sources = DataSourceFactory.DataSourceFactory().sources() File "/home/pi/pyspectrum/src/dataSources/DataSourceFactory.py", line 42, in __init__ module = importlib.import_module(input_source_module) File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 790, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "/home/pi/pyspectrum/src/dataSources/DataSource_pluto.py", line 40, in <module> import adi # analog devices device specifics for using iio File "/home/pi/.local/lib/python3.9/site-packages/adi/__init__.py", line 34, in <module> from adi.ad717x import ad717x File "/home/pi/.local/lib/python3.9/site-packages/adi/ad717x.py", line 39, in <module> from adi.context_manager import context_manager File "/home/pi/.local/lib/python3.9/site-packages/adi/context_manager.py", line 34, in <module> import iio File "/home/pi/.local/lib/python3.9/site-packages/iio.py", line 229, in <module> _get_backends_count = _lib.iio_get_backends_count File "/usr/lib/python3.9/ctypes/__init__.py", line 387, in __getattr__ func = self.__getitem__(name) File "/usr/lib/python3.9/ctypes/__init__.py", line 392, in __getitem__ func = self._FuncPtr((name_or_ordinal, self)) AttributeError: python3: undefined symbol: iio_get_backends_count

Can you explain me?

naj1024 commented 1 year ago

Lucky, just happened to check my emails.

Anyway, looks like it is having a problem finding iio devices, which is used for the analog devices Pluto device. If you don't have one of those then you could remove the python support for those. In requirements.txt those were.

pyadi-iio>=0.0.7 pylibiio>=0.21

Removing those from your python should do it. Alternatively, and possibly easier, you could delete (or move out of the way) the input device that depends on iio support:

/home/pi/pyspectrum/src/dataSources/DataSource_pluto.py

I've not tested this python programme on a raspberry pi (yet), tested on Ubuntu, debian and centos but mainly on windows through pycharm. I just tried a fresh clone from the repo and install through pip on an old debian 9.8 - but my python and apt is completely trashed for some reason. About time i built a new vm with something more up to date :)

Please remember this was a leason for me in python, so it has ideas but the implementation is not the best.

Lucstay11 commented 1 year ago

Thank you for your answer and yes your project seemed good and I found it super useful. I don't know if it's the Raspberry pi that does this but it doesn't work I get this error now. Do you know of a similar project with a spectrum analyzer JS frontend and no backend just an rtl_tcp connection that controls the rtl-sdr?

Traceback (most recent call last): File "/home/pi/pyspectrum/src/SpectrumAnalyser.py", line 692, in <module> main() File "/home/pi/pyspectrum/src/SpectrumAnalyser.py", line 74, in main configuration, snap_configuration, thumbs_dir = setup() File "/home/pi/pyspectrum/src/SpectrumAnalyser.py", line 334, in setup configuration.input_sources = DataSourceFactory.DataSourceFactory().sources() File "/home/pi/pyspectrum/src/dataSources/DataSourceFactory.py", line 42, in __init__ module = importlib.import_module(input_source_module) File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 790, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "/home/pi/pyspectrum/src/dataSources/DataSource_audio.py", line 30, in <module> import sounddevice as sd File "/home/pi/.local/lib/python3.9/site-packages/sounddevice.py", line 71, in <module> raise OSError('PortAudio library not found') OSError: PortAudio library not found

naj1024 commented 1 year ago

Looks like you are struggling with missing python libraries or OS support for them. It is now missing audio support, sounddevice/ portaudio.

If you removed support for pluto, audio , funcube etc from dataSources maybe the rtlsdr support will work. That is leave the following files in dataSources and remove the rest:

DataSource.py DataSource_file.py DataSource_null.py DataSource_rtlsdr.py DataSource_rtltcp.py DataSource_socket.py DataSourceFactory.py

If you have working rtlsdr on the Pi already then there is a chance it will work.

I do feel i should boot a Pi and try it out, but a bit busy at the moment and the only Pi i have free is quite old - shouldn't matter though to just get the app running.

I'm not aware of another project with a web front end to rtlsdr, seemed to me to be the thing to do. Most other spectrum analysers seem to code up actual applications, which makes sense due to speed issues.

I'm aware of https://github.com/maia-sdr, but that only supports the Pluto and does all the fft's in the fpga. To me it looks like a very good solution - just needs a fast software fft and support for all the other sdrs.

Lucstay11 commented 1 year ago

Ok well I think your program will suffice I managed to launch it correctly I access the web app but for some reason my RTL-SDR is connected to my pi 4 but it puts Null devices connected And the rtl_tcp connection does not work can you tell me why?

naj1024 commented 1 year ago

Progress then.

If you can run it from the command line then you can ask it what input devices it has found. It won't automatically select an input source, which is why it defaults to null. For rtlsdr devices they are normally numbered 0..N with the first device being 0. So you would select rtlsdr and enter 0 in the parameter field.

You can force it to use a device from the start, e.g. with -irtlsdr:0 to use the first rtlsdr device if one is available.

C:.....\python.exe C:/..../SpectrumAnalyser.py -irtlsdr:0

Or scan for all input sources:

C:.....\python.exe C:/..../SpectrumAnalyser.py -i? Available sources: ['audio', 'file', 'funcube', 'null', 'pluto', 'rtlsdr', 'rtltcp', 'socket'] audio:Number - number of the input device e.g. audio:1, '?' for list file:Filename - Filename, binary or wave, e.g. file:./xyz.cf123.4.cplx.200000.16tbe funcube:Number - number of the input device e.g. funcube:1, '?' for list null:xxx - xxx ignored parameter pluto:IP - The Ip or resolvable name of the Pluto device, e.g. pluto:192.168.2.1 rtlsdr:Number - The device number to use, normally 0. Use '?' for list rtltcp:IP:port - The Ip or resolvable name and port of an rtltcp server, e.g. rtltcp:192.168.2.1:12345 socket:IP:port - The Ip or resolvable name and port of a server, e.g. socket:192.168.2.1:12345

Process finished with exit code 0

Or just scan for rtlsdr devices device plugged in: C:....\python.exe C:/..../SpectrumAnalyser.py -irtlsdr:? No rtlsdr devices found, scanned 0 to 9

For one NooElec plugged in: C:...\python.exe C:/.../SpectrumAnalyser.py -irtlsdr:? device 0, type 5 R820T

You can then select 0 as the parameter on rtlsdr as the drop down selected device if you haven't run it with a device selected.

If you have an rtltcp available on say machine 192.168.1.123 port 5000 then: Select rtltcp and enter 192.168.1.123:5000 as the parameters.

Lucstay11 commented 1 year ago

Perfect it works I just had to add the 0 as you mentioned before! Now the rtl_tcp does not work I get this input specification does not contain two colon seperated items, 192.168.1.59:1234 I use port 1234 is by default with rtl_tcp

naj1024 commented 1 year ago

Ooops, wrong equality on line 111 of DataSource_rtltcp.py

if len(parts) <= 2:
should be if len(parts) < 2:

Lucstay11 commented 1 year ago

Yes but then:

required argument is not an integer
Null device
naj1024 commented 1 year ago

Not tested rtltcp much, obviously. Created an rtltcp server for testing and got it working. I uploaded an new DataSource_rtltcp.py file with the bug fixes. Works streaming samples from a pi with an rtl plugged.

Either git pull on main2 (default), remember this will put back the other sources as well. Or get that one file and replace the one you have.

Lucstay11 commented 1 year ago

Thank you the rtl_tcp works but it crashes sometimes for an unknown reason... Maybe my pi zero... Last question is it normal that I have no sound in the browser while I keep the Datasource_audio!

naj1024 commented 1 year ago

Possibly, not a fan of sound, not tested audio output when sound device is used for input.

Crashing may be due to something not keeping up with the required rate, rtl_tcp may be buffering up samples and running out of memory.

naj1024 commented 1 year ago

Just tested youtube playing a video with audio device zero selected for pyspectrum. No impact on audio out from browser.

Just noticed you are using a pizero, bit ambitious to run for the sort of sample rates and fft's required.

Lucstay11 commented 1 year ago

Ok strange. And what is thesocket and theaudio in the source input? I would like to delete it I don't need it I have tested your program on my pi 4 and pi zero 2

naj1024 commented 1 year ago

Just tested youtube playing a video with audio device zero selected for pyspectrum. No impact on audio out from browser.

Just noticed you are using a pizero, bit ambitious to run for the sort of sample rates and fft's required.

naj1024 commented 1 year ago

DataSource_socket.py DataSource_audio.py