Class: HuaweiE3131
- Inherits:
-
Object
- Object
- HuaweiE3131
- Defined in:
- lib/huawei_e3131.rb
Overview
HOWTO: Switching the Huawei E3131 to network controller mode
-
Plug in the Huawei E3131 dongle
-
‘sudo apt-get install sg3-utils`
-
‘sudo /usr/bin/sg_raw /dev/sr0 11 06 20 00 00 00 00 00 01 00`
-
edit /etc/network/interfaces and add the following:
allow-hotplug eth1 iface eth1 inet dhcp
-
observe IP address 192.168.1.1 is now reachable from eth1
credit: [Huawei E3131 on Wheezy](www.raspberrypi.org/forums/viewtopic.php?p=210958)
Instance Method Summary collapse
- #check_notifications ⇒ Object (also: #notifications)
- #connection_status ⇒ Object (also: #status)
-
#initialize(host = '192.168.1.1', callback: nil, autostart: false) ⇒ HuaweiE3131
constructor
A new instance of HuaweiE3131.
- #messages ⇒ Object
-
#read(idx = 1) ⇒ Object
read an SMS message.
- #sms_count ⇒ Object (also: #count)
-
#start ⇒ Object
continuously check for new messages.
- #stop ⇒ Object
Constructor Details
#initialize(host = '192.168.1.1', callback: nil, autostart: false) ⇒ HuaweiE3131
Returns a new instance of HuaweiE3131.
28 29 30 31 32 33 34 |
# File 'lib/huawei_e3131.rb', line 28 def initialize(host='192.168.1.1', callback: nil, autostart: false) @host, @callback = host, callback start if autostart end |
Instance Method Details
#check_notifications ⇒ Object Also known as: notifications
36 37 38 39 40 |
# File 'lib/huawei_e3131.rb', line 36 def check_notifications() query 'monitoring/check-notifications' end |
#connection_status ⇒ Object Also known as: status
44 45 46 47 48 |
# File 'lib/huawei_e3131.rb', line 44 def connection_status() query 'monitoring/status' end |
#messages ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/huawei_e3131.rb', line 52 def () = {PageIndex: 1, ReadCount: 20, BoxType: 1, SortType: 0, Ascending: 0, UnreadPreferred: 0} a = RexleBuilder.new(, debug: false).to_a a[0] = 'request' xml = Rexle.new(a).xml(declaration: false) response = RestClient.post "http://#{@host}/api/sms/sms-list", xml.to_s, :content_type => "text/xml" Rexle.new(response.body).root.xpath('Messages/Message').map do || .xpath('./*').inject({}) do |r,x| x.text ? r.merge(x.name => x.text.unescape) : r end end end |
#read(idx = 1) ⇒ Object
read an SMS message
76 77 78 |
# File 'lib/huawei_e3131.rb', line 76 def read(idx=1) [idx.to_i-1] end |
#sms_count ⇒ Object Also known as: count
80 81 82 83 84 |
# File 'lib/huawei_e3131.rb', line 80 def sms_count() query 'sms/sms-count' end |
#start ⇒ Object
continuously check for new messages
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/huawei_e3131.rb', line 90 def start() unread = notifications()['UnreadMessage'].to_i @thread = Thread.new do loop do = notifications()['UnreadMessage'].to_i if > unread then @callback.call if @callback unread = end sleep 3 end end 'checking for new message every 3 seconds ...' end |
#stop ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/huawei_e3131.rb', line 115 def stop() @thread.stop @thread.kill 'message checker stopped' end |