aws-amplify / aws-sdk-ios

AWS SDK for iOS. For more information, see our web site:
https://aws-amplify.github.io/docs
Other
1.68k stars 884 forks source link

IoT disconnected after token expired, auto refresh token is working #4191

Open JyotsnaPiOSDEV opened 2 years ago

JyotsnaPiOSDEV commented 2 years ago

For connecting to MQTT channel of AWS IOT core we are using custom auth lambda for policy generation. In custom auth lambda we are using access token of AWS cognito to authenticate request. I want to reconnect on dissconect

Which AWS Services are you utilizing? AWSIoT

let clientId = UUID().uuidString
    self.base64String = AwsSignature.shared.featchPrivateKeySdk(token:  AWSAuthManager.shared.accessToken ?? "")
    obj.connectUsingWebSocket(withClientId: clientId,
        cleanSession: true,
        customAuthorizerName: "r",
        tokenKeyName: "",
        tokenValue:  AWSAuthManager.shared.accessToken ?? "" ,
        tokenSignature: self.base64String,
        statusCallback:mqttEventCallbackWebsocket(_:))

SDK Version: 2.270. Dependency Manager: Cocoapods

Device: Any device iOS Version: Any version

Please help how to reconnect and fix this disconnect issue

brennanMKE commented 2 years ago

@JyotsnaPiOSDEV

I see you are directly using a tokenValue which is what will expire. Once it expires this connection will no longer be valid since it is not being refreshed. What you can do is set up AWSIoTDataManager with an instance of AWSCredentialsProvider which will get a fresh credentials as needed.

We have a sample project which you can reference. First, see how the credentials provider is created. (code) It is passed into initializeControlPlane and initializeDataPlane.

Below is an example of sections you can define in awsconfiguration.json for IoT. The first 2 sections are for the control plane and the last one is for the data plane. Set the region as appropriate and replace "REPLACE" with the data URL for IoT.

    "IoT": {
        "Default": {
            "Region": "us-east-1",
            "Endpoint": "https://iot.us-east-1.amazonaws.com"
        }
    },
    "IoTManager": {
        "Default": {
            "Region": "us-east-1",
            "Endpoint": "https://iot.us-east-1.amazonaws.com"
        }
    },
    "IoTDataManager": {
        "Default": {
            "Region": "us-east-1",
            "Endpoint": "https://REPLACE-ats.iot.us-east-1.amazonaws.com"
        }
    },

Below is some reference code you can use as well. It loads these sections from awsconfiguration.json so your code does not require any constants with these values. It sets up the control plane and data plane and confirms them with assertions at the end.

// MARK: - Control Plane setup

guard let iotServiceInfo = AWSInfo.default().serviceInfo("IoT", forKey: "Default"),
      let iotManagerServiceInfo = AWSInfo.default().serviceInfo("IoTManager", forKey: "Default"),
      let iotDataManagerServiceInfo = AWSInfo.default().serviceInfo("IoTDataManager", forKey: "Default")  else {
    fatalError("Failed to read in default service info for IoT")
}

let iot = AWSIoT.default()
guard let credentialsProvider = iot.configuration.credentialsProvider as? AWSCognitoCredentialsProvider else {
    fatalError("App must be configured")
}

let region = iotServiceInfo.region
let controlPlaneServiceConfiguration = AWSServiceConfiguration(region:region, credentialsProvider:credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = controlPlaneServiceConfiguration
iotManager = AWSIoTManager.default()

self.region = region
self.credentialsProvider = credentialsProvider

guard let iotDataManagerEndpoint = iotDataManagerServiceInfo.endpoint else {
    fatalError("Failed to get Data Manager endpoint")
}

// MARK: - Data Plane setup

guard let dataConfiguration = AWSServiceConfiguration(region: iotDataManagerServiceInfo.region,
                                                      endpoint: iotDataManagerEndpoint,
                                                      credentialsProvider: credentialsProvider) else {
    fatalError("Failed to create Data Configuration")
}

// Configure MQTT with Last Will & Testament (LWT)
let mqttConfiguration = AWSIoTMQTTConfiguration()
let message = "LWT-\(Date())"
mqttConfiguration.lastWillAndTestament.message = message
mqttConfiguration.lastWillAndTestament.topic = "lwt/disconnected"
mqttConfiguration.lastWillAndTestament.qos = .messageDeliveryAttemptedAtLeastOnce
mqttConfiguration.lastWillAndTestament.willRetain = true

AWSIoTDataManager.register(with: dataConfiguration, with: mqttConfiguration, forKey: Constants.dataManagerKey)
iotDataManager = AWSIoTDataManager(forKey: Constants.dataManagerKey)

// Control Plane
assertEqual(iotServiceInfo.infoDictionary["Endpoint"] as? String, iot.configuration.endpoint.url.absoluteString)
assertEqual(iotManagerServiceInfo.infoDictionary["Endpoint"] as? String, iotManager.configuration.endpoint.url.absoluteString)

// Data Plane
assertEqual(iotDataManagerServiceInfo.infoDictionary["Endpoint"] as? String, iotDataManager.configuration.endpoint.url.absoluteString)

This code uses Cognito to support the credentials provider which may meet your needs with not additional requirements. Since you have a lambda doing this work you could create your own implementation of AWSCredentialsProvider because it is a protocol. See that we have an implementation called AWSStaticCredentialsProvider. You can see that you would need to implement the credentials function which returns AWSTask<AWSCredentials *> *. (code)

Your implementation will need to refresh the credentials before the current credentials expire so when they are requested they are always current. You could also refresh credentials on demand when they are expired. You will want to ensure this is done once when the token is expiring and make that process thread-safe.

JyotsnaPiOSDEV commented 2 years ago

HI THANKS for now I am trying reconnect on connect error

  func mqttEventCallbackWebsocket(_ status: AWSIoTMQTTStatus) {
            print("AWS connection status = \(status.rawValue)")
                case .connected:
                print("Connected to AWS successfully")

                switch region {
                case .Singapore:
                    isSingaporeConnectedToAWS = true
                case .Sydney:
                    isSydneyConnectedToAWS = true

                case .Japan:
                    isJapanConnectedToAWS = true

                case .China:
                    isChinaConnectedToAWS = true

                case .Virginia:
                    isVirginiaConnectedToAWS = true

                case .California:
                    isCaliforniaConnectedToAWS = true

                case .London:
                    isLondonConnectedToAWS = true
                case .Frankfurt :
                    isFrankfurtConnectedToAWS = true
                }
             completionHandler(region)
                print("AT connect \(region)")
            case .connectionError:
                print("AWS IoT connection error")

                completionHandler(region)
                SetupStatusCallback(err: "err", region: region)

            case .connectionRefused:
                print("AWS IoT connection refused")

                SetupStatusCallback(err: "err", region: region)
                completionHandler(region)

            case .protocolError:
                print("AWS IoT protocol error")
                SetupStatusCallback(err: "err", region: region)
                completionHandler(region)

            case .disconnected:
                SetupStatusCallback(err: "err", region: region)

                print("AWS disconnected")
                completionHandler(region)
            case .unknown:
                print("AWS unknown connection")
                SetupStatusCallback(err: "err", region: region)

                completionHandler(region)
            default:
                print("AWS IoT unknown state")
                SetupStatusCallback(err: "err", region: region)

                completionHandler(region)
            }
/        }
        }
        func perfromActionforRegion(obj : AWSIoTDataManager?) {
            guard let obj = obj else {
                 let status =  obj?.getConnectionStatus()
                print("AWS IoT  state \(status)")

                completionHandler(region)
                return
            }

//On error
func SetupStatusCallback(err : String,region : Regions){
        print("SetupStatusCallback \(err)")
        self.initMQQt()
    }
    func initMQQt(){
        AWSAuthManager.shared.getToken{ accessToken in
        if   accessToken ==  "error on getting token"{
                AWSAuthManager.shared.logoutFromApp()
        }
        if accessToken == AWSAuthManager.shared.accessToken {
            print(" dont need new token")
        }
        else{
            print(" Reconnect Reuired")
            self.initializeAWSWithTopic()
            AWSAuthManager.shared.accessToken = accessToken
            self.connectDeviceToAWS()

        }
        }
    }

Trying to reconnect on error but not working fine(some time able to reconnect) Also taking more time I have look closely on AWSCognitoIdentityProvider File auto refresh done before 2 min that is exactly expired Not able to get that triggered to isToken expired then I can refresh credentials on your explained way . When to call custom credentials Provider ?

JyotsnaPiOSDEV commented 2 years ago

As per suggestion from IOT coder "Your implementation will need to refresh the credentials before the current credentials expire so when they are requested they are always current. You could also refresh credentials on demand when they are expired. You will want to ensure this is done once when the token is expiring and make that process thread-safe" I have created custom credentials Provider On Connection error I am doing like this

 AWSMobileClient.default().getAWSCredentials { [self] (credentials, error) in
                if let error = error {
                    print("\(error.localizedDescription)")
                    completionHandler("out")
                } else if let credentials = credentials {
                    self.ProviderManager  = CustomIdentityProviderToken(accessKey:credentials.accessKey, secretKey:credentials.secretKey, sessionKey: credentials.sessionKey, expiration: credentials.expiration as NSDate?)
                    print(credentials.accessKey)
                    initializeDataPlane { isComplete in
                        self.connectDeviceToAWS()
                        completionHandler("done")
                    }

                }
            } 
  1. Problem able to connect but not subscribes
  2. first auto disconnect then able to connect
  3. I have passed all keys from AWSMobileClient.default().getAWSCredentials to my custom credentials provider is it fine ?
brennanMKE commented 2 years ago

@JyotsnaPiOSDEV I see you are using AWSMobileClient.default() to get the values for accessKey and secretKey. That is actually an implementation of AWSCredentialsProvider so you could use it directly. What you want to make sure happens is every time the app uses credentials it gets them from the provider. It will always ensure the credentials are current. Your custom provider is only going to hold onto those values and not update them when they expire.

JyotsnaPiOSDEV commented 2 years ago

Problem able to connect but not subscribes why ? Log -Auto-resubscribe is enabled. Resubscribing to topics. what to to resolve this On app launch also need to use custom provider ?

brennanMKE commented 2 years ago

Can you provide more information like logs to show what is happening? I am not able to determine what is happening from these questions.

JyotsnaPiOSDEV commented 2 years ago

In android on connection error they ate just calling get token .Able to change token and reconnect and subscribe

  1. On iot connection error m doing get token , get credentials set up data panel with custom provider , reconnect to iot .. what issue in this sequence. I am not able to connect exact time of expiration.. done lots of debugging ....
brennanMKE commented 2 years ago

Please add this code when you configure AWS:

AWSDDLog.sharedInstance.logLevel = .verbose
AWSDDLog.add(AWSDDTTYLogger())

Then use the console to see what is happening. Share the relevant details on this issue.

JyotsnaPiOSDEV commented 2 years ago

AWSCognitoCredentialsProvider using on launch and on reconnection its on app launchlet credentialsProvider = AWSCognitoCredentialsProvider(regionType:.APSoutheast2, identityPoolId:AWS_IDENTITY_POOL_ID) on error CustomIdentityProviderToken- own credentialsProvider

Initializing MQTTEncoder and MQTTDecoder streams 2022-07-08 14:45:26:902 Votion Home[6879:122569] opening encoder stream. 2022-07-08 14:45:26:902 Votion Home[6879:122569] opening decoder stream. AWS connection status = 2 This is on lunch of app There is no log then Till token expiration auto reconnect off for mqqt connection I have done false cleanSession: false Till token expired not able to see any subscribes message After 8 min WebSocket closed with code:1001 with reason:Stream end encountered AWS connection status = 5 AWS IoT connection error SetupStatusCallback err 2022-07-08 14:56:38:976 Votion Home[6879:122519] MQTT session error, code: 2 2022-07-08 14:56:38:980 Votion Home[6879:127112] Adding FetchUserPoolTokensOperation operation 2022-07-08 14:56:38:981 Votion Home[6879:122519] closing encoder stream. 2022-07-08 14:56:38:982 Votion Home[6879:122519] closing decoder stream. 2022-07-08 14:56:38:987 Votion Home[6879:127112] C27D6E17-BE99-4CE7-8A2F-6AC2B5D58C67 Created FetchUserPoolTokensOperation us-east-1 2022-07-08 14:56:38:989 Votion Home[6879:126422] C27D6E17-BE99-4CE7-8A2F-6AC2B5D58C67 Start execution 2022-07-08 14:56:38:990 Votion Home[6879:127112] C27D6E17-BE99-4CE7-8A2F-6AC2B5D58C67 notStarted: startOperation -> fetching 2022-07-08 14:56:38:990 Votion Home[6879:126422] C27D6E17-BE99-4CE7-8A2F-6AC2B5D58C67 Inside fetch token 2022-07-08 14:56:39:013 Votion Home[6879:126422] Request headers: { "Content-Type" = "application/x-amz-json-1.1"; Host = "cognito-idp.us-east-1.amazonaws.com"; "User-Agent" = "aws-sdk-iOS/2.27.10 iOS/14.5 en_US"; "X-Amz-Date" = 20220708T092639Z; "X-Amz-Target" = "AWSCognitoIdentityProviderService.InitiateAuth"; "UserContextData" {} MQTTSessionEventConnectionClosed: MQTT session closed. AWS IoT connection error SetupStatusCallback err 2022-07-08 14:56:39:983 Votion Home[6879:126615] Adding FetchUserPoolTokensOperation operation 2022-07-08 14:56:39:985 Votion Home[6879:126615] AA83778B-8531-4833-BCEE-9F6C4C085E5D Created FetchUserPoolTokensOperation us-east-1 2022-07-08 14:56:39:989 Votion Home[6879:127113] Attempting to reconnect. 2022-07-08 14:56:39:989 Votion Home[6879:127113] AWSIoTMQTTClient: connecting via websocket. AWS connection status = 12022-07-08 14:56:39:989 Votion Home[6879:127113] Using Custom Auth URL: wss://a2voxa1cppcped-ats.iot.us-east-1.amazonaws.com/mqtt.

Connecting to AWS IoT 2022-07-08 14:56:39:990 Votion Home[6879:127113] user metadata is : ?SDK=iOS&Version=2.27.10

Metrics collection is: Enabled 2022-07-08 14:56:40:180 Votion Home[6879:127110] Response headers: { "Content-Length" = 2214; "Content-Type" = "application/x-amz-json-1.1"; Date = "Fri, 08 Jul 2022 09:26:40 GMT"; "x-amzn-requestid" = "a235c5cb-4e3b-4022-ac4d-9e6786f71fbd"; } 2022-07-08 14:56:40:180 Votion Home[6879:127110] Response body: {"AuthenticationResult":{"AccessToken":"v,"TokenType":"Bearer"},"ChallengeParameters":{}} token at default library) 2022-07-08 14:56:40:208 Votion Home[6879:126615] C27D6E17-BE99-4CE7-8A2F-6AC2B5D58C67 fetching: tokenFetched(AWSMobileClient.Tokens(idToken: nString: 2022-07-08 14:56:40:210 Votion Home[6879:126615] C27D6E17-BE99-4CE7-8A2F-6AC2B5D58C67 Success token retrievd at library difference is 419 2022-07-08 14:56:40:220 Votion Home[6879:127110] AA83778B-8531-4833-BCEE-9F6C4C085E5D Start execution 2022-07-08 14:56:40:221 Votion Home[6879:127110] AA83778B-8531-4833-BCEE-9F6C4C085E5D notStarted: startOperation -> fetching 2022-07-08 14:56:40:222 Votion Home[6879:127110] AA83778B-8531-4833-BCEE-9F6C4C085E5D Inside fetch token 2022-07-08 14:56:40:222 Votion Home[6879:126422] Adding FetchUserPoolTokensOperation operation 2022-07-08 14:56:40:224 Votion Home[6879:126422] 6FA2B424-5652-463D-BEEF-3A5F21344C38 Created FetchUserPoolTokensOperation token at default library) token retrievd at library difference is 419 2022-07-08 14:56:40:242 Votion Home[6879:127112] 6FA2B424-5652-463D-BEEF-3A5F21344C38 Start execution 2022-07-08 14:56:40:243 Votion Home[6879:127112] 6FA2B424-5652-463D-BEEF-3A5F21344C38 notStarted: startOperation -> fetching 2022-07-08 14:56:40:245 Votion Home[6879:127112] 6FA2B424-5652-463D-BEEF-3A5F21344C38 Inside fetch token token at default library) 2022-07-08 14:56:40:255 Votion Home[6879:127110] 6FA2B424-5652-463D-BEEF-3A5F21344C38 fetching: tokenFetched(AWSMobileClient.Tokens(idToken: Optional(AWSMobileClient.SessionToken(tokenString: Optional("eyJraWQiOiJyZHgrZk9WRVlmRTVhUkV6QjNCSGxJN3ptbTdKTEx2SnBoRFhqaGVuN0FNPSIsImFsZyI6IlJTMjU2In0.3MDNiIiwiYXV0aF90aW1lIjoxNjU3MjY5ODQxLCJleHAiOjE2NTcyNzI4MjAsImlhdCI6MTY1NzI3MjQwMCwiZW1haWwiOiJqeW90aW9zMThmZWJAZ21haWwuY29tIn0.chsa7UdPG2a7AP4oXeDfxccepD6Zdk3Cs-4uwxSE9L8xXcDQCuL6fiyph6HLYK1dGwtsn3vmtms0nOeS9JOFle7DvYvvInVP-Uv_kf4-p5zBlRkP5DVbI1piBHYq6aRS2Ij6rZ6TA3_o_eqE_biZe7-7IME3IGoq8f8bCG6wZhd2JGLgu7rHYuhvBh43TjQ6KUSjGWWSlYI-HT9a8574PqDy9zCEpJueHBIbl3YqV1FTC9notH4YVu6Va9JQ9kHPNJPQdu_JgZoBAae5i3esSB9lrkrimx89NbET90GB3nMmdWXQBQKvo87MREQmk2W23JSzSDqgFTFIxgW0dHdNOw"))), accessToken: Optional(AWSMobileClient.SessionToken(tokenString: yD12KZfF6uUzF6SiXwwHYqU-dDq_goenb29j807VwKWwfmwt- 2022-07-08 14:56:40:257 Votion Home[6879:127110] 6FA2B424-5652-463D-BEEF-3A5F21344C38 Success token retrievd at library 2022-07-08 14:56:40:265 Votion Home[6879:127112] Request headers: { "Content-Type" = "application/x-amz-json-1.1"; Host = ""; "User-Agent" = "aws-sdk-iOS/2.27.10 iOS/14.5 en_US"; "X-Amz-Date" = 20220708T092640Z; "X-Amz-Target" = "AWSCognitoIdentityService.GetId"; } 2022-07-08 14:56:40:265 Votion Home[6879:127112] Request body: {"IdentityPoolId":"f","Logins":{""}} 2022-07-08 14:56:41:238 Votion Home[6879:127112] Websocket did open and is connected. 2022-07-08 14:56:41:241 Votion Home[6879:127143] <<<NSThread: 0x7b10000db300>{number = 25, name = (null)}>> Initializing MQTTEncoder and MQTTDecoder streams 2022-07-08 14:56:41:241 Votion Home[6879:127143] opening encoder stream. 2022-07-08 14:56:41:241 Votion Home[6879:127143] opening decoder stream. 2022-07-08 14:56:41:390 Votion Home[6879:127110] Response headers: { "Content-Length" = 63; "Content-Type" = "application/x-amz-json-1.1"; Date = "Fri, 08 Jul 2022 09:26:41 GMT"; "x-amzn-requestid" = ""; } 2022-07-08 14:56:41:390 Votion Home[6879:127110] Response body: {"IdentityId":""} 2022-07-08 14:56:41:404 Votion Home[6879:127112] Request headers: { "Content-Type" = "application/x-amz-json-1.1"; Host = "cognito-identity.us-east-1.amazonaws.com"; "User-Agent" = "aws-sdk-iOS/2.27.10 iOS/14.5 en_US"; "X-Amz-Date" = 20220708T092641Z; "X-Amz-Target" = "AWSCognitoIdentityService.GetCredentialsForIdentity"; } 2022-07-08 14:56:41:404 Votion Home[6879:127112] Request body: {"Logins":{"} AWS connection status = 5 AWS IoT connection error SetupStatusCallback err 2022-07-08 14:56:41:522 Votion Home[6879:126615] WebSocket closed with code:1001 with reason:Stream end encountered 2022-07-08 14:56:41:524 Votion Home[6879:127143] MQTT session error, code: 2 2022-07-08 14:56:41:527 Votion Home[6879:125706] Adding FetchUserPoolTokensOperation operation 2022-07-08 14:56:41:534 Votion Home[6879:127143] closing encoder stream. 2022-07-08 14:56:41:534 Votion Home[6879:127143] closing decoder stream. 2022-07-08 14:56:41:537 Votion Home[6879:125706] CDA8DE43-B381-4E0F-9F5B-088175D176B4 Created FetchUserPoolTokensOperation us-east-1 2022-07-08 14:56:41:541 Votion Home[6879:125706] CDA8DE43-B381-4E0F-9F5B-088175D176B4 Start execution 2022-07-08 14:56:41:541 Votion Home[6879:126422] CDA8DE43-B381-4E0F-9F5B-088175D176B4 notStarted: startOperation -> fetching 2022-07-08 14:56:41:542 Votion Home[6879:125706] CDA8DE43-B381-4E0F-9F5B-088175D176B4 Inside fetch token token at default library) 2022-07-08 14:56:41:551 Votion Home[6879:126422] CDA8DE43-B381-4E0F-9F5B-088175D176B4 fetching: -_DsKN01sg"))), expiration: Optional(2022-07-08 09:33:40 +0000))) -> fetched(AWSMobileClient.Tokens(idToken: Optional(AWSMobileClient.SessionToken(tokenString: Optional("eyJraWQiOiJyZHgrZk9WRVlmRTVhUkV6QjNCSGxJN3ptbTdKTEx2SnBoRFhqaGVuN0FNPSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiIzMmU1OGQzMC0xMzdiLTRhYmUtYWIxYy05ZjBmZDMyMjRlN2UiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfUkhXbTlrZmc2IiwiY29nbml0bzp1c2VybmFtZSI6IjMyZTU4ZDMwLTEzN2ItNGFiZS1hYjFjLTlmMGZkMzIyNGU3ZSIsImN1c3RvbTpkZWZhdWx0X3BvbGljeSI6InRydWUiLCJhdWQiOiIxZzZqY29nbnVlanQwdGFtYmNrbzl1bmpoOCIsImV2ZW50X2lkIjoiZTAwNDYxOTktZmRjZS00YTdkLTljYTYtMTdmZjhhY2IyNmNiIiwidG9rZW5fdXNlIjoiaWQiLCJjdXN0b206cHJpbmNpcGFsSWQiOiJ1cy1lYXN0LTE6ZmMxODU4ODAtMjE1YS00ZGQ0LWE3ZGEtMGE0NDUwYzg3MDNiIiwiYXV0aF90aW1lIjoxNjU3MjY5ODQxLCJleHAiOjE2NTcyNzI4MjAsImlhdCI6MTY1NzI3MjQwMCwiZW1haWwiOiJqeW90aW9zMThmZWJAZ21haWwuY29tIn0.chsa7UdPG2a7AP4oXeDfxccepD6Zdk3Cs-4uwxSE9L8xXcDQCuL6fiyph6HLYK1dGwtsn3vmtms0nOeS9JOFle7DvYvvInVP-Uv_kf4-p5zBlRkP5DVbI1piBHYq6aRS2Ij6rZ6TA3_o_eqE_biZe7-7IME3IGoq8f8bCG6wZhd2JGLgu7rHYuhvBh43TjQ6KUSjGWWSlYI-HT9a8574PqDy9zCEpJueHBIbl3YqV1FTC9notH4YVu6Va9JQ9kHPNJPQdu_JgZoBAae5i3esSB9lrkrimx89NbET90GB3nMmdWXQBQKvo87MREQmk2W23JSzSDqgFTFIxgW0dHdNOw"))), accessToken: ional(2022-07-08 09:33:40 +0000))) 2022-07-08 14:56:41:553 Votion Home[6879:126422] CDA8DE43-B381-4E0F-9F5B-088175D176B4 Success token retrievd at library difference is 418 2022-07-08 14:56:42:503 Votion Home[6879:127112] Response headers: { "Content-Length" = 1508; "Content-Type" = "application/x-amz-json-1.1"; Date = "Fri, 08 Jul 2022 09:26:42 GMT"; "x-amzn-requestid" = ""; } 2022-07-08 14:56:42:504 Votion Home[6879:127112] Response body: {"Credentials":{"AccessKeyId":"","Expiration":1.657276002E9,"SecretKey":""},"IdentityId":""} 2022-07-08 14:56:42:527 Votion Home[6879:127112] Initializing AWSIoTMqttConfiguration with KeepAlive:300.000000, baseReconnectTime:1.000000,minimumConnectionTime:20.000000, maximumReconnectTime:128.000000, autoResubscribe:Enabled, lwt topic: message: setRegion working 2022-07-08 14:56:42:528 Votion Home[6879:127112] Initializing AWSIoTMqttConfiguration with KeepAlive:300.000000, baseReconnectTime:1.000000,minimumConnectionTime:20.000000, maximumReconnectTime:128.000000, autoResubscribe:Enabled, lwt topic: message: setRegion working 2022-07-08 14:56:42:529 Votion Home[6879:127112] Initializing AWSIoTMqttConfiguration with KeepAlive:300.000000, baseReconnectTime:1.000000,minimumConnectionTime:20.000000, maximumReconnectTime:128.000000, autoResubscribe:Enabled, lwt topic: message: setRegion working 2022-07-08 14:56:42:530 Votion Home[6879:127112] Initializing AWSIoTMqttConfiguration with KeepAlive:300.000000, baseReconnectTime:1.000000,minimumConnectionTime:20.000000, maximumReconnectTime:128.000000, autoResubscribe:Enabled, lwt topic: message: setRegion working Acccess token at connect eyJraWQiOiJ............. AWS connection status = 5 AWS IoT connection error SetupStatusCallback err 2022-07-08 14:56:42:538 Votion Home[6879:127143] MQTTSessionEventConnectionClosed: MQTT session closed. 2022-07-08 14:56:42:538 Votion Home[6879:127112] IOTDataManager: Connecting to IoT using websocket with Custom Auth, client id: E17ABDF3-F6EF-4A6C-8125-C2509FCD156D 2022-07-08 14:56:42:538 Votion Home[6879:126422] Adding FetchUserPoolTokensOperation operation 2022-07-08 14:56:42:538 Votion Home[6879:127112] AWSIoTMQTTClient: connecting via websocket. AWS connection status = 1 Connecting to AWS IoT 2022-07-08 14:56:42:538 Votion Home[6879:127112] Using Custom Auth URL: wss://a2voxa1cppcped-ats.iot.us-east-1.amazonaws.com/mqtt. 2022-07-08 14:56:42:538 Votion Home[6879:127112] user metadata is : ?SDK=iOS&Version=2.27.10 2022-07-08 14:56:42:539 Votion Home[6879:127112] Metrics collection is: Enabled 2022-07-08 14:56:42:539 Votion Home[6879:127112] -[AWSMQTTSession initWithClientId:userName:password:keepAlive:cleanSession:willTopic:willMsg:willQoS:willRetainFlag:publishRetryThrottle:] [Line 84], Thread:<NSThread: 0x7b100008e080>{number = 21, name = (null)} 2022-07-08 14:56:42:539 Votion Home[6879:127112] +[AWSMQTTMessage connectMessageWithClientId:userName:password:keepAlive:cleanSession:willTopic:willMsg:willQoS:willRetain:] [Line 68], Thread:<NSThread: 0x7b100008e080>{number = 21, name = (null)} 2022-07-08 14:56:42:540 Votion Home[6879:127112] Creating AWSMQTTMessage with raw data >>>>> {length = 74, bytes = 0x00044d51 54540480 012c0024 45313741 ... 3d322e32 372e3130 } <<<<< 2022-07-08 14:56:42:540 Votion Home[6879:127112] Creating AWSMQTTMessage with >>>>> <AWSMQTTMessage: 0x7b080037a940> <<<<< 2022-07-08 14:56:42:541 Votion Home[6879:126422] B86888A4-FAAE-4F05-92ED-D07CBBC79CA3 Created FetchUserPoolTokensOperation us-east-1 2022-07-08 14:56:42:548 Votion Home[6879:126422] B86888A4-FAAE-4F05-92ED-D07CBBC79CA3 Start execution 2022-07-08 14:56:42:549 Votion Home[6879:125706] B86888A4-FAAE-4F05-92ED-D07CBBC79CA3 notStarted: startOperation -> fetching 2022-07-08 14:56:42:549 Votion Home[6879:126422] B86888A4-FAAE-4F05-92ED-D07CBBC79CA3 Inside fetch token token at default library) 2022-07-08 14:56:42:561 Votion Home[6879:126957] B86888A4-FAAE-4F05-92ED-D07CBBC79CA3 fetching: tokenFetched(AWSMobileClient., expiration: Optional(2022-07-08 09:33:40 +0000))) -> fetched(AWSMobileClient.Tokens(idToken: Optional(AWSMobileClient.SessionToken(tokenString: 2022-07-08 14:56:42:563 Votion Home[6879:126957] B86888A4-FAAE-4F05-92ED-D07CBBC79CA3 Success token retrievd at library difference is 417 2022-07-08 14:56:43:530 Votion Home[6879:127149] Attempting to reconnect. 2022-07-08 14:56:43:530 Votion Home[6879:127149] AWSIoTMQTTClient: connecting via websocket. AWS connection status = 1 Connecting to AWS IoT 2022-07-08 14:56:43:531 Votion Home[6879:127149] Using Custom Auth URL: wss://a2voxa1cppcped-ats.iot.us-east-1.amazonaws.com/mqtt. 2022-07-08 14:56:43:531 Votion Home[6879:127149] user metadata is : ?SDK=iOS&Version=2.27.10 2022-07-08 14:56:43:531 Votion Home[6879:127149] Metrics collection is: Enabled 2022-07-08 14:56:43:833 Votion Home[6879:126422] Websocket did open and is connected. 2022-07-08 14:56:43:834 Votion Home[6879:127160] <<<NSThread: 0x7b10000f5840>{number = 30, name = (null)}>> Initializing MQTTEncoder and MQTTDecoder streams 2022-07-08 14:56:43:834 Votion Home[6879:127160] opening encoder stream. 2022-07-08 14:56:43:834 Votion Home[6879:127160] opening decoder stream. AWS connection status = 2 Connected to AWS successfully us-east-1 2022-07-08 14:56:44:151 Votion Home[6879:127160] MQTT session connected. 2022-07-08 14:56:44:151 Votion Home[6879:127160] Auto-resubscribe is enabled. Resubscribing to topics.

so what is wrong in my sequence. Multiple time credentials coming then disconnect and connect Also clear session of paused socket before expire no logs there

brennanMKE commented 2 years ago

Can you try using this code?

Start out by making sure you initialize the control plane and data plane along with the MQTT configuration.


    public init() {
#if DEBUG
        AWSDDLog.sharedInstance.logLevel = .verbose
        AWSDDLog.add(AWSDDTTYLogger())
#endif

        // MARK: - Control Plane setup

        guard let iotServiceInfo = AWSInfo.default().serviceInfo("IoT", forKey: "Default"),
              let iotManagerServiceInfo = AWSInfo.default().serviceInfo("IoTManager", forKey: "Default"),
              let iotDataManagerServiceInfo = AWSInfo.default().serviceInfo("IoTDataManager", forKey: "Default")  else {
            fatalError("Failed to read in default service info for IoT")
        }

#if DEBUG
        print("IoT: \(iotServiceInfo.infoDictionary["Endpoint"] ?? "")")
        print("IoT Manager: \(iotManagerServiceInfo.infoDictionary["Endpoint"] ?? "")")
        print("IoT Data Manager: \(iotDataManagerServiceInfo.infoDictionary["Endpoint"] ?? "")")
#endif

        let iot = AWSIoT.default()
        guard let credentialsProvider = iot.configuration.credentialsProvider as? AWSCognitoCredentialsProvider else {
            fatalError("App must be configured")
        }

        let region = iotServiceInfo.region
        let controlPlaneServiceConfiguration = AWSServiceConfiguration(region:region, credentialsProvider:credentialsProvider)
        AWSServiceManager.default().defaultServiceConfiguration = controlPlaneServiceConfiguration
        iotManager = AWSIoTManager.default()

        self.region = region
        self.credentialsProvider = credentialsProvider

        // MARK: - Data Plane setup

        guard let iotDataManagerEndpoint = iotDataManagerServiceInfo.endpoint else {
            fatalError("Failed to get Data Manager endpoint")
        }

        guard let dataConfiguration = AWSServiceConfiguration(region: iotDataManagerServiceInfo.region,
                                                              endpoint: iotDataManagerEndpoint,
                                                              credentialsProvider: credentialsProvider) else {
            fatalError("Failed to create Data Configuration")
        }

        // Configure MQTT with Last Will & Testament (LWT)
        let mqttConfiguration = AWSIoTMQTTConfiguration()
        let message = "LWT-\(Date())"
        mqttConfiguration.lastWillAndTestament.message = message
        mqttConfiguration.lastWillAndTestament.topic = "lwt/disconnected"
        mqttConfiguration.lastWillAndTestament.qos = .messageDeliveryAttemptedAtLeastOnce
        mqttConfiguration.lastWillAndTestament.willRetain = true

        AWSIoTDataManager.register(with: dataConfiguration, with: mqttConfiguration, forKey: Constants.dataManagerKey)
        iotDataManager = AWSIoTDataManager(forKey: Constants.dataManagerKey)

        // Control Plane
        assertEqual(iotServiceInfo.infoDictionary["Endpoint"] as? String, iot.configuration.endpoint.url.absoluteString)
        assertEqual(iotManagerServiceInfo.infoDictionary["Endpoint"] as? String, iotManager.configuration.endpoint.url.absoluteString)

        // Data Plane
        assertEqual(iotDataManagerServiceInfo.infoDictionary["Endpoint"] as? String, iotDataManager.configuration.endpoint.url.absoluteString)
    }

This is the function to connect.

    func connectWithWebSocket(clientId: String) {
        dispatchPrecondition(condition: .notOnQueue(.main))
        log("Connecting with Web Socket")

        if iotDataManager.connectUsingWebSocket(withClientId: clientId, cleanSession: true, statusCallback: self.mqttStatusCallback(_:)) {
            log("Started connection")
        } else {
            log("Failed to connect")
        }
    }

See that it does not pass in tokenValue or tokenSignature. That is not necessary when you have provided a credentials provider to your AWSIoTDataManager.

In the init function it creates credentialsProvider by defaulting to AWSCognitoCredentialsProvider. If you are not going to use that I see you were using AWSMobileClient.default() which you could use as a credentials provider. Use that instead. It conforms to the AWSCredentialsProvider protocol.

JyotsnaPiOSDEV commented 2 years ago
        guard let iotServiceInfo = AWSInfo.default().serviceInfo("IoT", forKey: "Default"),
              let iotManagerServiceInfo = AWSInfo.default().serviceInfo("IoTManager", forKey: "Default"),
              let iotDataManagerServiceInfo = AWSInfo.default().serviceInfo("VirginiaIoTDataManager", forKey: "Default")  else {
            print("Failed to read in default service info for IoT")
            return
        }

Result - print("Failed to read in default service info for IoT") I am using AWSIoT'SDK not amplify

brennanMKE commented 2 years ago

You need to define each of the IoT sections in awsconfiguration.json. Change the config below to match your region (currently set to us-east-1) and the value for CHANGE_ME which is for your IoT data plane.

    "IoT": {
        "Default": {
            "Region": "us-east-1",
            "Endpoint": "https://iot.us-east-1.amazonaws.com"
        }
    },
    "IoTManager": {
        "Default": {
            "Region": "us-east-1",
            "Endpoint": "https://iot.us-east-1.amazonaws.com"
        }
    },
    "IoTDataManager": {
        "Default": {
            "Region": "us-east-1",
            "Endpoint": "https://CHANGE_ME-ats.iot.us-east-1.amazonaws.com"
        }
    },
JyotsnaPiOSDEV commented 2 years ago

All configuration done let clientId = UUID().uuidString self.connectWithWebSocket(clientId: clientId)

2022-07-11 13:21:15:085 Votion Home[7211:205865] [SR] NSStreamEventOpenCompleted <__NSCFInputStream: 0x7b24000192c0> 2022-07-11 13:21:15:085 Votion Home[7211:205865] [SR] Connected 2022-07-11 13:21:15:085 Votion Home[7211:205865] [SR] GET /mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAW4FR7BZXXZ4C7Q5E%2F20220711%2Fus-east-1%2Fiotdata%2Faws4_request&X-Amz-Date=20220711T075114Z&X-Amz-SignedHeaders=host&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEAgaCXVzLWVhc3QtMSJHMEUCIQD2C0vXZNyTD%2Fey%2B6HLluLeOuLJWWQS0H3CqT63YAGhTAIgXAwrykC8gU%2BiYsDeI7Wy9YUMa7NF%2BilqPkhJQqFj1XkqxAQIQBABGgw0NzI4MTk2MzM3NzUiDHfp3tYdW1RFRww4VCqhBHc8oXP1q53y%2FA3N%2FTtuQeScSSe3nD1k5JZecJveZHZ2k1IEHHMqR%2F%2FDn%2BJ1En0E2RxAVjMwjlh4PD26KQNyKwXBKLpIgMyM2RW%2FxNBpBhT9iSqSruYcrJ0%2BOHsE94swc9v5OMY9tVYSKMgIC1QEBJzL1q3GCMfY00WhZrqUGeN7QmOH4LV6sBXMiqzu6sEbcM1ol1mM85IpzFFcXPMLSsr%2FTippArjcqh8Ha381MnJqhl%2BwSh8Yb9i26im6Ojp4y4M0zWX0LS2rLedlYstEjW6pq1TTur3Ic8VW8vE8dHQBEsVcZvJuaga5lJApa%2BcDzyH8aUBwjGBeNyyqs%2FjiWi6lxUd7eQ15Jfp2i%2BArjXYORjdJXoPDoNFVjujzyYT%2F%2FQDF2Zmfjp9gMfiuL1M0ViktsD%2BK1%2BHaE40ciPujrKu5pP%2B1hj1bX5s8gMz4kh4gwX3auPenV0IRCjFEzRUDC2qgM6jZhsx1um3kSwxdt7QMQ6yZB%2FMUw%2Bs4El2Q1UvmFDTinh%2BtaBG8fJ3MR2xFWGmfxmx5m7Bqm3%2BfwiQhX3fbZV9XGoA6hhvSTs18rG%2BMpDJk1DdRWrRfmdyERRETZFsrbUGCnT%2F0C4z1jFLk8kVsrMLkeQdaeECYTl61NFlXcfq8zoj5zKeTl5FISHyXO76dYkyfdM7uDY5zHKHcbqRwoLxRG0zawwHQIDpbpZ8idn9iuBHWvu2BCPaxUUr4e6FiMJmZr5YGOoUC7vWoNkRVpkW1dAhnHk4cyRmv3Pg%2BXsfMqPXTTGE5LuZFC8VBdJNhX2Bx3xLvf2GtH0q2zLtc23BZCqQ00bNDt3aKR14mkx4tknVTljNpX5kLz%2F1RR4Jl%2FPStfSvQRryGMAQClWaRSghvh92ffMjbqZZ5bIMPnNaznDfnfLASF8UMWVDh7p9pfW3cpTBac1r8DpwYZxu7KfCqkWng8N0%2BtVCNPqoWRu%2Frxs3mzsTZaNDAinkZIqdpsRPoT4yLzPDWTlBL%2FvPfU1b%2F9TC%2FQ8XkT7Ve3IvITrVx0jmJ10nT9Es6gKFlM47uEP1PP5FDjbsI3gZpVVw20FWXJ8VPxkxnVgChJq60&X-Amz-Signature=fc5ab3564f508bccd398cb832f4553ab8a6acf39d18225a9ef49480cedc9786a HTTP/1.1 Host: a2voxa1cppcped-ats.iot.us-east-1.amazonaws.com Sec-WebSocket-Protocol: mqttv3.1 Sec-WebSocket-Key: Sec-WebSocket-Version: 13 Upgrade: websocket Origin: https://a2voxa1cppcped-ats.iot.us-east-1.amazonaws.com Connection: Upgrade

2022-07-11 13:21:15:086 Votion Home[7211:205865] [SR] NSStreamEventOpenCompleted <NSCFOutputStream: 0x7b2400019980> 2022-07-11 13:21:15:938 Votion Home[7211:206200] [SR] NSStreamEventHasSpaceAvailable <NSCFOutputStream: 0x7b2400019980> 2022-07-11 13:21:15:939 Votion Home[7211:206200] [SR] NSStreamEventHasSpaceAvailable <NSCFOutputStream: 0x7b2400019980> 2022-07-11 13:21:16:245 Votion Home[7211:205895] [SR] NSStreamEventHasBytesAvailable <NSCFInputStream: 0x7b24000192c0> 2022-07-11 13:21:16:245 Votion Home[7211:205895] [SR] Finished reading headers { "Access-Control-Allow-Origin" = "*"; Connection = upgrade; "Content-Length" = 0; "Sec-WebSocket-Accept" = "2M9UvzWxJQpYXAHdPfWMjB3cSfU="; "Sec-WebSocket-Protocol" = "mqttv3.1"; Upgrade = websocket; "access-control-expose-headers" = "x-amzn-ErrorMessage, x-amzn-RequestId, x-amzn-ErrorType, Date"; } 2022-07-11 13:21:16:246 Votion Home[7211:205895] [SR] using _delegateDispatchQueue. 2022-07-11 13:21:16:246 Votion Home[7211:206123] Websocket did open and is connected. 2022-07-11 13:21:16:247 Votion Home[7211:206123] Issued Cancel on thread [<NSThread: 0x7b1000093f40>{number = 26, name = (null)}] 2022-07-11 13:21:16:248 Votion Home[7211:206207] <<<NSThread: 0x7b10000f2800>{number = 30, name = (null)}>> Initializing MQTTEncoder and MQTTDecoder streams 2022-07-11 13:21:16:248 Votion Home[7211:206207] opening encoder stream. 2022-07-11 13:21:16:248 Votion Home[7211:206207] opening decoder stream. 2022-07-11 13:21:16:249 Votion Home[7211:206207] -[AWSMQTTEncoder stream:handleEvent:] [Line 59] EventCode:1, Thread: <NSThread: 0x7b10000f2800>{number = 30, name = (null)} 2022-07-11 13:21:16:249 Votion Home[7211:206207] -[AWSMQTTEncoder stream:handleEvent:] [Line 59] EventCode:4, Thread: <NSThread: 0x7b10000f2800>{number = 30, name = (null)} 2022-07-11 13:21:16:249 Votion Home[7211:206207] MQTTEncoderStatus = 0 2022-07-11 13:21:16:249 Votion Home[7211:206207] -[AWSMQTTSession encoder:handleEvent:] [Line 335], eventCode: 0 2022-07-11 13:21:16:249 Votion Home[7211:206207] MQTTSessionStatus = 0 2022-07-11 13:21:16:249 Votion Home[7211:206207] waiting on encodeSemaphore 2022-07-11 13:21:16:249 Votion Home[7211:206207] passed encodeSempahore. 2022-07-11 13:21:16:250 Votion Home[7211:206207] sending 125 bytes 2022-07-11 13:21:16:250 Votion Home[7211:206207] signaling encodeSemaphore 2022-07-11 13:21:16:250 Votion Home[7211:206207] <<<NSThread: 0x7b10000f2800>{number = 30, name = (null)}>>: Encoder finished writing message 2022-07-11 13:21:16:250 Votion Home[7211:206123] [SR] NSStreamEventHasSpaceAvailable <NSCFOutputStream: 0x7b2400019980> 2022-07-11 13:21:16:250 Votion Home[7211:206207] -[AWSMQTTDecoder stream:handleEvent:] [Line 63] EventCode:1, status:0, stream: <NSCFInputStream: 0x7b240004dbb0>, Thread: <NSThread: 0x7b10000f2800>{number = 30, name = (null)} 2022-07-11 13:21:16:553 Votion Home[7211:206200] [SR] NSStreamEventHasBytesAvailable <NSCFInputStream: 0x7b24000192c0> 2022-07-11 13:21:16:553 Votion Home[7211:206200] [SR] Received close frame 2022-07-11 13:21:16:553 Votion Home[7211:206200] [SR] NSStreamEventHasBytesAvailable <NSCFInputStream: 0x7b24000192c0> 2022-07-11 13:21:16:554 Votion Home[7211:206200] [SR] NSStreamEventEndEncountered <__NSCFInputStream: 0x7b24000192c0> 2022-07-11 13:21:16:554 Votion Home[7211:206200] [SR] Closing with code 1000 reason (null) connection status = 5 Connection Error 2022-07-11 13:21:16:554 Votion Home[7211:206200] [SR] Trying to disconnect 2022-07-11 13:21:16:555 Votion Home[7211:206200] [SR] using _delegateDispatchQueue. 2022-07-11 13:21:16:555 Votion Home[7211:206200] [SR] NSStreamEventEndEncountered <NSCFOutputStream: 0x7b2400019980> 2022-07-11 13:21:16:557 Votion Home[7211:205865] WebSocket closed with code:1001 with reason:Stream end encountered 2022-07-11 13:21:16:562 Votion Home[7211:206207] -[AWSMQTTDecoder stream:handleEvent:] [Line 63] EventCode:2, status:1, stream: <NSCFInputStream: 0x7b240004dbb0>, Thread: <NSThread: 0x7b10000f2800>{number = 30, name = (null)} 2022-07-11 13:21:16:563 Votion Home[7211:206207] -[AWSMQTTDecoder stream:handleEvent:] [Line 63] EventCode:16, status:1, stream: <NSCFInputStream: 0x7b240004dbb0>, Thread: <NSThread: 0x7b10000f2800>{number = 30, name = (null)} 2022-07-11 13:21:16:563 Votion Home[7211:206207] -[AWSMQTTSession decoder:handleEvent:] [Line 376] eventCode:1 2022-07-11 13:21:16:564 Votion Home[7211:206207] MQTT session error, code: 2 2022-07-11 13:21:16:573 Votion Home[7211:206207] closing encoder stream. 2022-07-11 13:21:16:573 Votion Home[7211:206207] closing decoder stream. connection status = 5 2022-07-11 13:21:17:577 Votion Home[7211:206207] MQTTSessionDelegate handleEvent: 2 Connection Error 2022-07-11 13:21:17:578 Votion Home[7211:206207] MQTTSessionEventConnectionClosed: MQTT session closed. 2022-07-11 13:21:30:816 Votion Home[7211:206122] Attempting to reconnect. 2022-07-11 13:21:30:816 Votion Home[7211:206122] AWSIoTMQTTClient: connecting via websocket. connection status = 1 Connecting... 2022-07-11 13:21:30:816 Votion Home[7211:206122] Using AWSCredentials. 2022-07-11 13:21:30:821 Votion Home[7211:206261] user metadata is : ?SDK=iOS&Version=2.27.10 2022-07-11 13:21:30:821 Votion Home[7211:206261] Metrics collection is: Enabled 2022-07-11 13:21:30:823 Votion Home[7211:206261] Websocket is created and opened. 2022-07-11 13:21:31:083 Votion Home[7211:206261] [SR] NSStreamEventOpenCompleted <NSCFInputStream: 0x7b2400038250> 2022-07-11 13:21:31:083 Votion Home[7211:206261] [SR] Connected 2022-07-11 13:21:31:083 Votion Home[7211:206261] [SR] GET /mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAW4FR7BZXXZ4C7Q5E%2F20220711%2Fus-east-1%2Fiotdata%2Faws4_request&X-Amz-Date=20220711T075130Z&X-Amz-SignedHeaders=host&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEAgaCXVzLWVhc3QtMSJHMEUCIQD2C0vXZNyTD%2Fey%2B6HLluLeOuLJWWQS0H3CqT63YAGhTAIgXAwrykC8gU%2BiYsDeI7Wy9YUMa7NF%2BilqPkhJQqFj1XkqxAQIQBABGgw0NzI4MTk2MzM3NzUiDHfp3tYdW1RFRww4VCqhBHc8oXP1q53y%2FA3N%2FTtuQeScSSe3nD1k5JZecJveZHZ2k1IEHHMqR%2F%2FDn%2BJ1En0E2RxAVjMwjlh4PD26KQNyKwXBKLpIgMyM2RW%2FxNBpBhT9iSqSruYcrJ0%2BOHsE94swc9v5OMY9tVYSKMgIC1QEBJzL1q3GCMfY00WhZrqUGeN7QmOH4LV6sBXMiqzu6sEbcM1ol1mM85IpzFFcXPMLSsr%2FTippArjcqh8Ha381MnJqhl%2BwSh8Yb9i26im6Ojp4y4M0zWX0LS2rLedlYstEjW6pq1TTur3Ic8VW8vE8dHQBEsVcZvJuaga5lJApa%2BcDzyH8aUBwjGBeNyyqs%2FjiWi6lxUd7eQ15Jfp2i%2BArjXYORjdJXoPDoNFVjujzyYT%2F%2FQDF2Zmfjp9gMfiuL1M0ViktsD%2BK1%2BHaE40ciPujrKu5pP%2B1hj1bX5s8gMz4kh4gwX3auPenV0IRCjFEzRUDC2qgM6jZhsx1um3kSwxdt7QMQ6yZB%2FMUw%2Bs4El2Q1UvmFDTinh%2BtaBG8fJ3MR2xFWGmfxmx5m7Bqm3%2BfwiQhX3fbZV9XGoA6hhvSTs18rG%2BMpDJk1DdRWrRfmdyERRETZFsrbUGCnT%2F0C4z1jFLk8kVsrMLkeQdaeECYTl61NFlXcfq8zoj5zKeTl5FISHyXO76dYkyfdM7uDY5zHKHcbqRwoLxRG0zawwHQIDpbpZ8idn9iuBHWvu2BCPaxUUr4e6FiMJmZr5YGOoUC7vWoNkRVpkW1dAhnHk4cyRmv3Pg%2BXsfMqPXTTGE5LuZFC8VBdJNhX2Bx3xLvf2GtH0q2zLtc23BZCqQ00bNDt3aKR14mkx4tknVTljNpX5kLz%2F1RR4Jl%2FPStfSvQRryGMAQClWaRSghvh92ffMjbqZZ5bIMPnNaznDfnfLASF8UMWVDh7p9pfW3cpTBac1r8DpwYZxu7KfCqkWng8N0%2BtVCNPqoWRu%2Frxs3mzsTZaNDAinkZIqdpsRPoT4yLzPDWTlBL%2FvPfU1b%2F9TC%2FQ8XkT7Ve3IvITrVx0jmJ10nT9Es6gKFlM47uEP1PP5FDjbsI3gZpVVw20FWXJ8VPxkxnVgChJq60&X-Amz-Signature=4c94748ad5b4ef07b6cd2781c6d6d90a0d7a7e8e840c1095232c7e832b159fd4 HTTP/1.1 Host: Sec-WebSocket-Protocol: mqttv3.1 Sec-WebSocket-Key: u00pgMRKJeT+h7LER6+6hA== Sec-WebSocket-Version: 13 Upgrade: websocket Origin: "" Connection: Upgrade

2022-07-11 13:21:31:084 Votion Home[7211:206261] [SR] NSStreamEventOpenCompleted <NSCFOutputStream: 0x7b2400038370> 2022-07-11 13:21:31:914 Votion Home[7211:206261] [SR] NSStreamEventHasSpaceAvailable <NSCFOutputStream: 0x7b2400038370> 2022-07-11 13:21:31:915 Votion Home[7211:206315] [SR] NSStreamEventHasSpaceAvailable <NSCFOutputStream: 0x7b2400038370> 2022-07-11 13:21:32:219 Votion Home[7211:206263] [SR] NSStreamEventHasBytesAvailable <NSCFInputStream: 0x7b2400038250> 2022-07-11 13:21:32:220 Votion Home[7211:206263] [SR] Finished reading headers { "Access-Control-Allow-Origin" = "*"; Connection = upgrade; "Content-Length" = 0; "Sec-WebSocket-Accept" = "ENt418g2e9FlsA827X7zzUyywBk="; "Sec-WebSocket-Protocol" = "mqttv3.1"; Upgrade = websocket; "access-control-expose-headers" = "x-amzn-ErrorMessage, x-amzn-RequestId, x-amzn-ErrorType, Date"; } 2022-07-11 13:21:32:220 Votion Home[7211:206263] [SR] using _delegateDispatchQueue. 2022-07-11 13:21:32:220 Votion Home[7211:206315] Websocket did open and is connected. 2022-07-11 13:21:32:221 Votion Home[7211:206315] Issued Cancel on thread [<NSThread: 0x7b10000f2800>{number = 30, name = (null)}] 2022-07-11 13:21:32:223 Votion Home[7211:206321] <<<NSThread: 0x7b10000f2fc0>{number = 36, name = (null)}>> Initializing MQTTEncoder and MQTTDecoder streams 2022-07-11 13:21:32:223 Votion Home[7211:206321] opening encoder stream. 2022-07-11 13:21:32:223 Votion Home[7211:206321] opening decoder stream. 2022-07-11 13:21:32:224 Votion Home[7211:206321] -[AWSMQTTEncoder stream:handleEvent:] [Line 59] EventCode:1, Thread: <NSThread: 0x7b10000f2fc0>{number = 36, name = (null)} 2022-07-11 13:21:32:224 Votion Home[7211:206321] -[AWSMQTTEncoder stream:handleEvent:] [Line 59] EventCode:4, Thread: <NSThread: 0x7b10000f2fc0>{number = 36, name = (null)} 2022-07-11 13:21:32:224 Votion Home[7211:206321] MQTTEncoderStatus = 0 2022-07-11 13:21:32:224 Votion Home[7211:206321] -[AWSMQTTSession encoder:handleEvent:] [Line 335], eventCode: 0 2022-07-11 13:21:32:225 Votion Home[7211:206321] MQTTSessionStatus = 0 2022-07-11 13:21:32:225 Votion Home[7211:206321] waiting on encodeSemaphore 2022-07-11 13:21:32:225 Votion Home[7211:206321] passed encodeSempahore. 2022-07-11 13:21:32:225 Votion Home[7211:206321] sending 125 bytes 2022-07-11 13:21:32:225 Votion Home[7211:206321] signaling encodeSemaphore 2022-07-11 13:21:32:227 Votion Home[7211:206321] <<<NSThread: 0x7b10000f2fc0>{number = 36, name = (null)}>>: Encoder finished writing message 2022-07-11 13:21:32:227 Votion Home[7211:206321] -[AWSMQTTDecoder stream:handleEvent:] [Line 63] EventCode:1, status:0, stream: <NSCFInputStream: 0x7b2400039840>, Thread: <NSThread: 0x7b10000f2fc0>{number = 36, name = (null)} 2022-07-11 13:21:32:228 Votion Home[7211:206123] [SR] NSStreamEventHasSpaceAvailable <NSCFOutputStream: 0x7b2400038370> 2022-07-11 13:21:32:528 Votion Home[7211:206315] [SR] NSStreamEventHasBytesAvailable <NSCFInputStream: 0x7b2400038250> 2022-07-11 13:21:32:528 Votion Home[7211:206315] [SR] Received close frame 2022-07-11 13:21:32:528 Votion Home[7211:206315] [SR] NSStreamEventHasBytesAvailable <NSCFInputStream: 0x7b2400038250> 2022-07-11 13:21:32:528 Votion Home[7211:206315] [SR] NSStreamEventEndEncountered <__NSCFInputStream: 0x7b2400038250> connection status = 5 Connection Error 2022-07-11 13:21:32:529 Votion Home[7211:206315] [SR] Closing with code 1000 reason (null) 2022-07-11 13:21:32:529 Votion Home[7211:206315] [SR] Trying to disconnect 2022-07-11 13:21:32:529 Votion Home[7211:206315] [SR] using _delegateDispatchQueue. 2022-07-11 13:21:32:529 Votion Home[7211:206315] [SR] NSStreamEventEndEncountered <NSCFOutputStream: 0x7b2400038370> 2022-07-11 13:21:32:530 Votion Home[7211:206261] WebSocket closed with code:1001 with reason:Stream end encountered 2022-07-11 13:21:32:533 Votion Home[7211:206321] -[AWSMQTTDecoder stream:handleEvent:] [Line 63] EventCode:2, status:1, stream: <NSCFInputStream: 0x7b2400039840>, Thread: <NSThread: 0x7b10000f2fc0>{number = 36, name = (null)} 2022-07-11 13:21:32:533 Votion Home[7211:206321] -[AWSMQTTDecoder stream:handleEvent:] [Line 63] EventCode:16, status:1, stream: <__NSCFInputStream: 0x7b2400039840>, Thread: <NSThread: 0x7b10000f2fc0>{number = 36, name = (null)} 2022-07-11 13:21:32:533 Votion Home[7211:206321] -[AWSMQTTSession decoder:handleEvent:] [Line 376] eventCode:1 2022-07-11 13:21:32:534 Votion Home[7211:206321] MQTT session error, code: 2 2022-07-11 13:21:32:543 Votion Home[7211:206321] closing encoder stream. 2022-07-11 13:21:32:543 Votion Home[7211:206321] closing decoder stream. 2022-07-11 13:21:33:544 Votion Home[7211:206321] MQTTSessionDelegate handleEvent: 2 connection status = 5 Connection Error 2022-07-11 13:21:33:544 Votion Home[7211:206321] MQTTSessionEventConnectionClosed: MQTT session closed.

harsh62 commented 9 months ago

Our team is trying to look into the issue and will provide an update soon.