Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lua/example/example_01.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ function callback(

print("Topic: " .. topic .. ", message: '" .. message .. "'")

mqtt_client2:publish(args.topic2, message)
time = socket.gettime()
if (time - last_time >= args.delay) then
-- print("PUBLISHING: " .. time .. " Delta: " .. time - last_time .. " Delay: " .. args.delay )
last_time = time
mqtt_client2:publish(args.topic2, message)
else
-- print("NOT READY: " .. time .. " Delta: " .. time - last_time .. " Delay: " .. args.delay )
end
end

-- ------------------------------------------------------------------------- --
Expand All @@ -47,10 +54,15 @@ args = lapp [[
-q,--port2 (default 1883) Publish MQTT server port number
-s,--topic1 (default test/1) Subscribe topic
-t,--topic2 (default test/2) Publish topic
-d,--delay (default 0) Minimum period between messages
]]

local MQTT = require("mqtt_library")

-- Globals accessed within callback
last_time = 0
time = 0

mqtt_client1 = MQTT.client.create(args.host1, args.port1, callback)
mqtt_client2 = MQTT.client.create(args.host2, args.port2)

Expand Down