hilink 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +52 -0
  3. metadata +3 -3
  4. data/lib/hilink.rb +0 -160
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4cba55d74717973ed7b5afc525491281eaf43a5a
4
- data.tar.gz: 1238b03a6e15a8efde8c5971c2f7ce503feed1bd
3
+ metadata.gz: 1f36911eae5aa21b7a930202fcda969270b4b200
4
+ data.tar.gz: 6df1daade018152d51cc2a9f2d75ffff792f1994
5
5
  SHA512:
6
- metadata.gz: efae533d427e1d05c37a76aa19cfa37039a449bd9cd502fa65592c16b678308e8162c1e70302f4422d35bfca2ae217c5c5c11b4dbac78f81c8d3d2989c6781cd
7
- data.tar.gz: 61d0a903e2397a8dce0e117c017dfca38b5bc134e5bd6de2e4cc73687f4b6655a8a37d564615b65cbe9a261d4133dd1fa22fbb889cbba33286b50e782d1939aa
6
+ metadata.gz: efd5c13d32cec536d87b4fef058d89816da22b416cbad73859e58f19f1ff00ef6ec74f55850f6e08959ddee7787a6f8233cd2d83703557ca115919c5cbcadc2d
7
+ data.tar.gz: 0ca7899a7855b18365da8caf5b9fdaf485a713d3169efa5333759b20c455e750e04ddc232e3cd7b300363138c217a80a287dcf9d960f9fa5552c5896bf466146
@@ -0,0 +1,52 @@
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
+ ## Commands
19
+
20
+ Each command is a module inside of Hilink. There are different modules:
21
+
22
+ - Monitoring - return different status of the modem
23
+ - Network - change 2g / 3g network
24
+ - SMS - send, receive and list
25
+ - Dialup - (dis)connect from network
26
+ - Modem - useful only when it is in modem-mode
27
+ - USSD - *Doesn't work due to Huawei restriction*
28
+
29
+ The Hilink-module itself has three methods:
30
+ - `send_request( path, request = {} )` - generates a valid XML-request and return
31
+ the result as a hash
32
+ - `switch_to_modem` - sends the command so the key behaves as a modem
33
+ - `switch_to_debug` - according to web-interface, no difference visible
34
+
35
+ ### Monitoring
36
+
37
+ You can monitor different things:
38
+
39
+ - `traffic_statistics` - per-connection and total usage
40
+ - `traffic_reset` - set all to 0
41
+ - `status` - shows whether connected or not
42
+ - `check_notifications`
43
+
44
+ ### Network
45
+
46
+ - `set_connection_type( mode = 'auto', band = '-1599903692' )` - mode
47
+ can be 'auto', '2g' or '3g'
48
+ - `current_plnm` - get actual connection
49
+
50
+ ### SMS
51
+
52
+ - `list`
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hilink
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Linus Gasser
@@ -44,8 +44,8 @@ executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
- - lib/hilink.rb
48
- homepage: http://rubygems.org/gems/hilink
47
+ - README.md
48
+ homepage: https://github.com/ineiti/Hilink
49
49
  licenses:
50
50
  - GPLv3
51
51
  metadata: {}
@@ -1,160 +0,0 @@
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
- return :error => "Sorry, doesn't work!"
155
- send_request( "send", :content => str, :codeType => "CodeType" )
156
- end
157
- end
158
- end
159
- end
160
-