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

local fh = io.open("spider-image.bin", "rb")
local contents = fh:read("a")
fh:close()

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

	print("Connected and subscribed")
end

client = mqtt.client {
	uri = "mqtt.seeseepuff.be",
	id = "tool-test-image",
	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)

	
--while true do
assert(client:publish {
		topic = "spider/telemetry/camfeed",
		payload = "a" .. contents,
		qos = 0
	})
--end

print("Calling disconnect")
require("socket").sleep(0.002)
client:disconnect()

