FM Band Scan

Move the mouse pointer over the frequency spectrum and a graph of the signal strength versus time will be displayed below.
Roll the mouse pointer over the lower graph to view details of the time that the signal was measured.

How does it work?

This Python script scans a USB FM tuner, storing the signal strength and status in a MySQL database as it goes.

#! /usr/bin/env python
# import mysql 
import MySQLdb as mdb
# import radio stuff
from FMRadio import FMRadio, FMRadioUnavailableError

con = mdb.connect('0.0.0.0', 'user', 'password', 'bandscanner')

with con:
    cur = con.cursor()
# open the radio 
    try:
        radio = FMRadio()
    except FMRadioUnavailableError:
        print "Radio not found"
        import sys; sys.exit(1)

# get the low and high values for the range
    low, high = radio.get_frequency_range()

# scan range
    for freq in range(low, high + 1, 50): 
        radio.set_frequency(freq)                
        signal = radio.get_raw_rssi()
        print "%0.2fMHz %0.0f" % (freq / 1000.0, signal)
        cur.execute("INSERT INTO logitem (frequency,signal,loggedat,afcstatus,rxsubchannels) VALUES ('%s','%s',now(),'%s','%s')", (freq / 1000.0, signal, 1==radio.get_afc(), radio.get_rxsubchans()))
    radio.close()

A PHP script running on the web server queries the database through PDO and returns the results as JSON

$sth = $dbh->prepare('SELECT frequency,signal,loggedat,afcstatus,rxsubchannels 
					FROM logitem 
					WHERE FLOOR(UNIX_TIMESTAMP(loggedat)/150)=
					(SELECT MAX(FLOOR(UNIX_TIMESTAMP(loggedat)/150))-2-(2*?) FROM logitem) 
					ORDER BY pk,frequency');

A second query is called to show the history of each frequency.

$sth = $dbh->prepare('SELECT signal,loggedat,afcstatus,rxsubchannels 
					FROM logitem WHERE frequency=?
					ORDER BY pk DESC LIMIT 400');
				

The graphs are generated from the JSON data in your browser using Elycharts, which makes use of a useful vector graphics library named Raphael.