mqtt-sn-ruby 0.1.6 → 0.1.7
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/http/coffee/mqtt-sn-sub.coffee +27 -1
- data/http/haml/mqtt-sn-sub.haml +2 -0
- data/http/json/action.rb +8 -4
- data/http/json/gateways.rb +1 -0
- data/lib/mqtt-sn-http.rb +2 -3
- data/lib/mqtt-sn-ruby.rb +12 -2
- 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: fc76cd166972276f880d322760d35adc7720eaa1
         | 
| 4 | 
            +
              data.tar.gz: 2b0f87f21f19caf3e896ab35127a8f88d89aa756
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ab598d395528d9cce9126daf3238562be93decda49a6bb2afc8929262a43132d055927c170fa5be9a650ae9d5262217e17f906ef370a7a6b53a5afcccef9f6bd
         | 
| 7 | 
            +
              data.tar.gz: 9ac8e5e7bfb3b9c8c8dcc26df8c6432b176a986f77c022a1b7861eb5ddc1020f0bdc31b34972d15107aefd2edc2b4eae27c18c621c29f6eaa79d424a804dcaa2
         | 
| @@ -3,9 +3,35 @@ now=0 | |
| 3 3 |  | 
| 4 4 | 
             
            update_status = (data) ->
         | 
| 5 5 | 
             
              console.log data.jes
         | 
| 6 | 
            -
              console.log data. | 
| 6 | 
            +
              console.log data.clients
         | 
| 7 7 | 
             
              #console.log data.logpos
         | 
| 8 8 | 
             
              now=data.now
         | 
| 9 | 
            +
              html="<table><tr><th>uri</th><th>state</th><th>stamp</th><th>last_send</th><th>counter_send</th><th>last_recv</th><th>counter_recv</th></tr>"
         | 
| 10 | 
            +
              for k,v of data.clients
         | 
| 11 | 
            +
                html+="<tr>"
         | 
| 12 | 
            +
                html+="<td>#{k}</td>"
         | 
| 13 | 
            +
                html+="<td>#{v.state}</td>"
         | 
| 14 | 
            +
                html+="<td>#{now-v.stamp}</td>"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
             | 
| 17 | 
            +
             | 
| 18 | 
            +
                if v.last_send
         | 
| 19 | 
            +
                  html+="<td>#{now-v.last_send}</td>"
         | 
| 20 | 
            +
                else
         | 
| 21 | 
            +
                  html+="<td></td>"
         | 
| 22 | 
            +
                html+="<td>#{v.counter_send}</td>"
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                if v.last_recv
         | 
| 25 | 
            +
                  html+="<td>#{now-v.last_recv}</td>"
         | 
| 26 | 
            +
                else
         | 
| 27 | 
            +
                  html+="<td></td>"
         | 
| 28 | 
            +
                html+="<td>#{v.counter_recv}</td>"
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                html+="</tr>"
         | 
| 31 | 
            +
              html+="</table>"
         | 
| 32 | 
            +
              #console.log html
         | 
| 33 | 
            +
              $(".clients").html(html)
         | 
| 34 | 
            +
                
         | 
| 9 35 | 
             
              html="<table><tr><th>gw_id</th><th>uri</th><th>source</th><th>stamp</th><th>last_use</th><th>last_ping</th><th>last_send</th><th>counter_send</th><th>last_recv</th><th>counter_recv</th></tr>"
         | 
| 10 36 | 
             
              for k,v of data.gateways
         | 
| 11 37 | 
             
                k=parseInt(k,10)
         | 
    
        data/http/haml/mqtt-sn-sub.haml
    CHANGED
    
    
    
        data/http/json/action.rb
    CHANGED
    
    | @@ -4,14 +4,18 @@ | |
| 4 4 |  | 
| 5 5 | 
             
            def json_action request,args,session,event
         | 
| 6 6 | 
             
              #$sn.pub msg: "jees123", server_uri: "udp://20.20.20.21:1882"
         | 
| 7 | 
            -
              puts "agrs:#{args}"
         | 
| 8 7 | 
             
              topic="top"
         | 
| 9 8 | 
             
              msg=args['msg']||"test_message"
         | 
| 10 9 | 
             
              topic=args['topic']||"XX"
         | 
| 11 10 | 
             
              qos=(args['qos']||0).to_i
         | 
| 12 | 
            -
               | 
| 13 | 
            -
             | 
| 14 | 
            -
               | 
| 11 | 
            +
              if args['retain']=="true"
         | 
| 12 | 
            +
                retain=true
         | 
| 13 | 
            +
              else
         | 
| 14 | 
            +
                retail=nil
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
              pp args
         | 
| 17 | 
            +
              pp retain
         | 
| 18 | 
            +
              $sn.publish topic, msg, qos: qos, retain: retain
         | 
| 15 19 | 
             
              data={jee: 123}
         | 
| 16 20 | 
             
              return ["text/json",data]
         | 
| 17 21 | 
             
            end
         | 
    
        data/http/json/gateways.rb
    CHANGED
    
    
    
        data/lib/mqtt-sn-http.rb
    CHANGED
    
    | @@ -28,7 +28,7 @@ def http_server options | |
| 28 28 | 
             
                      req=request[1]
         | 
| 29 29 | 
             
                      req="/#{http_app}.html" if req=="/" or req=="/index.htm" or req=="/index.html"
         | 
| 30 30 | 
             
                      req,argss=req.split "\?"
         | 
| 31 | 
            -
                      puts "req: #{req}, agss:#{argss}"
         | 
| 31 | 
            +
                      #puts "req: #{req}, agss:#{argss}"
         | 
| 32 32 | 
             
                      args={}
         | 
| 33 33 | 
             
                      if argss
         | 
| 34 34 | 
             
                        argss.split("&").each do |a|
         | 
| @@ -38,7 +38,7 @@ def http_server options | |
| 38 38 | 
             
                          end
         | 
| 39 39 | 
             
                        end
         | 
| 40 40 | 
             
                      end
         | 
| 41 | 
            -
                      puts "req: #{req}, args:#{args}"
         | 
| 41 | 
            +
                      #puts "req: #{req}, args:#{args}"
         | 
| 42 42 | 
             
                      if req[/\.html$/] and File.file?(fn="#{$http_dir}haml#{req.gsub('.html','.haml')}")
         | 
| 43 43 | 
             
                        contents = File.read(fn)
         | 
| 44 44 | 
             
                        response=Haml::Engine.new(contents).render
         | 
| @@ -68,7 +68,6 @@ def http_server options | |
| 68 68 | 
             
                          end
         | 
| 69 69 | 
             
                        end
         | 
| 70 70 | 
             
                        if type!="text/event-stream" and status=="200 OK"
         | 
| 71 | 
            -
                          puts  "json_#{act} request,args,0,0   '#{req},#{args}'" 
         | 
| 72 71 | 
             
                          begin
         | 
| 73 72 | 
             
                            type,response=eval "json_#{act} req,args,0,0"  #event handlers get called with zero session => init :)
         | 
| 74 73 | 
             
                          rescue => e
         | 
    
        data/lib/mqtt-sn-ruby.rb
    CHANGED
    
    | @@ -256,7 +256,7 @@ class MqttSN | |
| 256 256 | 
             
                    key="#{client_ip}:#{client_port}"
         | 
| 257 257 | 
             
                    if not @clients[key]
         | 
| 258 258 | 
             
                      uri="udp://#{client_ip}:#{client_port}"
         | 
| 259 | 
            -
                      @clients[key]={ip:client_ip, port:client_port, socket: UDPSocket.new, uri: uri, state: :active | 
| 259 | 
            +
                      @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 260 | 
             
                      c=@clients[key]
         | 
| 261 261 | 
             
                      puts "thread start for #{key}"
         | 
| 262 262 | 
             
                      @clients[key][:thread]=Thread.new(key) do |my_key|
         | 
| @@ -268,6 +268,11 @@ class MqttSN | |
| 268 268 | 
             
                          _,port,_,_ = @clients[my_key][:socket].addr
         | 
| 269 269 | 
             
                          dest="#{@server}:#{port}"
         | 
| 270 270 | 
             
                          logger "sc %-24.24s <- %-24.24s | %s",@clients[my_key][:uri],@gateways[@active_gw_id][:uri],mm.to_json
         | 
| 271 | 
            +
                          @gateways[@active_gw_id][:last_recv]=Time.now.to_i
         | 
| 272 | 
            +
                          @gateways[@active_gw_id][:counter_recv]+=1
         | 
| 273 | 
            +
                          @clients[my_key][:last_send]=Time.now.to_i
         | 
| 274 | 
            +
                          @clients[my_key][:counter_send]+=1
         | 
| 275 | 
            +
             | 
| 271 276 | 
             
                          case mm[:type]
         | 
| 272 277 | 
             
                          when :disconnect
         | 
| 273 278 | 
             
                            @clients[my_key][:state]=:disconnected
         | 
| @@ -289,6 +294,10 @@ class MqttSN | |
| 289 294 | 
             
                    sbytes=@clients[key][:socket].send(r, 0, @server, @port) # to rsmb -- ok as is
         | 
| 290 295 | 
             
                    _,port,_,_ = @clients[key][:socket].addr
         | 
| 291 296 | 
             
                    dest="#{@server}:#{port}"
         | 
| 297 | 
            +
                    @gateways[@active_gw_id][:last_send]=Time.now.to_i
         | 
| 298 | 
            +
                    @gateways[@active_gw_id][:counter_send]+=1
         | 
| 299 | 
            +
                    @clients[key][:last_recv]=Time.now.to_i
         | 
| 300 | 
            +
                    @clients[key][:counter_recv]+=1
         | 
| 292 301 | 
             
                    begin 
         | 
| 293 302 | 
             
                      if @active_gw_id
         | 
| 294 303 | 
             
                        logger "cs %-24.24s -> %-24.24s | %s", @clients[key][:uri],@gateways[@active_gw_id][:uri],m.to_json
         | 
| @@ -815,7 +824,8 @@ class MqttSN | |
| 815 824 | 
             
                  end
         | 
| 816 825 | 
             
                  qos=(flags>>5)&0x03
         | 
| 817 826 | 
             
                  qos=-1 if qos==3
         | 
| 818 | 
            -
                  m={type: :publish, qos: qos, topic_id: topic_id, topic_type:topic_type, topic: topic, msg_id: msg_id, msg: msg,status: :ok}
         | 
| 827 | 
            +
                  m={type: :publish, qos: qos, topic_id: topic_id, topic_type:topic_type, topic: topic, msg_id: msg_id, msg: msg,flags: flags, status: :ok}
         | 
| 828 | 
            +
                  m[:retain]=true if flags & RETAIN_FLAG == RETAIN_FLAG        
         | 
| 819 829 | 
             
                when PUBREL_TYPE
         | 
| 820 830 | 
             
                  msg_id=(r[2].ord<<8)+r[3].ord
         | 
| 821 831 | 
             
                  m={type: :pub_rel, msg_id: msg_id, status: :ok}
         |