flightonary / Moscapsule

MQTT Client for iOS written in Swift
MIT License
273 stars 69 forks source link

Not able to Publish with CA Server Certificate #79

Open VisRaman opened 6 years ago

VisRaman commented 6 years ago

I have a CA server certificate, using the same certificate i am able to PUBLISH the message in android using paho lib, I am not able to receive the message PUBLISHED by my iOS app using the moscapsule lib. the log shows "mosq_success", but i am not able to receive the message on the other end. The code is below -

`
func initMQTTByMoscapsule() -> Void {

    mosquitto_lib_cleanup()

    moscapsule_init()

    let mqttConfig = MQTTConfig(clientId: clientID + String(ProcessInfo().processIdentifier), host: host, port: 8883, keepAlive: 60)

    let mqttAuth = MQTTAuthOpts.init(username: userName, password: password)
    mqttConfig.mqttAuthOpts = mqttAuth

    let resourcePath = Bundle.main.url(forResource: "authoritycert", withExtension: "crt");
    mqttConfig.mqttServerCert = MQTTServerCert(cafile: nil, capath: resourcePath?.absoluteString)

    let mqttClient1 = MQTT.newConnection(mqttConfig)

    mqttClient1.connectTo(host: host, port: 8883, keepAlive: 60) { (MosqResult) in
    print("\n\n\n Return Code is \(MosqResult)")

    if mqttClient1.isConnected {
        print("\n\n\n Dude its is connected \n\n")
    }

    mqttClient1.publish(string: "test-blind-10", topic: topicToSub, qos: 0, retain: false, requestCompletion: { (resultMessage, resultcode) in
                    print("\n\n\n The PUBLISH result - \(resultMessage) \n\n")
        })
    }

    mqttConfig.onPublishCallback = { messageID in
        print("\n\n\n Return Code is \(messageID.description) on publish")
    }
    //mqttClient.subscribe("subscribe/topic", qos: 2)

    mqttConfig.onConnectCallback = { returnCode in
        print("\n\n\n Return Code is \(returnCode.description) (on Connect)")
    }

    `

and the resulting log is below

`[38695:1102928] [MOSQUITTO] DEBUG Client Smart&Client38695 sending CONNECT 2018-10-24 10:27:34.845393+0530 CC[38695:1104304] [MOSQUITTO] DEBUG Client Smart&Client38695 sending CONNECT

Return Code is mosq_success

2018-10-24 10:27:36.975967+0530 CC[38695:1102928] [MOSQUITTO] DEBUG Client Smart*&Client38695 sending PUBLISH (d0, q0, r0, m1, 'a*&-r&*-topic', ... (13 bytes))

The PUBLISH result - mosq_success

2018-10-24 10:27:38.375126+0530 CC[38695:1104304] [MOSQUITTO] DEBUG Client Smart***&Client38695 sending DISCONNECT`

still i am not receiving the message in the other end.