MQTT with TLS
Posted: Thu Apr 13, 2017 4:00 am
Hi guys, I'm not able to make the esp8266 deals with mqtts brokers (not even the test.moquito.org ones).
I compiled my custom NodeMCU with TLS (and its dependancy NET) module included:
With vanilla MQTT I had no issue, I built a simple Node.js broker and everything is fine.
I don't get how to use MQTT on top of TSL, from docs isn't clear to me how to do it. Can someone help me?
This is the code I'm using so far (for sure it's not the sound way to do it, since it's not clear to me how to manage TLS):
I've got this:
Thanks for the help.
I compiled my custom NodeMCU with TLS (and its dependancy NET) module included:
Code: Select all
#define LUA_USE_MODULES_ADC
#define LUA_USE_MODULES_BIT
#define LUA_USE_MODULES_CJSON
#define LUA_USE_MODULES_CRYPTO
#define LUA_USE_MODULES_DHT
#define LUA_USE_MODULES_ENCODER
#define LUA_USE_MODULES_FILE
#define LUA_USE_MODULES_GPIO
#define LUA_USE_MODULES_HTTP
#define LUA_USE_MODULES_I2C
#define LUA_USE_MODULES_MQTT
#define LUA_USE_MODULES_NET
#define LUA_USE_MODULES_NODE
#define LUA_USE_MODULES_OW
#define LUA_USE_MODULES_RTCTIME
#define LUA_USE_MODULES_SPI
#define LUA_USE_MODULES_TLS
#define LUA_USE_MODULES_TMR
#define LUA_USE_MODULES_UART
#define LUA_USE_MODULES_WIFI
With vanilla MQTT I had no issue, I built a simple Node.js broker and everything is fine.
I don't get how to use MQTT on top of TSL, from docs isn't clear to me how to do it. Can someone help me?
This is the code I'm using so far (for sure it's not the sound way to do it, since it's not clear to me how to manage TLS):
Code: Select all
function startMQTT()
print("starting MQTT client")
local _id = "nodemcu"
local _user = "user"
local _password = "password
local _keep_alive = 60
local _broker = "test.mosquito.org"
local _port = 8883
local _use_SSL = true
local _auto_reconnect = true
local _clean_session = false
tls.cert.verify(true)
_client = mqtt.Client(_id, _keep_alive, _user, _password, _clean_session)
_client:lwt("/lwt", _id .. " went offline", 0, 0)
_client:connect(_broker, _port, 1, 1,
function(client)
print("connected")
local _topic = "/topic"
local _qos = 0
local _retain = false
client:subscribe(_topic, _qos, function(conn)
print("subscribed to" .. _topic)
end)
end
,
function(client, reason)
print("failed, reason: " .. reason)
end
)
_client:on("offline", function(client)
print("offline")
end)
_client:on("message", function(client, topic, data)
print(topic .. ": ")
if data ~= nil then
print(data)
end
end)
end
I've got this:
Code: Select all
PANIC: unprotected error in call to Lua API (mqtt_client.lua:13: attempt to index global 'tls)
Thanks for the help.