HilinkModem 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +55 -0
- data/lib/hilinkmodem.rb +172 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 591d5a10ea51be5ead9e916f452222457b1e3812
|
4
|
+
data.tar.gz: eae97b559f4a815e0940331bb0855be3a411a6da
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b6b09913f32466f380f39420a653f2c9228ffb7cdcd281fa96d286f7331addb0008537345539d1f46b363d7dfb5323264e5d60592869ebde3b4e2be09fbe1e81
|
7
|
+
data.tar.gz: d98e9c4c83b461b575b13d6de6e0524a95292c4173f2ec77acf9bdfcb705961e022ade59f65241b53c871b7018538753c7731a04d44bfc7b8f8427d5c9419511
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Hilink - ruby interface for Huawei Hilink web-frontend
|
2
|
+
|
3
|
+
## Usage
|
4
|
+
|
5
|
+
The code supposes that the modem is connected and has the IP
|
6
|
+
192.168.1.1. Then you can do:
|
7
|
+
|
8
|
+
````
|
9
|
+
require 'hilink'
|
10
|
+
puts Hilink::Monitoring::status.inspect
|
11
|
+
````
|
12
|
+
|
13
|
+
which will return a hash of all variables that the stick can return.
|
14
|
+
|
15
|
+
Please also see the much more complete PhP-implementation on
|
16
|
+
[BlackyPanther/Huawei-HiLink](https://github.com/BlackyPanther/Huawei-HiLink).
|
17
|
+
|
18
|
+
If you have the newer version which connects to 192.168.8.1, this library
|
19
|
+
won't work for you, sorry.
|
20
|
+
|
21
|
+
## Commands
|
22
|
+
|
23
|
+
Each command is a module inside of Hilink. There are different modules:
|
24
|
+
|
25
|
+
- Monitoring - return different status of the modem
|
26
|
+
- Network - change 2g / 3g network
|
27
|
+
- SMS - send, receive and list
|
28
|
+
- Dialup - (dis)connect from network
|
29
|
+
- Modem - useful only when it is in modem-mode
|
30
|
+
- USSD - *Doesn't work due to Huawei restriction*
|
31
|
+
|
32
|
+
The Hilink-module itself has three methods:
|
33
|
+
- `send_request( path, request = {} )` - generates a valid XML-request and return
|
34
|
+
the result as a hash
|
35
|
+
- `switch_to_modem` - sends the command so the key behaves as a modem
|
36
|
+
- `switch_to_debug` - according to web-interface, no difference visible
|
37
|
+
|
38
|
+
### Monitoring
|
39
|
+
|
40
|
+
You can monitor different things:
|
41
|
+
|
42
|
+
- `traffic_statistics` - per-connection and total usage
|
43
|
+
- `traffic_reset` - set all to 0
|
44
|
+
- `status` - shows whether connected or not
|
45
|
+
- `check_notifications`
|
46
|
+
|
47
|
+
### Network
|
48
|
+
|
49
|
+
- `set_connection_type( mode = 'auto', band = '-1599903692' )` - mode
|
50
|
+
can be 'auto', '2g' or '3g'
|
51
|
+
- `current_plnm` - get actual connection
|
52
|
+
|
53
|
+
### SMS
|
54
|
+
|
55
|
+
- `list`
|
data/lib/hilinkmodem.rb
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
require 'active_support'
|
4
|
+
require 'serialport'
|
5
|
+
require 'helperclasses/hashaccessor'
|
6
|
+
|
7
|
+
|
8
|
+
module HilinkModem
|
9
|
+
extend self
|
10
|
+
#using HelperClasses::HashAccessor
|
11
|
+
|
12
|
+
def send_request( path, request = {} )
|
13
|
+
url = "/api/#{path}"
|
14
|
+
http = Net::HTTP.new('192.168.1.1')
|
15
|
+
|
16
|
+
if request != {}
|
17
|
+
req = Net::HTTP::Post.new(url)
|
18
|
+
req.body = request.to_xml(root: 'request', indent: 0, skip_types: true)
|
19
|
+
req.content_type = 'text/xml'
|
20
|
+
else
|
21
|
+
req = Net::HTTP::Get.new(url)
|
22
|
+
end
|
23
|
+
begin
|
24
|
+
response = http.request(req).body
|
25
|
+
rescue Errno::ENETUNREACH => e
|
26
|
+
return nil
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
Hash.from_xml( response )['response']
|
31
|
+
rescue REXML::ParseException => e
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def switch_to_modem
|
37
|
+
send_request( 'device/mode', :mode => 0 )
|
38
|
+
end
|
39
|
+
|
40
|
+
def switch_to_debug
|
41
|
+
send_request( 'device/mode', :mode => 1 )
|
42
|
+
end
|
43
|
+
module Modem
|
44
|
+
extend self
|
45
|
+
|
46
|
+
def send_modem( str )
|
47
|
+
sp = SerialPort.new('/dev/ttyUSB0',115200)
|
48
|
+
sp.write("#{str}\r\n")
|
49
|
+
sp.read_timeout = 100
|
50
|
+
sp.readlines
|
51
|
+
end
|
52
|
+
|
53
|
+
def switch_to_hilink
|
54
|
+
send_modem('AT^U2DIAG=119')
|
55
|
+
end
|
56
|
+
|
57
|
+
def save_modem
|
58
|
+
send_modem('AT^U2DIAG=0')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
module Monitoring
|
62
|
+
extend self
|
63
|
+
|
64
|
+
def send_request( path, request = {} )
|
65
|
+
Hilink::send_request( "monitoring/#{path}", request )
|
66
|
+
end
|
67
|
+
|
68
|
+
def traffic_statistics
|
69
|
+
send_request('traffic-statistics')
|
70
|
+
end
|
71
|
+
|
72
|
+
def traffic_reset
|
73
|
+
send_request('clear-traffic')
|
74
|
+
end
|
75
|
+
|
76
|
+
def status
|
77
|
+
send_request('status')
|
78
|
+
end
|
79
|
+
|
80
|
+
def check_notifications
|
81
|
+
send_request('check-notifications')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
module Network
|
85
|
+
extend self
|
86
|
+
|
87
|
+
def send_request( path, request = {} )
|
88
|
+
Hilink::send_request( "net/#{path}", request )
|
89
|
+
end
|
90
|
+
|
91
|
+
def current_plnm
|
92
|
+
send_request('current-plnm')
|
93
|
+
end
|
94
|
+
|
95
|
+
def set_connection_type( mode = 'auto', band: '-1599903692' )
|
96
|
+
nmode = case mode
|
97
|
+
when /2g/i
|
98
|
+
1
|
99
|
+
when /3g/i
|
100
|
+
2
|
101
|
+
else
|
102
|
+
0
|
103
|
+
end
|
104
|
+
send_request( 'network', {
|
105
|
+
:NetworkMode => nmode,
|
106
|
+
:NetworkBand => band } )
|
107
|
+
end
|
108
|
+
end
|
109
|
+
module SMS
|
110
|
+
extend self
|
111
|
+
|
112
|
+
def send_request( path, request = {} )
|
113
|
+
Hilink::send_request( "sms/#{path}", request )
|
114
|
+
end
|
115
|
+
|
116
|
+
def list( box = 1, site: 1, pref_unread: 0, count: 20 )
|
117
|
+
ret = send_request( 'sms-list', {
|
118
|
+
:PageIndex => site,
|
119
|
+
:ReadCount => count,
|
120
|
+
:BoxType => box,
|
121
|
+
:SortType => 0,
|
122
|
+
:Ascending => 0,
|
123
|
+
:UnreadPreferred => pref_unread } )
|
124
|
+
if ret && ret['Messages']['Message'].class == Hash
|
125
|
+
ret['Messages']['Message'] = [ ret['Messages']['Message'] ]
|
126
|
+
end
|
127
|
+
ret
|
128
|
+
end
|
129
|
+
|
130
|
+
def delete( index )
|
131
|
+
send_request( 'delete-sms', { :Index => index } )
|
132
|
+
end
|
133
|
+
|
134
|
+
def send( number, message, index = -1 )
|
135
|
+
send_request( 'send-sms', {
|
136
|
+
:Index => index,
|
137
|
+
:Phones => [number].flatten,
|
138
|
+
:Sca => "",
|
139
|
+
:Content => message,
|
140
|
+
:Length => message.length,
|
141
|
+
:Reserved => 1,
|
142
|
+
:Date => Time.now.strftime('%Y-%m-%d %H:%M:%S') } )
|
143
|
+
end
|
144
|
+
end
|
145
|
+
module Dialup
|
146
|
+
extend self
|
147
|
+
|
148
|
+
def send_request( path, request = {} )
|
149
|
+
Hilink::send_request( "dialup/#{path}", request )
|
150
|
+
end
|
151
|
+
|
152
|
+
def connect
|
153
|
+
send_request( 'dial', :Action => 1 )
|
154
|
+
end
|
155
|
+
|
156
|
+
def disconnect
|
157
|
+
send_request( 'dial', :Action => 0 )
|
158
|
+
end
|
159
|
+
end
|
160
|
+
module USSD
|
161
|
+
extend self
|
162
|
+
|
163
|
+
def send_request( path, request = {} )
|
164
|
+
Hilink::send_request( "ussd/#{path}", request )
|
165
|
+
end
|
166
|
+
|
167
|
+
def send( str )
|
168
|
+
return :error => "Sorry, doesn't work!"
|
169
|
+
send_request( 'send', :content => str, :codeType => 'CodeType')
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: HilinkModem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Linus Gasser
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: serialport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
description: Using the web-interface of huawei hilink modems to do things
|
42
|
+
email: ineiti@linusetviviane.ch
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- README.md
|
48
|
+
- lib/hilinkmodem.rb
|
49
|
+
homepage: https://github.com/ineiti/HilinkModem
|
50
|
+
licenses:
|
51
|
+
- GPLv3
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.2.2
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Accessing Huawei HilinkModem modems
|
73
|
+
test_files: []
|