Core2 MQTT fails to subscribe on SSL=True



  • Hello everyone

    I have trouble with connecting my Core2 to HiveMQ using MQTT.

    What works well so far:

    • Connecting to a public MQTT broker (hivemq or mosquitto) with no auth (and no SSL) works perfectly fine.
    • Connecting to my private cloud broker works and I can send messages (from core2 to hivemq) when using the 'execute code' block.

    What does not work and drives me kind of crazy is that I don't receive any messages on the topics I subscribed to -- when being connected to the private cloud instance using SSL.

    Any hints on what is wrong are greatly appreciated :)

    Cheers, Alex

    0_1651312904171_Screenshot 2022-04-30 120111.png



  • Well, according to that image, you are missing the SSL codes, keys and certificates.



  • Hello @alexanders

    it looks like the generated micropython code is missing the statement to actually subscribe. I have to add something like below, in an Execute Code block, just before the mqtt start block to make the subscription work:

    m5mqtt.subscribe(str('kesabi'), fun_kesabi_)
    

    Thanks
    Felix



  • Hello @ajb2k3

    afaik, the client keyFile and certFile are optional and only required if the MQTT broker is setup to verify the MQTT client. Or am I missing something?

    Thanks
    Felix



  • @felmue
    If you check out the Execute Code block the params are different.
    For some reason there is an oddity with security lately that if SSL is set to true in MicroPython the the files are required.

    Also the main program functions need to be run in a loop placed after the MQTT Start block.



  • Hello @ajb2k3

    ah, ok, thank you for the information. I was not aware of that.

    Thanks
    Felix



  • @felmue said in Core2 MQTT fails to subscribe on SSL=True:

    Hello @ajb2k3

    ah, ok, thank you for the information. I was not aware of that.

    Thanks
    Felix

    No worries, it's not a well know feature.



  • Thanks a lot @ajb2k3 and @felmue for your swift responses! Good point with the subscribe statement -- and thanks for pointing out that I need to set keys and certs, I wasn't aware of that.

    I'm sure your answers will help others, too :)

    Cheers, Alex



  • @alexanders thanks to you question, I have now added a paragraph about this to my book which will hopefully get an update by the end of the month!