hilink 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/hilink.rb +228 -0
  3. metadata +72 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e82d555b6a19e5f6a9f6a4f3d42d5f7ea56052a
4
+ data.tar.gz: c8239dd6a032d27bffed109b348814b2a280e64f
5
+ SHA512:
6
+ metadata.gz: 47693d4046b27b7a63f599064e8448bf147c567fdadde0b1c84186bc43550b132fd7f374579c1e56de9410a87f03adef4d1ff175da05c43d5460c2a4b3d46435
7
+ data.tar.gz: 448d31cb825fb406adc91b0c1c37543de8527d1e1ba5ba4559f8e9ed5f9427a7c5b379773472664ff7cfc69d1f87578a2a7a4dac85e89f35c2b2c0e5f354665d
data/lib/hilink.rb ADDED
@@ -0,0 +1,228 @@
1
+ require 'net/http'
2
+ require "active_support/core_ext"
3
+ require 'active_support'
4
+ require 'serialport'
5
+
6
+ module Hilink
7
+ class << self
8
+ def send_request( path, request = {} )
9
+ url = "/api/#{path}"
10
+ http = Net::HTTP.new("192.168.1.1")
11
+
12
+ if request != {}
13
+ req = Net::HTTP::Post.new(url)
14
+ req.body = request.to_xml(root: "request", indent: 0, skip_types: true)
15
+ req.content_type = 'text/xml'
16
+ else
17
+ req = Net::HTTP::Get.new(url)
18
+ end
19
+
20
+ puts "Calling #{url} with _#{req.body}_"
21
+ response = http.request(req).body
22
+
23
+ Hash.from_xml( response )['response']
24
+ end
25
+
26
+ def switch_to_modem
27
+ send_request( "device/mode", :mode => 0 )
28
+ end
29
+
30
+ def switch_to_debug
31
+ send_request( "device/mode", :mode => 1 )
32
+ end
33
+ end
34
+ module Modem
35
+ class << self
36
+ def send_modem( str )
37
+ sp = SerialPort.new('/dev/ttyUSB0',115200)
38
+ sp.write("#{str}\r\n")
39
+ sp.read_timeout = 100
40
+ sp.readlines
41
+ end
42
+
43
+ def switch_to_hilink
44
+ send_modem( "AT^U2DIAG=119" )
45
+ end
46
+ end
47
+ end
48
+ module Monitoring
49
+ class << self
50
+ def send_request( path, request = {} )
51
+ Hilink::send_request( "monitoring/#{path}", request )
52
+ end
53
+
54
+ def traffic_statistics
55
+ send_request( "traffic-statistics" )
56
+ end
57
+
58
+ def traffic_reset
59
+ send_request( "clear-traffic" )
60
+ end
61
+
62
+ def status
63
+ send_request( "status" )
64
+ end
65
+
66
+ def check_notifications
67
+ send_request( "check-notifications" )
68
+ end
69
+ end
70
+ end
71
+ module Network
72
+ class << self
73
+ def send_request( path, request = {} )
74
+ Hilink::send_request( "net/#{path}", request )
75
+ end
76
+
77
+ def current_plnm
78
+ send_request( "current-plnm" )
79
+ end
80
+
81
+ def set_connection_type( mode = 'auto', band: '-1599903692' )
82
+ nmode = case mode
83
+ when /2g/i
84
+ 1
85
+ when /3g/i
86
+ 2
87
+ else
88
+ 0
89
+ end
90
+ send_request( "network", {
91
+ :NetworkMode => nmode,
92
+ :NetworkBand => band } )
93
+ end
94
+ end
95
+ end
96
+ module SMS
97
+ class << self
98
+ def send_request( path, request = {} )
99
+ Hilink::send_request( "sms/#{path}", request )
100
+ end
101
+
102
+ def list( box = 1, site: 1, pref_unread: 0, count: 20 )
103
+ ret = send_request( "sms-list", {
104
+ :PageIndex => site,
105
+ :ReadCount => count,
106
+ :BoxType => box,
107
+ :SortType => 0,
108
+ :Ascending => 0,
109
+ :UnreadPreferred => pref_unread } )
110
+ if ret['Messages']['Message'].class == Hash
111
+ ret['Messages']['Message'] = [ ret['Messages']['Message'] ]
112
+ end
113
+ ret
114
+ end
115
+
116
+ def delete( index )
117
+ send_request( "delete-sms", { :Index => index } )
118
+ end
119
+
120
+ def send( number, message, index = -1 )
121
+ send_request( "send-sms", {
122
+ :Index => index,
123
+ :Phones => [number].flatten,
124
+ :Sca => "",
125
+ :Content => message,
126
+ :Length => message.length,
127
+ :Reserved => 1,
128
+ :Date => Time.now.strftime( "%Y-%m-%d %H:%M:%S" ) } )
129
+ end
130
+ end
131
+ end
132
+ module Dialup
133
+ class << self
134
+ def send_request( path, request = {} )
135
+ Hilink::send_request( "dialup/#{path}", request )
136
+ end
137
+
138
+ def connect
139
+ send_request( "dial", :Action => 1 )
140
+ end
141
+
142
+ def disconnect
143
+ send_request( "dial", :Action => 0 )
144
+ end
145
+ end
146
+ end
147
+ module USSD
148
+ class << self
149
+ def send_request( path, request = {} )
150
+ Hilink::send_request( "ussd/#{path}", request )
151
+ end
152
+
153
+ def send( str )
154
+ send_request( "send", :content => str, :codeType => "CodeType" )
155
+ end
156
+ end
157
+ end
158
+ end
159
+
160
+ #puts Hilink::USSD::send( "*100#" )
161
+ #exit
162
+
163
+ #puts Hilink::switch_to_debug
164
+ #exit
165
+
166
+ puts Hilink::Modem::switch_to_hilink
167
+ exit
168
+
169
+ puts Hilink::switch_to_modem
170
+ exit
171
+
172
+ puts Hilink::Dialup::connect
173
+ puts Hilink::Dialup::disconnect
174
+ exit
175
+
176
+
177
+ #puts Hilink::SMS::send( "93999699", "hello there" )
178
+ puts Hilink::SMS::list.inspect
179
+ Hilink::SMS::list['Messages']['Message'].each{|m|
180
+ puts m.inspect
181
+ Hilink::SMS::delete( m['Index'] )
182
+ }
183
+ exit
184
+
185
+ #puts Hilink::send_request( "device/information" )
186
+ message = "Hello from Smileplug"
187
+ =begin
188
+ puts Hilink::send_request( "sms/send-sms",
189
+ { :Index => -1,
190
+ :Phones => ["93999699"],
191
+ :Sca => '',
192
+ :Content => message,
193
+ :Length => message.length,
194
+ :Reserved => 1,
195
+ :Date => Time.now.strftime('%Y-%m-%d %H:%M:%S') } )
196
+ =end
197
+ #puts Hilink::send_request( "monitoring/check-notifications" )
198
+ #puts Hilink::send_request( "monitoring/status" )
199
+ puts Hilink::send_request( "sms/sms-list",
200
+ { :PageIndex => 1,
201
+ :ReadCount => 20,
202
+ :BoxType => 1,
203
+ :SortType => 0,
204
+ :Ascending => 0,
205
+ :UnreadPreferred => 0 } )
206
+ puts Hilink::send_request( "sms/delete-sms", { :Index => 20067 } )
207
+
208
+ exit
209
+
210
+ a = Document.new
211
+ ( a.add_element "Index" ).text = -1
212
+ a.write $stdout
213
+
214
+ exit
215
+
216
+ url = 'http://192.168.1.1/api/monitoring/status'
217
+ url = 'http://192.168.1.1/api/device/information'
218
+
219
+ # get the XML data as a string
220
+ xml_data = Net::HTTP.get_response(URI.parse(url)).body
221
+
222
+ puts xml_data.inspect
223
+ # extract event information
224
+ doc = REXML::Document.new(xml_data)
225
+
226
+ XPath.each( doc, "//response/*" ){|a|
227
+ puts a.inspect, a.text
228
+ }
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hilink
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Linus Gasser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-21 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
+ - lib/hilink.rb
48
+ homepage: http://rubygems.org/gems/hilink
49
+ licenses:
50
+ - GPLv3
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.2.0
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Accessing Huawei Hilink modems
72
+ test_files: []