biscuit-monitor 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +20 -0
- data/.noexec.yml +1 -0
- data/.rvmrc +52 -0
- data/Gemfile +10 -0
- data/LICENSE +22 -0
- data/README.md +57 -0
- data/Rakefile +4 -0
- data/bin/biscuit-monitor +8 -0
- data/bin/biscuit-monitor-gui.rb +11 -0
- data/biscuit-monitor.gemspec +22 -0
- data/lib/biscuit-monitor/version.rb +5 -0
- data/lib/biscuit-monitor.rb +147 -0
- metadata +123 -0
data/.gitignore
ADDED
data/.noexec.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
exclude: [mux, tmuxinator]
|
data/.rvmrc
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p194-perf@biscuit-monitor"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.14.7 (stable)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
if [[ $- == *i* ]] # check for interactive shells
|
29
|
+
then echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
|
30
|
+
else echo "Using: $GEM_HOME" # don't use colors in non-interactive shells
|
31
|
+
fi
|
32
|
+
else
|
33
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
34
|
+
rvm --create use "$environment_id" || {
|
35
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
36
|
+
return 1
|
37
|
+
}
|
38
|
+
fi
|
39
|
+
|
40
|
+
# If you use bundler, this might be useful to you:
|
41
|
+
# if [[ -s Gemfile ]] && {
|
42
|
+
# ! builtin command -v bundle >/dev/null ||
|
43
|
+
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
44
|
+
# }
|
45
|
+
# then
|
46
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
47
|
+
# gem install bundler
|
48
|
+
# fi
|
49
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
50
|
+
# then
|
51
|
+
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
52
|
+
# fi
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Michael D. Hall
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Biscuit::Monitor
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'biscuit-monitor'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install biscuit-monitor
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
30
|
+
|
31
|
+
## Notes
|
32
|
+
|
33
|
+
- cinr
|
34
|
+
|
35
|
+
Carrier to Interference-plus-Noise Ratio (CINR)
|
36
|
+
|
37
|
+
- rssi
|
38
|
+
|
39
|
+
Received signal strength indication
|
40
|
+
|
41
|
+
## Reference
|
42
|
+
|
43
|
+
http://www.clear.com/support/faq/connection-issues/connectionsignal/how-do-i-find-my-cinr-score-from-my-clear-spot-device
|
44
|
+
|
45
|
+
From the CLEAR Spot 4G+ Personal Hotspot website
|
46
|
+
|
47
|
+
CINR
|
48
|
+
|
49
|
+
CINR stands for Carrier to Interference-plus-Noise Ratio (CINR), expressed in decibels (dBs). CINR is a measurement of signal effectiveness. We use the CINR score to tell us the signal quality received by the modem.
|
50
|
+
|
51
|
+
The higher the number the better signal quality you are receiving. You need at minimum a CINR of 8 or greater to receive consistent service. A CINR score of 18 or higher is considered excellent signal quality.
|
52
|
+
|
53
|
+
RSSI
|
54
|
+
|
55
|
+
RSSI stands for Received signal strength indicator RSSI is a measurement of the power present in a received radio signal. We use RSSI score to tell us the strength of signal your CLEAR Spot is receiving.
|
56
|
+
|
57
|
+
A RSSI score of -100dBm reflects poor signal strength, a score of -50dBm is an excellent RSSI score and reflects a strong signal.
|
data/Rakefile
ADDED
data/bin/biscuit-monitor
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/Applications/Shoes.app/Contents/MacOS/shoes
|
2
|
+
Shoes.app :title => "Biscuit Monitor", :width => 400, :height => 300 do
|
3
|
+
para "What's your login name?"
|
4
|
+
@name = edit_line
|
5
|
+
para "What's your password?"
|
6
|
+
@password = edit_line(:secret => true)
|
7
|
+
para "What's the device's IP address?"
|
8
|
+
@device_ip = edit_line(:default => "192.168.1.1")
|
9
|
+
|
10
|
+
button("click me") { alert "#{@username} #{@device_ip}" }
|
11
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/biscuit-monitor/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Michael D. Hall"]
|
6
|
+
gem.email = ["mdh@just3ws.com"]
|
7
|
+
gem.description = %q{Monitors your Clear Hotspot biscuit.}
|
8
|
+
gem.summary = %q{Console app that will poll your attached Clear Hotspot biscuit.}
|
9
|
+
gem.homepage = "https://github.com/just3ws/biscuit-monitor"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "biscuit-monitor"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Biscuit::Monitor::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency 'thor'
|
19
|
+
gem.add_runtime_dependency 'multi_json'
|
20
|
+
gem.add_runtime_dependency 'oj'
|
21
|
+
gem.add_runtime_dependency 'colorize'
|
22
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'biscuit-monitor/version'
|
4
|
+
require 'colorize'
|
5
|
+
require 'logger'
|
6
|
+
require 'multi_json'
|
7
|
+
require 'net/http'
|
8
|
+
require 'thor'
|
9
|
+
require 'uri'
|
10
|
+
|
11
|
+
module Biscuit
|
12
|
+
module Monitor
|
13
|
+
trap("SIGINT") { throw :ctrl_c }
|
14
|
+
|
15
|
+
class Monitor
|
16
|
+
def initialize(device_ip)
|
17
|
+
@logger = Logger.new('biscuit-monitor.log', 10, 1024000)
|
18
|
+
@device_ip = device_ip
|
19
|
+
@seconds = 3
|
20
|
+
end
|
21
|
+
|
22
|
+
def device_uri
|
23
|
+
URI.parse("http://#{@device_ip}/cgi-bin/webmain.cgi?act=act_wimax_status¶m=WIMAX_LINK_STATUS,WIMAX_DEVICE_STATUS")
|
24
|
+
# TODO get the battery status
|
25
|
+
# URI.parse("http://#{@device_ip}/cgi-bin/webmain.cgi?act_battery_status&TYPE=BISCUIT¶m=BATTERY_STATUS")
|
26
|
+
end
|
27
|
+
|
28
|
+
def clear_last_message
|
29
|
+
(@last_message || "").length.times { print "\b" }
|
30
|
+
end
|
31
|
+
|
32
|
+
def cinr_foreground_color(cinr)
|
33
|
+
case
|
34
|
+
when cinr > 24
|
35
|
+
:green
|
36
|
+
when (13..24).include?(cinr)
|
37
|
+
:light_green
|
38
|
+
when (8..12).include?(cinr)
|
39
|
+
:yellow
|
40
|
+
when (3..7).include?(cinr)
|
41
|
+
:light_red
|
42
|
+
when cinr < 3
|
43
|
+
:red
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def rssi_foreground_color (rssi)
|
48
|
+
case
|
49
|
+
when rssi > -50
|
50
|
+
:green
|
51
|
+
when rssi < -100
|
52
|
+
:red
|
53
|
+
else
|
54
|
+
:yellow
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def poll
|
59
|
+
catch :ctrl_c do
|
60
|
+
begin
|
61
|
+
response = parse(scrub_response(Net::HTTP.get(device_uri)))
|
62
|
+
|
63
|
+
cinr = Integer(response[:data][:cinr])
|
64
|
+
rssi = Integer(response[:data][:rssi])
|
65
|
+
|
66
|
+
message = "CINR: #{cinr}dBs".colorize(cinr_foreground_color(cinr))
|
67
|
+
message << " ".uncolorize
|
68
|
+
message << "RSSI: #{rssi}dBs".colorize(rssi_foreground_color(rssi))
|
69
|
+
|
70
|
+
write message
|
71
|
+
@logger.debug(response)
|
72
|
+
|
73
|
+
rescue Errno::EHOSTUNREACH => err
|
74
|
+
|
75
|
+
write "Cannot find the biscuit. Check your connection."
|
76
|
+
@logger.error(err.inspect)
|
77
|
+
|
78
|
+
rescue StandardError => err
|
79
|
+
|
80
|
+
write "There was an error checking your biscuit. See the logfile for details."
|
81
|
+
@logger.error(err.inspect)
|
82
|
+
|
83
|
+
ensure
|
84
|
+
|
85
|
+
sleep @seconds # TODO when error increase length of time until next check to avoid spamming error log
|
86
|
+
end until false
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def write(message)
|
92
|
+
clear_last_message
|
93
|
+
print message
|
94
|
+
@last_message = message
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
def parse(document)
|
100
|
+
data = {}
|
101
|
+
hash = MultiJson.decode(document, symbolize_keys: true)
|
102
|
+
hash.delete(:list)
|
103
|
+
hash.each do |k,v|
|
104
|
+
data[k] = if v.class == String && /^-?\d+$/ =~ v
|
105
|
+
Integer(v)
|
106
|
+
elsif v.class == Hash
|
107
|
+
idata = {}
|
108
|
+
v.each do |ik, iv|
|
109
|
+
idata[ik] = if iv.class == String && /^-?\d+$/ =~ iv
|
110
|
+
Integer(iv)
|
111
|
+
else
|
112
|
+
iv
|
113
|
+
end
|
114
|
+
end
|
115
|
+
idata
|
116
|
+
else
|
117
|
+
v
|
118
|
+
end
|
119
|
+
end
|
120
|
+
data
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
def scrub_response(document)
|
125
|
+
document = document.split.join
|
126
|
+
document.gsub!(/'/, '"')
|
127
|
+
document.gsub!(/:(\d*),/, ':"\1",')
|
128
|
+
document.gsub!(/(\w*):"/, '"\1":"')
|
129
|
+
document.gsub!(/(\w*):{/, '"\1": {')
|
130
|
+
document.gsub!(/(\w*):\[/, '"\1": [')
|
131
|
+
document.gsub!(/":"/, '": "')
|
132
|
+
document.gsub!(/,/, ', ')
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
class CLI < Thor
|
138
|
+
default_task :start
|
139
|
+
|
140
|
+
desc "start", "Start monitoring your biscuit."
|
141
|
+
method_option :device_ip, :default => "192.168.1.1", :aliases => "-d"
|
142
|
+
def start
|
143
|
+
Biscuit::Monitor::Monitor.new(options[:device_ip]).poll
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: biscuit-monitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael D. Hall
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: multi_json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: oj
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: colorize
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Monitors your Clear Hotspot biscuit.
|
79
|
+
email:
|
80
|
+
- mdh@just3ws.com
|
81
|
+
executables:
|
82
|
+
- biscuit-monitor
|
83
|
+
- biscuit-monitor-gui.rb
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files: []
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- .noexec.yml
|
89
|
+
- .rvmrc
|
90
|
+
- Gemfile
|
91
|
+
- LICENSE
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- bin/biscuit-monitor
|
95
|
+
- bin/biscuit-monitor-gui.rb
|
96
|
+
- biscuit-monitor.gemspec
|
97
|
+
- lib/biscuit-monitor.rb
|
98
|
+
- lib/biscuit-monitor/version.rb
|
99
|
+
homepage: https://github.com/just3ws/biscuit-monitor
|
100
|
+
licenses: []
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.8.24
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: Console app that will poll your attached Clear Hotspot biscuit.
|
123
|
+
test_files: []
|