adafruit / Adafruit_CircuitPython_MiniMQTT

MQTT Client Library for CircuitPython
Other
80 stars 49 forks source link

allow to specify arbitrary TLS port #140

Closed vladak closed 1 year ago

vladak commented 1 year ago

As mentioned in #139, some MQTT brokers accept TLS based connections on non-standard port, e.g. test.mosquitto.org:8886.

When I tried something like this:

import adafruit_minimqtt.adafruit_minimqtt as MQTT

...

    broker_port = secrets["broker_port"]  # set to 8886                                      
    MQTT.MQTT_TLS_PORT = broker_port                               

    # Set up a MiniMQTT Client                                                  
    mqtt_client = MQTT.MQTT(                                                    
        broker=secrets["broker"],                                               
        port=broker_port,                                                       
        socket_pool=pool,                                                       
        ssl_context=ssl_context,                                                
    )

    mqtt_client.connect()

it failed (with the changes for the above mentioned PR in place), because it tried to initiate 'INSECURE' (quoting the log message) connection.

Clearly something better than overriding global variable is needed, perhaps a new attribute with a setter. Or maybe my Python-fu is not enough and some other incantation is needed to overwrite the TLS port definition.