fizista / micropython-umqtt.robust2

MIT License
49 stars 7 forks source link

Subscribing does not work on cert and key encrypted connection. #6

Closed Molaire closed 1 year ago

Molaire commented 3 years ago

Describe the bug When I subscribe to a topic on a certificate and key encrypted connection, subscription do not work and the callback is not called.

To Reproduce Create a cert and key and connect to a broker with the valid permissions (in my case a AWS broker).

This code works with umqtt.simple:

def sub_cb(topic, msg):
        print('hey')
        print((topic, msg))

cert_handler = CertificationHandler(folder='/certificates')
client = MQTTClient('random',
                                 server_url,
                                 port=server_port,
                                 ssl=True,
                                 ssl_params=as_ssl_params(cert_handler.most_recent_cert_and_key))
client.set_callback(sub_cb)
client.connect()
client.subscribe('banana')
client.publish('banana', '123')

while True:
    client.check_msg()
    utime.sleep(1)

This code does not with umqtt.robust2, but would work if I was not setting up an encrypted connection.

if __name__ == '__main__':
    def sub_cb(topic, msg, retain, dup):
        print('hey')
        print((topic, msg, retain, dup))

    cert_handler = CertificationHandler(folder='/certificates')
    client = MQTTClient(client_id,
                        endpoint,
                        port=endpoint_port,
                        ssl=True,
                        ssl_params=as_ssl_params(cert_handler.most_recent_cert_and_key))
    client.set_callback(sub_cb)
    client.connect()
    client.set_callback(sub_cb)
    client.subscribe('banana')
    client.publish('banana', '123')

    while True:
        client.check_msg()

Details (please complete the following information):

peergum commented 3 years ago

Looks like you publish to the banane topic not banana…

On Jul 28, 2021, at 10:29 AM, Vincent Thibault @.***> wrote:

 Describe the bug When I subscribe to a topic on a certificate and key encrypted connection, subscription do not work and the callback is not called.

To Reproduce Create a cert and key and connect to a broker with the valid permissions (in my case a AWS broker).

This code works with umqtt.simple ` def sub_cb(topic, msg): print('hey') print((topic, msg))

cert_handler = CertificationHandler(folder='/certificates') client = MQTTClient('random', glb.server_url, port=glb.server_port, ssl=True, ssl_params=as_ssl_params(cert_handler.most_recent_cert_and_key)) client.set_callback(sub_cb) client.connect() client.subscribe('banana') client.publish('banana', '123')

while True: client.check_msg() utime.sleep(1) This code does not with umqtt.robust2, but would work if I was not setting up an encrypted connection. if name == 'main': def sub_cb(topic, msg, retain, dup): print('hey') print((topic, msg, retain, dup))

cert_handler = CertificationHandler(folder='/certificates') client = MQTTClient(client_id, endpoint, port=endpoint_port, ssl=True, ssl_params=as_ssl_params(cert_handler.most_recent_cert_and_key)) client.set_callback(sub_cb) client.connect() client.set_callback(sub_cb) client.subscribe('banana') client.publish('banane', '123')

while True: client.check_msg() Details (please complete the following information):

Device board: ESP32 Micropython version: 1.16-135 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

Molaire commented 3 years ago

Looks like you publish to the banane topic not banana…

Edited. This is me trying to translate my code from french to english, everything was named 'banane' when I tested.

fizista commented 1 year ago

There is a new version of umqtt-simple2=v2.2.0.

Probably the problems have been fixed in this library, please let us know if they still occur.