mqtt-sn-ruby 0.1.7 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc76cd166972276f880d322760d35adc7720eaa1
4
- data.tar.gz: 2b0f87f21f19caf3e896ab35127a8f88d89aa756
3
+ metadata.gz: b2cf90277e54e38c81138fd1e4f540e9e074e34b
4
+ data.tar.gz: efffe5bdaaf339a20b16e8cacbf967b6cfafb915
5
5
  SHA512:
6
- metadata.gz: ab598d395528d9cce9126daf3238562be93decda49a6bb2afc8929262a43132d055927c170fa5be9a650ae9d5262217e17f906ef370a7a6b53a5afcccef9f6bd
7
- data.tar.gz: 9ac8e5e7bfb3b9c8c8dcc26df8c6432b176a986f77c022a1b7861eb5ddc1020f0bdc31b34972d15107aefd2edc2b4eae27c18c621c29f6eaa79d424a804dcaa2
6
+ metadata.gz: 1070a821c0eb64abba5873774a566b90050fd8a9c15381442dca19d14d7d6d6e09c1b91776aaa45a7160f24b1e74296e57afbf5974c2ca34ac9085ad3bf8c1ea
7
+ data.tar.gz: 55ecc32a4aca8acd05658c466a3303687ca5f19e91d579494f8346a0df90c06dd4bff397e376dfe643234db658317e35be684ed2f1462366f1224c8500a29439
data/lib/mqtt-sn-http.rb CHANGED
@@ -5,10 +5,15 @@ require "haml"
5
5
  require "coffee-script"
6
6
 
7
7
  def http_server options
8
+
8
9
  prev_t={}
9
- #@http_log=[]
10
- ports=Socket.getifaddrs.map { |i| i.addr.ip_address if i.addr.ipv4? }.compact
11
- puts "Starting HTTP services at port #{options[:http_port]}, server IPs: #{ports}"
10
+ ports=['127.0.0.1']
11
+ if Socket.method_defined? :getifaddrs
12
+ ports=Socket.getifaddrs.map { |i| i.addr.ip_address if i.addr.ipv4? }.compact
13
+ puts "Starting HTTP services at port #{options[:http_port]}, server IPs: #{ports}"
14
+ else
15
+ puts "Starting HTTP services at port #{options[:http_port]}."
16
+ end
12
17
  if File.directory? './http'
13
18
  $http_dir="http/"
14
19
  else
data/lib/mqtt-sn-ruby.rb CHANGED
@@ -136,7 +136,12 @@ class MqttSN
136
136
  ip = IPAddr.new(uri.host).hton + IPAddr.new("0.0.0.0").hton
137
137
  s = UDPSocket.new
138
138
  s.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, ip)
139
- s.setsockopt(:SOL_SOCKET, :SO_REUSEPORT, 1)
139
+ begin
140
+ s.setsockopt(:SOL_SOCKET, :SO_REUSEPORT, 1)
141
+ rescue #on raspian this is needed...
142
+ puts "WARNING: :SO_REUSEPORT not defined -- guessing it is 15 ;)"
143
+ s.setsockopt(:SOL_SOCKET, 15, 1)
144
+ end
140
145
  s.bind(Socket::INADDR_ANY, uri.port)
141
146
  s
142
147
  end
@@ -259,6 +264,7 @@ class MqttSN
259
264
  @clients[key]={ip:client_ip, port:client_port, socket: UDPSocket.new, uri: uri, state: :active, counter_send:0, last_send:0 , counter_recv:0, last_recv:0}
260
265
  c=@clients[key]
261
266
  puts "thread start for #{key}"
267
+
262
268
  @clients[key][:thread]=Thread.new(key) do |my_key|
263
269
  while true
264
270
  pacc=MqttSN::poll_packet_block(@clients[my_key][:socket]) #if we get data from server destined to our client
@@ -774,7 +780,15 @@ class MqttSN
774
780
 
775
781
  def self.parse_message r
776
782
  m=nil
783
+ if not r[0]
784
+ puts "Malformed empty packet #{r}"
785
+ return {}
786
+ end
777
787
  len=r[0].ord
788
+ if len!= r.size
789
+ puts "Malformed packet #{r}"
790
+ return {}
791
+ end
778
792
  case r[len-1].ord
779
793
  when 0x00
780
794
  status=:ok
@@ -941,7 +955,7 @@ class MqttSN
941
955
  end
942
956
  sleep @keepalive
943
957
  if @active_gw_id and @gateways[@active_gw_id] and @gateways[@active_gw_id][:socket] #if we are connected...
944
- send :ping, timeout: 2,expect: :pong do |status,message|
958
+ send :ping, timeout: 5,expect: :pong do |status,message|
945
959
  if status!=:ok
946
960
  note "Error:#{@id} no pong! -- sending disconnect to app"
947
961
  @state=:disconnected
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mqtt-sn-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Siitonen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-23 00:00:00.000000000 Z
11
+ date: 2014-11-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby toolkit for MQTT-SN, compatible with RSMB, command line tools and
14
14
  API