shajen / rtl-sdr-scanner

Automatically scan and record selected frequencies ranges using rtl-sdr.
GNU General Public License v3.0
58 stars 14 forks source link

main.py gets killed sometimes when recording #14

Open dandud100 opened 2 years ago

dandud100 commented 2 years ago

[2022-01-21 15:42:58.089][ DEBUG][ sdr] frequency: 145,081,420 Hz, power: -10.01 dB ____ [2022-01-21 15:42:58.090][ DEBUG][ sdr] frequency: 145,477,783 Hz, power: -10.00 dB ____ [2022-01-21 15:42:58.090][ DEBUG][ sdr] frequency: 145,535,156 Hz, power: -9.93 dB ____ [2022-01-21 15:42:58.090][ DEBUG][ sdr] frequency: 145,579,833 Hz, power: -10.03 dB ____ [2022-01-21 15:42:58.091][ DEBUG][ sdr] frequency: 145,650,146 Hz, power: -4.73 dB ##################### [2022-01-21 15:42:58.091][ DEBUG][ sdr] -------------------------------------------------------------------------------- [2022-01-21 15:42:58.091][ INFO][ sdr] new recording: 145,650,146 Hz [2022-01-21 15:43:06.536][ DEBUG][ sdr] frequency: 145,086,059 Hz, power: -9.95 dB ____ [2022-01-21 15:43:06.583][ DEBUG][ sdr] frequency: 145,524,902 Hz, power: -9.99 dB ____ [2022-01-21 15:43:06.584][ DEBUG][ sdr] frequency: 145,569,458 Hz, power: -9.99 dB ____ [2022-01-21 15:43:06.584][ DEBUG][ sdr] frequency: 145,650,146 Hz, power: -4.72 dB ##################### [2022-01-21 15:43:06.584][ DEBUG][ sdr] frequency: 145,847,167 Hz, power: -9.98 dB ____ [2022-01-21 15:43:06.585][ DEBUG][ sdr] -------------------------------------------------------------------------------- [2022-01-21 15:43:06.595][ INFO][ sdr] close recording: 145,650,146 Hz, time: 0.53s, too short, removing [2022-01-21 15:43:09.739][ DEBUG][ sdr] frequency: 145,588,134 Hz, power: -10.00 dB ____ [2022-01-21 15:43:09.740][ DEBUG][ sdr] frequency: 145,650,146 Hz, power: -4.74 dB #####################___ [2022-01-21 15:43:09.740][ DEBUG][ sdr] frequency: 145,716,674 Hz, power: -9.93 dB ____ [2022-01-21 15:43:09.741][ DEBUG][ sdr] frequency: 145,739,135 Hz, power: -10.01 dB ____ [2022-01-21 15:43:09.741][ DEBUG][ sdr] frequency: 145,773,437 Hz, power: -9.99 dB ____ [2022-01-21 15:43:09.741][ DEBUG][ sdr] -------------------------------------------------------------------------------- [2022-01-21 15:43:09.743][ INFO][ sdr] new recording: 145,650,146 Hz Killed

Where are detailed logs saved?

dandud100 commented 2 years ago

Okay found logs (dmesg)

[ 2781.272968] lowmem_reserve[]: 0 0 0 [ 2781.272992] DMA: 5264kB (UMEC) 3788kB (UMEC) 11116kB (UME) 6632kB (UE) 3864kB (UEC) 15128kB (U) 8256kB (U) 1512kB (C) 01024kB 02048kB 3*4096kB (C) = 28216kB [ 2781.273106] 527 total pagecache pages [ 2781.273113] 340 pages in swap cache [ 2781.273121] Swap cache stats: add 108385, delete 108046, find 19755/22864 [ 2781.273126] Free swap = 0kB [ 2781.273132] Total swap = 102396kB [ 2781.273138] 242688 pages RAM [ 2781.273143] 0 pages HighMem/MovableOnly [ 2781.273149] 6443 pages reserved [ 2781.273155] 65536 pages cma reserved [ 2781.273160] Tasks state (memory values in pages): [ 2781.273166] [ pid ] uid tgid total_vm rss pgtables_bytes swapents oom_score_adj name [ 2781.273189] [ 134] 0 134 19591 78 69632 97 -250 systemd-journal [ 2781.273198] [ 156] 0 156 4897 14 20480 297 -1000 systemd-udevd [ 2781.273211] [ 373] 108 373 1728 20 14336 62 0 avahi-daemon [ 2781.273221] [ 374] 0 374 2050 0 16384 54 0 cron [ 2781.273230] [ 375] 104 375 1924 13 18432 111 -900 dbus-daemon [ 2781.273239] [ 384] 108 384 1688 3 14336 62 0 avahi-daemon [ 2781.273249] [ 394] 0 394 6636 61 24576 185 0 rsyslogd [ 2781.273259] [ 401] 0 401 3256 28 22528 119 0 systemd-logind [ 2781.273268] [ 405] 65534 405 1328 5 14336 42 0 thd [ 2781.273278] [ 411] 0 411 2938 12 20480 91 0 wpa_supplicant [ 2781.273287] [ 465] 0 465 6924 0 18432 34 0 rngd [ 2781.273297] [ 483] 0 483 1121 0 14336 26 0 agetty [ 2781.273306] [ 485] 0 485 3089 14 18432 153 -1000 sshd [ 2781.273316] [ 488] 0 488 2999 19 20480 136 0 wpa_supplicant [ 2781.273325] [ 553] 0 553 514 0 8192 29 0 hciattach [ 2781.273335] [ 574] 0 574 5290 2 28672 209 0 bluetoothd [ 2781.273344] [ 668] 0 668 3619 0 22528 235 0 sshd [ 2781.273355] [ 673] 0 673 747 35 12288 75 0 dhcpcd [ 2781.273364] [ 677] 1000 677 3586 1 22528 213 0 systemd [ 2781.273373] [ 678] 1000 678 9256 54 32768 436 0 (sd-pam) [ 2781.273383] [ 701] 1000 701 3619 5 22528 230 0 sshd [ 2781.273392] [ 702] 1000 702 1128 6 12288 74 0 sftp-server [ 2781.273401] [ 781] 0 781 3619 9 22528 227 0 sshd [ 2781.273411] [ 789] 1000 789 3619 41 22528 196 0 sshd [ 2781.273420] [ 790] 1000 790 2149 71 18432 171 0 bash [ 2781.273430] [ 1003] 1000 1003 3255 0 20480 121 0 sudo [ 2781.273440] [ 1004] 0 1004 28300 32 88064 96 0 journalctl [ 2781.273451] [ 1094] 0 1094 262703 217673 1042432 21489 0 python3 [ 2781.273460] [ 1100] 0 1100 3619 25 22528 211 0 sshd [ 2781.273469] [ 1111] 1000 1111 3619 26 22528 211 0 sshd [ 2781.273479] [ 1112] 1000 1112 1128 2 12288 83 0 sftp-server [ 2781.273489] [ 1141] 100 1141 5560 0 22528 135 0 systemd-timesyn [ 2781.273497] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/,task=python3,pid=1094,uid=0 [ 2781.273559] Out of memory: Killed process 1094 (python3) total-vm:1050812kB, anon-rss:870400kB, file-rss:292kB, shmem-rss:0kB, UID:0 pgtables:1018kB oom_score_adj:0 [ 2781.507182] oom_reaper: reaped process 1094 (python3), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB

So i am running out of memory on my raspberry pi 3b+

dandud100 commented 2 years ago

Jan 21 17:56:10 raspberrypi python3[400]: Exception in thread Thread-1: Jan 21 17:56:10 raspberrypi python3[400]: Traceback (most recent call last): Jan 21 17:56:10 raspberrypi python3[400]: File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner Jan 21 17:56:10 raspberrypi python3[400]: self.run() Jan 21 17:56:10 raspberrypi python3[400]: File "/home/pi/rtl-sdr-scanner/sources/sdr/samples_reader.py", line 23, in run Jan 21 17:56:10 raspberrypi python3[400]: self.queue.put((self.device.read_samples(self.samples), self.start, self.__stop)) Jan 21 17:56:10 raspberrypi python3[400]: File "/usr/local/lib/python3.9/dist-packages/rtlsdr/rtlsdr.py", line 482, in read_samples Jan 21 17:56:10 raspberrypi python3[400]: iq = self.packed_bytes_to_iq(raw_data) Jan 21 17:56:10 raspberrypi python3[400]: File "/usr/local/lib/python3.9/dist-packages/rtlsdr/rtlsdr.py", line 498, in packed_bytes_to_iq Jan 21 17:56:10 raspberrypi python3[400]: iq = data.astype(np.float64).view(np.complex128) Jan 21 17:56:10 raspberrypi python3[400]: numpy.core._exceptions.MemoryError: Unable to allocate 15.6 MiB for an array with shape (2048000,) and data type float64

shajen commented 2 years ago

Hi, please visit my new project, rtl-sdr scanner in c++ https://github.com/shajen/rtl-sdr-scanner-cpp. I decied to move from python to c++ due to performance cause. I ran c++ implementation on raspberry pi with 1 GB ram, 4 cores and it work perfect. Keep in mind that this is alpha version.

dandud100 commented 2 years ago

Hi, please visit my new project, rtl-sdr scanner in c++ https://github.com/shajen/rtl-sdr-scanner-cpp. I decied to move from python to c++ due to performance cause. I ran c++ implementation on raspberry pi with 1 GB ram, 4 cores and it work perfect. Keep in mind that this is alpha version.

Thank you. The configuration file is very confusing. I dont get how i can set a frequency to ignore. It is permanently recording 144.600, i want to exclude this. Also i want to reduce the gain a little bit as it is very noisy for me.

But i like it, it works on my raspberry pi also!

shajen commented 2 years ago

Support of json configuration file (like in python) will be added in future.

For now you have to change this lines:

const std::vector<FrequencyRange> SCANNER_FREQUENCIES{{144000000, 146000000, 125}};
const std::vector<FrequencyRange> IGNORED_FREQUENCIES;
dandud100 commented 2 years ago

Support of json configuration file (like in python) will be added in future.

For now you have to change this lines:

const std::vector<FrequencyRange> SCANNER_FREQUENCIES{{144000000, 146000000, 125}};
const std::vector<FrequencyRange> IGNORED_FREQUENCIES;

Can you please give me an example for this and the gain.

shajen commented 2 years ago

Example to scan 430-440 MHz (with step 125 Hz) and 140-150 MHz (with step 250 Hz) and exclude 433-434 MHz use:

const std::vector<FrequencyRange> SCANNER_FREQUENCIES{{430000000, 440000000, 125}, {140000000, 150000000, 250}};
const std::vector<FrequencyRange> IGNORED_FREQUENCIES{{433000000, 434000000}};

Example for gain 49.6:

constexpr auto RTL_SDR_GAIN = std::optional<int>(496);

Example for gain 22.9:

constexpr auto RTL_SDR_GAIN = std::optional<int>(229);

Disable gain:

constexpr auto RTL_SDR_GAIN = std::nullopt;

Hope it helps you!

dandud100 commented 2 years ago

Hope it helps you!

It does! Thank you! May i ask what you configured for gain?

shajen commented 2 years ago

To check check gain values supported by your scanner:

shajen@artemida:~ $ rtl_test 
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Supported gain values (29): 0.0 0.9 1.4 2.7 3.7 7.7 8.7 12.5 14.4 15.7 16.6 19.7 20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6 
[R82XX] PLL not locked!
Sampling at 2048000 S/s.