Compare commits

..

No commits in common. "26c6b24c78cbdaa4c50b42cb689e70b2999eb664" and "ecebc72d3b036de7bf11f2c12fa13ac55a009a68" have entirely different histories.

1 changed files with 5 additions and 17 deletions

View File

@ -1,6 +1,6 @@
local mqtt = {} local mqtt = {}
local readVarint = function (conn, first_byte) local read_varint = function (conn, first_byte)
local b local b
if first_byte == nil then if first_byte == nil then
b = conn:read(1) b = conn:read(1)
@ -29,9 +29,9 @@ end
local MqttClient = {} local MqttClient = {}
function mqtt.open (address, port) function mqtt.open (address, port)
local conn, err = require("internet").open(address, port) local conn = require("internet").open(address, port)
if conn == nil then if conn == nil then
return nil, err return nil, "connection failed"
end end
return MqttClient:new(conn), nil return MqttClient:new(conn), nil
@ -42,9 +42,7 @@ function MqttClient:new (conn)
setmetatable(c, self) setmetatable(c, self)
self.__index = self self.__index = self
conn.readVarint = readVarint conn.read_varint = read_varint
conn:setTimeout(1)
c.conn = conn c.conn = conn
c.is_connecting = false c.is_connecting = false
c.is_connected = false c.is_connected = false
@ -60,7 +58,7 @@ function MqttClient:handle ()
local ptype, length, _ = string.unpack("B B", s) local ptype, length, _ = string.unpack("B B", s)
local length, err = self.conn:readVarint(length) local length, err = self.conn:read_varint(length)
if err ~= nil then if err ~= nil then
return err return err
end end
@ -144,11 +142,6 @@ function MqttClient:connect (username, password)
return err return err
end end
local _, err = self.conn:flush()
if err ~= nil then
return err
end
self.is_connecting = true self.is_connecting = true
return nil return nil
@ -170,11 +163,6 @@ function MqttClient:disconnect (reason)
return err return err
end end
local _, err = self.conn:flush()
if err ~= nil then
return err
end
self.is_connecting = false self.is_connecting = false
self.is_connected = false self.is_connected = false