package.path = package.path .. ';./controller-host/?/init.lua;./controller-host/?.lua'
local mqtt = require("mqtt")
local client

local function onConnect(connack)
	if connack.rc ~= 0 then
		print("Connection to broker failed:", connack:reason_string())
		os.exit(1)
	end

	--local length = 1000000
	-- 500000
	local length = 1000000
	-- 100000
	--while true do
	local payload = string.rep("b", length)
	--length = length + 100000
	
	assert(client:publish {
		topic = "spider/telemetry/camfeed",
		payload = payload,
		qos = 0
	})
	--end

	print("Connected and subscribed")
end

client = mqtt.client {
	uri = "mqtt.seeseepuff.be",
	username = "tools",
	clean = true,
	reconnect = 5,
	version = mqtt.v311,
}

client:on {
	connect = onConnect,
	message = onMessage,
	error = function(err)
		print("MQTT client error:", err)
	end,
}

mqtt.run_ioloop(client)
