As the title says... Chat on...
User avatar
By aterocana
#65044 Thanks for the help. Update:
Running this code:
Code: Select allfunction startMQTT()
    print("starting MQTT client")
    local _id = "nodemcu"
    local _keep_alive = 60
    local _broker = "broker_address"
    local _port = 8443
    local _use_SSL = true
    local _auto_reconnect = true
    local _clean_session = false

    _client = mqtt.Client(_id, _keep_alive, _user, _password, _clean_session)
    _client:lwt("/lwt", _id .. " went offline", 0, 0)

    verify()
    _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

function verify()
    print("verifying")
    tls.cert.verify([[-----BEGIN CERTIFICATE-----
    MIIDyDCCArACCQCFvizh52kCMDANBgkqhkiG9w0BAQsFADCBpTELMAkGA1UEBhMC
    SVQxDjAMBgNVBAgMBUN1bmVvMRAwDgYDVQQHDAdGb3NzYW5vMRUwEwYDVQQKDAxE
    b21vdGljYUxhYnMxETAPBgNVBAsMCFJlc2VhcmNoMR4wHAYDVQQDDBVsb2NhbGhv
    c3QubG9jYWxkb21haW4xKjAoBgkqhkiG9w0BCQEWG20uZG9taW5pY2lAZG9tb3Rp
    Y2FsYWJzLmNvbTAeFw0xNzA0MTMxMzE2MzdaFw0xODA0MTMxMzE2MzdaMIGlMQsw
    CQYDVQQGEwJJVDEOMAwGA1UECAwFQ3VuZW8xEDAOBgNVBAcMB0Zvc3Nhbm8xFTAT
    BgNVBAoMDERvbW90aWNhTGFiczERMA8GA1UECwwIUmVzZWFyY2gxHjAcBgNVBAMM
    FWxvY2FsaG9zdC5sb2NhbGRvbWFpbjEqMCgGCSqGSIb3DQEJARYbbS5kb21pbmlj
    aUBkb21vdGljYWxhYnMuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC
    AQEAwM/cLcKR/DIYXdvWEOq+C4drOfPMoWus19kKNR8GuafPbhPRC1I+YixhLT/U
    X8GZfuuxYiJ0iUJo04ApmvA1xSw+QSRDZv9K+1JEyWD0Dj0ZdGJBiHX/dzqb7wrT
    ua6Yel/9QhUGmCA36mGycvdA/TlKsW8Oopa544eE2Jlf9dBBnECTKVhCJ8bO6Okm
    kHkNXqu16hj4xByjbaE29q+YYUb9DH/u0a9BNIsjF0PYREAOUJ8Q0NaJX2OIvO2p
    elmD8WKOOf54Ks7AVDAZ9vyMSe412UDYRnoJ86cNDZJvWa7SzZy6TrlgfZejUBcZ
    ZfvtyAEQH+cClgTwwBQkD0CdrwIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQCvEwEd
    BZ0hpm91oBtUgGhl9cNJ7LtHpUPN6thZzYOCt+s8sJJhl8+B3boPFt20FFA7ckUd
    kpjEIlSbTpyRCyeNANkMvvuNyy9gTp8AgMCJ+pQ3aNrrT1SF6pHLCyakzA2VM/md
    afcBMWnv/pGkK9qy4J+bc5krvrwsko8+J06RxxClChi7F6n6bKZ7r8SXsMIWae45
    QJUViHCLl/uaj973kZ3UVwrcUHCABb3tbqNfkEOOOkGUT6DnrOhtaCwx4s8/lnUU
    LeJsMS82OPfsv+CM+vw3ejEf5rCypDwCR6SILqDUG0aSAULt1HFyj83FsaInqV2E
    0d+V9JHQxhg5dgUa
    -----END CERTIFICATE-----]])
    print("verification done")
end


The broker is working since I have success with other devices and the esp8266 is able to connect to it using 1883 port and disabling TLS in the broker.
What I get is:
Code: Select allstarting MQTT client
verifying
verification done
failed, reason: -5


I really need the MQTT over TLS feature. Should I use something else other than Nodemcu for that, at this point? Thank you.