mqtt-sn-ruby 0.0.11 → 0.0.12
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.
- checksums.yaml +4 -4
- data/bin/mqtt-sn-pub.rb +2 -10
- data/bin/mqtt-sn-sub.rb +1 -2
- data/lib/mqtt-sn-ruby.rb +20 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6e0d50a6122a25b13a777d12126907b20245da1
|
4
|
+
data.tar.gz: eb53d010e6489de64806a3542e1133c5e5bddbfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df1ab2aea08c3df21868bf4f55fad77f3b37dea31c72a5bb632a678d400127cc88ddaead67c783e584486499ae989eda75a40e1f2ce0db0c5fe2b01616101a49
|
7
|
+
data.tar.gz: fece50d44b9beccd91caf410275a27ef93aa06e0003bf8a5eb9319726eaf22696acbdfd8b1c33992b415aa605c1e942bcf9879ba611ab3dee9a8a67f4ea972c8
|
data/bin/mqtt-sn-pub.rb
CHANGED
@@ -22,8 +22,7 @@ OptionParser.new do |opts|
|
|
22
22
|
opts.on("-d", "--[no-]debug", "Produce Debug dump on console (false)") do |v|
|
23
23
|
options[:debug] = v
|
24
24
|
end
|
25
|
-
|
26
|
-
opts.on("-s", "--server uri", "URI of the MQTT-SN Server to connect to (udp://localhost:1883)") do |v|
|
25
|
+
opts.on("-s", "--server uri", "URI of the MQTT-SN Server to connect to. Example udp://localhost:1883. Default: Use Autodiscovery.") do |v|
|
27
26
|
options[:server_uri] = v
|
28
27
|
end
|
29
28
|
opts.on("-q", "--qos level", "QoS level (0)") do |v|
|
@@ -39,8 +38,7 @@ OptionParser.new do |opts|
|
|
39
38
|
options[:topic] = topic
|
40
39
|
end
|
41
40
|
end.parse!
|
42
|
-
|
43
|
-
#RubyProf.start
|
41
|
+
|
44
42
|
puts "MQTT-SN-PUB: #{options.to_json}"
|
45
43
|
begin
|
46
44
|
sn=MqttSN.new options
|
@@ -57,9 +55,3 @@ end
|
|
57
55
|
sn.disconnect if sn
|
58
56
|
|
59
57
|
puts "MQTT-SN-PUB Done."
|
60
|
-
|
61
|
-
#result = RubyProf.stop
|
62
|
-
|
63
|
-
# Print a flat profile to text
|
64
|
-
#printer = RubyProf::FlatPrinter.new(result)
|
65
|
-
#printer.print(STDOUT)
|
data/bin/mqtt-sn-sub.rb
CHANGED
@@ -22,8 +22,7 @@ OptionParser.new do |opts|
|
|
22
22
|
opts.on("-d", "--[no-]debug", "Produce Debug dump on console (false)") do |v|
|
23
23
|
options[:debug] = v
|
24
24
|
end
|
25
|
-
|
26
|
-
opts.on("-s", "--server uri", "URI of the MQTT-SN Server to connect to (udp://localhost:1883)") do |v|
|
25
|
+
opts.on("-s", "--server uri"," URI of the MQTT-SN Server to connect to. Example udp://localhost:1883. Default: Use Autodiscovery.") do |v|
|
27
26
|
options[:server_uri] = v
|
28
27
|
end
|
29
28
|
opts.on("-q", "--qos level", "QoS level (0)") do |v|
|
data/lib/mqtt-sn-ruby.rb
CHANGED
@@ -67,7 +67,7 @@ class MqttSN
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def log_flush
|
70
|
-
while not
|
70
|
+
while not log_empty?
|
71
71
|
sleep 0.1
|
72
72
|
end
|
73
73
|
end
|
@@ -125,7 +125,7 @@ class MqttSN
|
|
125
125
|
|
126
126
|
def initialize(hash={})
|
127
127
|
@options=hash #save these
|
128
|
-
@server_uri=hash[:server_uri]
|
128
|
+
@server_uri=hash[:server_uri]
|
129
129
|
@debug=hash[:debug]
|
130
130
|
@verbose=hash[:verbose]
|
131
131
|
@state=:inited
|
@@ -139,6 +139,17 @@ class MqttSN
|
|
139
139
|
@msg_id=1
|
140
140
|
@clients={}
|
141
141
|
@gateways={}
|
142
|
+
@autodiscovery=false
|
143
|
+
if @server_uri
|
144
|
+
puts "adding default gateway #{@server_uri}"
|
145
|
+
@gateways[0]={stamp: Time.now.to_i,uri: @server_uri, duration: 0, source: 'default', status: :ok}
|
146
|
+
pick_new_gateway
|
147
|
+
pp @gateways
|
148
|
+
else
|
149
|
+
puts "Autodiscovery Active"
|
150
|
+
@autodiscovery=true
|
151
|
+
end
|
152
|
+
|
142
153
|
@log_q = Queue.new #log queue :)
|
143
154
|
|
144
155
|
@log_t=Thread.new do
|
@@ -150,28 +161,25 @@ class MqttSN
|
|
150
161
|
@iq = Queue.new
|
151
162
|
@dataq = Queue.new
|
152
163
|
|
153
|
-
|
154
164
|
@bcast_s=MqttSN::open_multicast_send_port @bcast_port
|
155
165
|
@bcast=MqttSN::open_multicast_recv_port @bcast_port
|
156
166
|
|
157
167
|
@roam_t=Thread.new do
|
158
168
|
roam_thread @bcast
|
159
169
|
end
|
160
|
-
if
|
161
|
-
@client_t=Thread.new do
|
162
|
-
client_thread @s
|
163
|
-
end
|
164
|
-
else
|
170
|
+
if @forwarder
|
165
171
|
@s,@server,@port = MqttSN::open_port @server_uri
|
166
172
|
puts "Open port to Gateway: #{@server_uri}: #{@server},#{@port} -- local port: #{@local_port}"
|
167
173
|
@local_port=hash[:local_port]||1883
|
168
174
|
@s.bind("0.0.0.0",@local_port)
|
169
175
|
@bcast_period=60
|
176
|
+
else
|
177
|
+
@client_t=Thread.new do
|
178
|
+
client_thread
|
179
|
+
end
|
170
180
|
end
|
171
|
-
|
172
181
|
end
|
173
182
|
|
174
|
-
|
175
183
|
def forwarder_thread
|
176
184
|
if not @forwarder
|
177
185
|
raise "Cannot Forward if no Forwarder!"
|
@@ -771,7 +779,7 @@ class MqttSN
|
|
771
779
|
m
|
772
780
|
end
|
773
781
|
|
774
|
-
def client_thread
|
782
|
+
def client_thread
|
775
783
|
while true do
|
776
784
|
begin
|
777
785
|
if @active_gw_id and @gateways[@active_gw_id] and @gateways[@active_gw_id][:socket] #if we are connected...
|
@@ -856,7 +864,7 @@ class MqttSN
|
|
856
864
|
sleep @bcast_period
|
857
865
|
end
|
858
866
|
end
|
859
|
-
|
867
|
+
elsif @autodiscovery #client should try to find some gateways..
|
860
868
|
Thread.new do
|
861
869
|
while true do
|
862
870
|
send :searchgw #replies may or may not come -- even multiple!
|