MQTT timeout/disconnect processing.
authorRoman Bazalevskiy <rvb@rvb.name>
Sun, 19 Mar 2017 20:34:30 +0000 (23:34 +0300)
committerRoman Bazalevskiy <rvb@rvb.name>
Sun, 19 Mar 2017 20:34:30 +0000 (23:34 +0300)
mqtt-bt/scan-beacons

index 98c39937d8efedb096c89c9439ef68a29c297ba1..3c6a230b2e4151ee46887173fe9560672c359f5f 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/env lua
+#!/usr/bin/lua
 
 function getConfig(configname)
 
 
 function getConfig(configname)
 
@@ -151,13 +151,16 @@ function process_packet(packet)
       end
       if type=="ibeacon" then
         printLog(string.format("{type:'ibeacon',mac:'%s',uuid:'%s',major:'%s',minor:'%s',power:%d,tx:%d}",mac,uuid,major,minor,power,tx))
       end
       if type=="ibeacon" then
         printLog(string.format("{type:'ibeacon',mac:'%s',uuid:'%s',major:'%s',minor:'%s',power:%d,tx:%d}",mac,uuid,major,minor,power,tx))
-        details=uuid..'/'..major..'/'..minor..'/'
+        details=uuid..'/'..major..'/'..minor
       else
         type='unknown'
         details=dump(bytes)
         printLog(details)
       end
       if mqtt_client then
       else
         type='unknown'
         details=dump(bytes)
         printLog(details)
       end
       if mqtt_client then
+        if not mqtt_client.connected then
+          mqtt_client:connect(mqtt_id)
+        end
         mqtt_path=string.gsub(mqtt_topic,"{(.-)}", 
           function (name) 
             if name=="type" then
         mqtt_path=string.gsub(mqtt_topic,"{(.-)}", 
           function (name) 
             if name=="type" then
@@ -215,7 +218,6 @@ if mqtt_host then
   if mqtt_user then
     mqtt_client:auth(mqtt_user, mqtt_passwd)
   end
   if mqtt_user then
     mqtt_client:auth(mqtt_user, mqtt_passwd)
   end
-  mqtt_client:connect(mqtt_id)
 end
 
 inp = open_dump()
 end
 
 inp = open_dump()