simple mqtt and wss

  • Hello there,
    I want to use a little bit more secure solution for mqtt communicaton, but I am having some trouble to establish the connection. Probably some syntax error, but I alredy tried out all of the possibilites. (probably not all of it)
    Its always return -1
    The cert is provided externally, and its TLSv1.2.
    so the connection string looks like this:

    client = MQTTClient("GT01", "wss://", user=b"user", password=b"password", ssl=True, ssl_params = {'cert_reqs':ussl.CERT_NONE})

    Thanks in advance,

  • I did not, but this topic came back again! :)
    So this time I will have a secure mqtt.

  • This issue is come up again.
    Yes I know simple mqtt does not support wss, but then is there any other avaible library which does or some workaround?
    I search every corner of the internet, but didn't find any.

  • @tttadam that config is using websockets, which I don’t think simple mqtt supports. Websockets are useful for web clients as this is the only kind of socket they can open, but MQTT by default works over raw TCP or TLS over TCP, without the additional websockets layer.

    What’s your emqx configuration?

  • @jcaron I tried that one also, without luck.

    client = MQTTClient("GT01", "", user=b"user", password=b"pass", 
        ssl=True,  ssl_params = {'cert_reqs':ussl.CERT_NONE})

    With this settings I am able to connect the mqtt server with mqttbox:

  • @tttadam What's your emqx configuration? It looks like the default is to have TLS on port 8883, which is also simple mqtt's default when you don't provide a port but ssl is True. Just try leaving out the port.

  • @jcaron Yes your right, I think I left out some important detail.
    The mqtt server is emqx running on unix running in docker.
    I am using simple mqtt.
    Tried this also I got back oserror -1:

    client = MQTTClient("GT01", "", port=443, user=b"user", password=b"pass", 
        ssl=True,  ssl_params = {'cert_reqs':ussl.CERT_NONE}) #sc ssl

  • @tttadam Which MQTTClient implementation are you using? The one in pycom-libraries expects a domain name for the server, not a URL, and the port number provided separately:

    client = MQTTClient("GT01", "", 443, user=b"user", password=b"password", ssl=True, ssl_params = {'cert_reqs':ussl.CERT_NONE})

    Note also that it is designed to work with MQTT over SSL directly, not over web sockets or HTTP, so you probably don't want to connect to 443 but a different port.

    If you are using a different implementation, let us know which. Also, what server (broker) are you using, and how is it configured?

Log in to reply

Pycom on Twitter