Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 66 lines (52 sloc) 1.31 KB
#!./Selene
-- Simple MQTT receiving test
unpack = unpack or table.unpack
if not table.pack then
function table.pack (...)
return {n=select('#',...); ...}
end
end
--[[
-- Errors code test
print 'Error code handling test'
print '------------------------'
code = SelMQTT.ErrConst("MQTTCLIENT_DISCONNECTED")
print(code, SelMQTT.StrError(code))
--]]
print '\nTesting broker connection'
print '--------------------------'
-- Callbacks
function handle_tata( topic, msg )
print("Lua received t:'" .. topic .."' m:'".. msg .."'")
SelShared.set('tata', msg)
return true
end
-- Update functions
function update_tata()
print("Trigger for Tata :", SelShared.get('tata'))
end
function update_toto()
print("Trigger for toto :", SelShared.get('toto'))
end
-- Connection, subscription and finally waiting for messages
Brk, err = SelMQTT.connect( "tcp://localhost:1883", { reliable=false } )
if not Brk then
print( err )
return
end
_, err = Brk:subscribe( {
{ topic = "tata/+/truc", func=handle_tata, trigger=update_tata, trigger_once=false, qos=SelMQTT.QoSConst("QoS0") },
{ topic = "toto", trigger=update_toto, trigger_once=true }
} )
if err then
print( err )
return
end
while true do
local rt = table.pack( Selene.WaitFor() )
for _,ret in ipairs(rt) do
if type(ret) == 'function' then
ret()
end
end
end