Skip to content

Instantly share code, notes, and snippets.

@hh
Created March 5, 2011 05:38
Show Gist options
  • Save hh/856157 to your computer and use it in GitHub Desktop.
Save hh/856157 to your computer and use it in GitHub Desktop.
This snippit allows me to look at the signal strength of the cell towers used by my ZTE usb modem.
# quick hack to monitor signal strength
# based on info from: http://www.pcurtis.com/ubuntu-mobile.htm#signal_strength
require 'rubygems'
require 'serialport'
require 'time'
class GSM
def initialize(options = {})
@port = SerialPort.new(options[:port] || 3, options[:baud] || 38400, options[:bits] || 8, options[:stop] || 1, SerialPort::NONE)
@debug = options[:debug]
cmd("AT")
end
def close
@port.close
end
def cmd(cmd)
@port.write(cmd + "\r")
wait
end
def wait
buffer = ''
while IO.select([@port], [], [], 0.25)
chr = @port.getc.chr;
print chr if @debug == true
buffer += chr
end
buffer
end
end
gsm = GSM.new(:debug => false, :port => '/dev/tty.ZTEUSBATPort_')
while true
csq = gsm.cmd("AT+CSQ")
# RSSI (Received Signal Strength Indicator)
# 0 = 113 dBm or less
# 1 = 111 dBm
# 2 to 30 = 109 to 53 dBm
# 31 = 51 dBm or greater
# In practice, if the signal strength is below 10 then GPRS connections
# are unreliable. Values around 15 are good, 25 is excellent.
# mine hover between 9 and 12 in the Oropi
puts csq.scan(/\+CSQ\:\s*?(\d+),/)
gsm.wait()
end
@hh
Copy link
Author

hh commented Mar 5, 2011

Get's as low as 4, and often at 7 I'm still connected.... however the quality is poor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment