projects
/
openhab-process.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9e115a0
)
Timeout handling fixed.
author
Roman Bazalevskiy
<rvb@rvb.name>
Sun, 19 Mar 2017 21:24:50 +0000
(
00:24
+0300)
committer
Roman Bazalevskiy
<rvb@rvb.name>
Sun, 19 Mar 2017 21:24:50 +0000
(
00:24
+0300)
mqtt-bt/scan-beacons
patch
|
blob
|
history
diff --git
a/mqtt-bt/scan-beacons
b/mqtt-bt/scan-beacons
index 3c6a230b2e4151ee46887173fe9560672c359f5f..1709e9323cf436fd8de576e101cdd97518aaf977 100644
(file)
--- a/
mqtt-bt/scan-beacons
+++ b/
mqtt-bt/scan-beacons
@@
-87,8
+87,8
@@
function dump(o)
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
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
end
return s .. '} '
else
@@
-100,6
+100,11
@@
function trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
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={}
function process_packet(packet)
local bytes={}
@@
-155,12
+160,9
@@
function process_packet(packet)
else
type='unknown'
details=dump(bytes)
else
type='unknown'
details=dump(bytes)
- printLog(details)
+
--
printLog(details)
end
end
- if mqtt_client then
- if not mqtt_client.connected then
- mqtt_client:connect(mqtt_id)
- end
+ if not (type=="unknown") then
mqtt_path=string.gsub(mqtt_topic,"{(.-)}",
function (name)
if name=="type" then
mqtt_path=string.gsub(mqtt_topic,"{(.-)}",
function (name)
if name=="type" then
@@
-171,7
+173,12
@@
function process_packet(packet)
return '{'..name..'}'
end
end)
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
end
end
@@
-218,7
+225,9
@@
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()
+
read_loop()
read_loop()