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