emqx / CocoaMQTT

MQTT 5.0 client library for iOS and macOS written in Swift
https://www.emqx.com/en
Other
1.59k stars 418 forks source link

Setting enableSSL & allowUntrustCACertificate causes successful connection but no messages publish #356

Open mkornyev opened 3 years ago

mkornyev commented 3 years ago

Problem When connecting to a TCP-based MQTT broker w/no websockets, setting mqtt.enableSSL = true AND mqtt.allowUntrustCACertificate = true results in a successful connection (with the host resolving correctly), but none of the published messages will be processed by the broker. CocoaMQTT just keeps retrying.

Fix Set enableSSL = true & allowUntrustCACertificate = false

Feature Request Some sort of .info log level messages would be helpful.

The following works on Swift 5 & Xcode 11.7 on an iOS 12.4 target.

 // Client setup
        mqtt = CocoaMQTT(clientID: self.clientID, host: host, port: port)
        mqtt.username = username
        mqtt.password = password
        mqtt.willMessage = CocoaMQTTWill(topic: dieout_topic, message: dieout_message) // TCP
        mqtt.keepAlive = 30 // seconds
        mqtt.delegate = self
        mqtt.logLevel = .off //.debug
        mqtt.enableSSL = true;

        // Callbacks
        mqtt.didReceiveMessage = { mqtt, message, id in
            print("Message received in topic \(message.topic) with payload \(message.string!)")
        }

        _ = mqtt.connect()
leisurehound commented 3 years ago

I too am facing this issue. On HiveMQ which requires TLS I get the didConnectAck called, no subsequent of publishing of messages.