-
Notifications
You must be signed in to change notification settings - Fork 1
/
pubmqtt.lua
49 lines (47 loc) · 1.16 KB
/
pubmqtt.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
local M={}
M.publ = function(answer, call)
mod.publish = false
local tobr = {}
local senddat = function()
tobr.heap = ""..node.heap()
local sendMQ
local kkk,vvv
local getd = coroutine.create(function()
for kkk, vvv in pairs(tobr) do
sendMQ(kkk, vvv)
coroutine.yield()
end
-- collectgarbage()
if #_G.answer ~= 0 then
maketb()
elseif call then
uart.alt(1)
uart.setup(0, 9600, 8, uart.PARITY_NONE, uart.STOPBITS_1, 0)
M.publ,sendMQ, getd, M = nil, nil, nil, nil
mod.publish = true
package.loaded["pubmqtt"]=nil
call()
end
end)
sendMQ = function(k, v)
m:publish("from"..myClient.."/"..k,v,0,0,
function(con)
coroutine.resume(getd)
end)
end
coroutine.resume(getd)
end
local maketb = function()
local k,v,kk,vv
for k, v in pairs(_G.answer) do
for kk,vv in pairs(v) do
tobr[kk] = vv
print(kk, vv)
end
_G.answer[k] = nil
end
senddat()
end
maketb()
end
return M