module(...,package.seeall)

require"luatyuniotssl"

local qos1cnt = 1

--[[
print
  ӡӿڣļедӡtestǰ׺
  
ֵ
]]
local function print(...)
	_G.print("test",...)
end

--[[
pubqos1testackcb
  1qosΪ1ϢյPUBACKĻص
  
		usertagmqttclient:publishʱusertag
		resulttrueʾɹfalsenilʾʧ
ֵ
]]
local function pubqos1testackcb(usertag,result)
	print("pubqos1testackcb",usertag,result)
	sys.timer_start(pubqos1test,20000)
	qos1cnt = qos1cnt+1
end

--[[
pubqos1test
  1qosΪ1Ϣ
  
ֵ
]]
function pubqos1test()
	--ע⣺ڴ˴Լȥpayloadݱ룬luatyuniotsslвpayloadκαת
	luatyuniotssl.publish("qos1data",1,pubqos1testackcb,"publish1test_"..qos1cnt)
end

--[[
rcvmessage
  յPUBLISHϢʱĻص
  
		topicϢ⣨gb2312룩
		payloadϢأԭʼ룬յpayloadʲôݣʲôݣûκαת
		qosϢȼ
ֵ
]]
local function rcvmessagecb(topic,payload,qos)
	print("rcvmessagecb",topic,payload,qos)
end

--[[
connectedcb
  MQTT CONNECTɹص
  		
ֵ
]]
local function connectedcb()
	print("connectedcb")
	--һqosΪ1Ϣ
	pubqos1test()
end

--עMQTT CONNECTɹصյPUBLISHϢص
luatyuniotssl.regcb(connectedcb,rcvmessagecb)

