-#!/usr/bin/env lua
+#!/usr/bin/lua
function getConfig(configname)
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
--- s = s .. '['..k..'] = ' .. dump(v) .. ','
- s = s .. dump(v) .. ','
+ s = s .. '['..k..'] = ' .. dump(v) .. ','
+-- s = s .. dump(v) .. ','
end
return s .. '} '
else
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
+function mqtt_pub(path,value)
+ printLog("Pub "..path.." "..value)
+ return mqtt_client:publish(path,value)
+end
+
function process_packet(packet)
local bytes={}
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)
+-- printLog(details)
end
- if mqtt_client then
+ if not (type=="unknown") then
mqtt_path=string.gsub(mqtt_topic,"{(.-)}",
function (name)
if name=="type" then
return '{'..name..'}'
end
end)
- mqtt_client:publish(mqtt_path,tx)
+
+ if not pcall(mqtt_pub,mqtt_path,tx) then
+ printLog('Reconnecting MQTT...')
+ mqtt_client:connect(mqtt_id)
+ end
+
end
end
end
end
inp = open_dump()
+
read_loop()