#!/usr/bin/env python # (C) 2009 Kevin Mehall # http://blog.kevinmehall.net/2009/cell-signal-monitoring # BSD License # sudo rfcomm bind 0 1 # sudo rfcomm release 0 import pexpect, fdpexpect import sys,os,time device=sys.argv[1] outfile=sys.argv[2] out=open(outfile, 'a') print "opening device...", sys.stdout.flush() fd = os.open(device, os.O_RDWR|os.O_NOCTTY) m = fdpexpect.fdspawn(fd, timeout=5, logfile=open('/tmp/cellcom', 'a')) m.setecho(False) print "done" print "initializing...", sys.stdout.flush() m.send("AT S7=45 S0=0 V1 X4 &c1 E0\r") m.expect("OK") print "done" print "checking connection...", sys.stdout.flush() m.send("AT\r") m.expect("OK") print "ok" print "starting (at next t%30==0)" def bars(cind): parts=cind.split(',') if parts[1]!='1': return -1 else: return int(parts[4]) def sleep_till_30(): t=time.time() s=30-t%30 print s time.sleep(s) while True: sleep_till_30() print "*", m.send("AT+CIND?\r") m.expect(r"\+CIND: [^\r\n]*") cind=m.match.group(0) #m.before.strip().split('\n')[1] print "*", m.send("AT+CSQ\r") m.expect(r"\+CSQ: [^\r\n]*") csq=m.match.group(0) #m.before.strip().split('\n')[1] line='\t'.join([time.asctime(), cind, csq, '|', str(bars(cind))]) print line out.write(line+'\n') out.flush()