SHARE
TWEET

RTL_FM Pocsag Multimon decoder

a guest Apr 15th, 2014 1,018 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. # working cmd:
  3. # rtl_fm -f 153980000 -s 22050 -g 40 -p 65 | multimon-ng -a POCSAG1200 -f alpha -t raw -
  4. '''
  5.  
  6. !! This requires a recent build of Multimon-NG as the old builds wont accept a piped input !!
  7.  
  8. Change the rtl_fm string to suit your needs.. add -a POCSAG512 , 2400 etc if needed to the Multimon-ng string
  9. This just prints and writes to a file, you can put it in a threaded class and pass though a queue
  10. or whatever suits your needs.
  11.  
  12.  
  13. '''
  14. import time
  15. import sys
  16. import subprocess
  17. import os
  18.  
  19. def curtime():
  20.     return time.strftime("%H:%M:%S %Y-%m-%d")
  21.  
  22. with open('error.txt','a') as file:
  23.     file.write(('#' * 20) + '\n' + curtime() + '\n')
  24.  
  25. multimon_ng = subprocess.Popen("rtl_fm -f 153980000 -s 22050 -g 40 -p 65 | multimon-ng -a POCSAG1200 -f alpha -t raw -",
  26.                                #stdin=rtl_fm.stdout,
  27.                                stdout=subprocess.PIPE,
  28.                                stderr=open('error.txt','a'),
  29.                                shell=True)
  30.  
  31. try:
  32.     while True:
  33.         line = multimon_ng.stdout.readline()
  34.         multimon_ng.poll()
  35.         if line.__contains__("Alpha:"):    # filter out only the alpha
  36.             if line.startswith('POCSAG'):
  37.                 address = line[22:28].replace(" ", "").zfill(7)
  38.                 message = line.split('Alpha:   ')[1].strip().rstrip('<ETB>').strip()
  39.                 output=(address+' '+curtime()+' '+ message+'\n')
  40.                 print address, curtime(), message
  41.                 with open('pocsag.txt','a') as f:
  42.                     f.write(output)
  43.         if not "Alpha:" in line:
  44.             with open("missed.txt","a") as missed:
  45.                 missed.write(line + '\n')
  46.  
  47. except KeyboardInterrupt:
  48.     os.kill(multimon_ng.pid, 9)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top