Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After SUBSCRIBING to topic connection getting disconnect #72

Open
shantharsk opened this issue Apr 12, 2018 · 1 comment
Open

After SUBSCRIBING to topic connection getting disconnect #72

shantharsk opened this issue Apr 12, 2018 · 1 comment

Comments

@shantharsk
Copy link

shantharsk commented Apr 12, 2018

Hi I'm trying to connect Connect to my MQTT server with SSL Certificate authentication it worked fine. After I subcribed the Topic the connection getting disconnected. This is my code
moscapsule_init()
**let mqttConfig = MQTTConfig(clientId: "shantha", host: "aws.amazonaws.com", port:poer, keepAlive: 60)
let path = Bundle.main.path(forResource: "ca", ofType: "pem")
let path1 = Bundle.main.path(forResource: "client", ofType: "crt")
let key = Bundle.main.path(forResource: "client", ofType: "key")

    mqttConfig.mqttServerCert = MQTTServerCert(cafile: path, capath: nil)
    mqttConfig.mqttClientCert = MQTTClientCert(certfile: path1!, keyfile: key!, keyfile_passwd: nil)
    mqttConfig.mqttTlsOpts = MQTTTlsOpts(tls_insecure: false, cert_reqs: CertReqs.ssl_verify_peer, tls_version: "tlsv1", ciphers: nil)
   
    mqttConfig.onConnectCallback = { returnCode in
        if returnCode == ReturnCode.success {
            print("connected")
            // something to do in case of successful connection
        }
        else {
            // error handling for connection failure
        }
    }
    
            mqttConfig.onMessageCallback = { mqttMessage in
                if mqttMessage.topic == "topic" {
                    NSLog("MQTT Message received: payload=\(mqttMessage.payloadString)")
                } else  {
                    // something to do in case of other topics
                }
            }
    
    let mqttClient = MQTT.newConnection(mqttConfig)
   
    mqttClient.connectTo(host: "aws.amazonaws.com", port: 7926, keepAlive: 60)
            let deadlineTime = DispatchTime.now() + .seconds(20)
            DispatchQueue.main.asyncAfter(deadline: deadlineTime, execute: {
               mqttClient.subscribe("topic", qos: 2, requestCompletion: nil)
            })**

Im geting connection keep disconnecting can please help me with this issue.

Thanks,

@smartAkash
Copy link

I am geting same issue connection keep disconnecting can please help me with this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants