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 885 forks source link

Connecting to the AWS IoT Service from iOS #1612

Closed adanaj closed 5 years ago

adanaj commented 5 years ago

State your question When following the readme, and making the changes on the iOS demo application, the device never connects to the IoT Service.

This is my output

2019-06-17 09:45:10:671 IoTSampleSwift[1768:1800959] Couldn't read the region configuration from awsconfiguration.json / Info.plist. Please check your configuration file if you are loading the configuration through it. 2019-06-17 09:45:36:578 IoTSampleSwift[1768:1800959] AWSMobileClient -> sharedInstance... 2019-06-17 09:45:36:578 IoTSampleSwift[1768:1800959] AWSMobileClient -> sharedInstance... AWSMobileClient initialized. 2019-06-17 09:47:16:776 IoTSampleSwift[1768:1800959] Initializing AWSIoTMqttConfiguration with KeepAlive:300.000000, baseReconnectTime:1.000000,minimumConnectionTime:20.000000, maximumReconnectTime:128.000000, autoResubscribe:Enabled, lwt topic: message: 2019-06-17 09:47:21:129 IoTSampleSwift[1768:1800959] <<<NSThread: 0x281886dc0>{number = 1, name = main}>>In connectWithClientID 2019-06-17 09:47:21:130 IoTSampleSwift[1768:1800959] hostName: xxxxxxxxxxxx.iot.us-west-2.amazonaws.com 2019-06-17 09:47:21:130 IoTSampleSwift[1768:1800959] URL: https://a3g4ol08la2aua.iot.us-west-2.amazonaws.com 2019-06-17 09:47:21:144 IoTSampleSwift[1768:1800959] username is : ?SDK=iOS&Version=2.6.19 2019-06-17 09:47:21:144 IoTSampleSwift[1768:1800959] Metrics collection is: Enabled 2019-06-17 09:47:21:145 IoTSampleSwift[1768:1800959] -[AWSMQTTSession initWithClientId:userName:password:keepAlive:cleanSession:willTopic:willMsg:willQoS:willRetainFlag:publishRetryThrottle:] [Line 82], Thread:<NSThread: 0x281886dc0>{number = 1, name = main} 2019-06-17 09:47:21:145 IoTSampleSwift[1768:1800959] +[AWSMQTTMessage connectMessageWithClientId:userName:password:keepAlive:cleanSession:willTopic:willMsg:willQoS:willRetain:] [Line 66], Thread:<NSThread: 0x281886dc0>{number = 1, name = main} 2019-06-17 09:47:21:145 IoTSampleSwift[1768:1800959] Creating AWSMQTTMessage with raw data >>>>> <00044d51 54540482 012c0024 37353139 46423939 2d423144 372d3445 44412d39 3634362d 45453742 39393131 44374146 00173f53 444b3d69 4f532656 65727369 6f6e3d32 2e362e31 39> <<<<< connection status = 1 Connecting... 2019-06-17 09:47:21:151 IoTSampleSwift[1768:1801402] <<<NSThread: 0x2818cf280>{number = 3, name = (null)}>> Initializing MQTTEncoder and MQTTDecoder streams 2019-06-17 09:47:21:151 IoTSampleSwift[1768:1801402] opening encoder stream. 2019-06-17 09:47:21:213 IoTSampleSwift[1768:1801402] opening decoder stream. 2019-06-17 09:47:21.498143-0400 IoTSampleSwift[1768:1801402] CFNetwork SSLHandshake failed (-9807) 2019-06-17 09:47:21.498220-0400 IoTSampleSwift[1768:1801402] TCP Conn 0x283890240 SSLHandshake failed (-9807) 2019-06-17 09:47:21:498 IoTSampleSwift[1768:1801402] MQTT session error, code: 3 2019-06-17 09:47:21:498 IoTSampleSwift[1768:1801402] closing encoder stream. 2019-06-17 09:47:21:498 IoTSampleSwift[1768:1801402] closing decoder stream. 2019-06-17 09:47:22:504 IoTSampleSwift[1768:1801402] MQTTSessionEventConnectionError: Received an MQTT session connection error connection status = 5 Connection Error 2019-06-17 09:47:23:510 IoTSampleSwift[1768:1801410] Attempting to reconnect.

****The x's are the actually values for the endpoint from AWS

Which AWS Services are you utilizing? Cognito and IoT Provide code snippets (if applicable) awsconfiguration.json { "Version": "1.0", "IdentityManager": { "Default": {} }, "CredentialsProvider": { "CognitoIdentity": { "Default": { "PoolId": "us-west-2:", "Region": "us-west-2" } } } }

Constants.swift import Foundation import AWSCore

//WARNING: To run this sample correctly, you must set the following constants.

let CertificateSigningRequestCommonName = "AWS IoT iOS Application" let CertificateSigningRequestCountryName = "US" let CertificateSigningRequestOrganizationName = "Organization" let CertificateSigningRequestOrganizationalUnitName = "Unit Name" let PolicyName = "TestApp1"

// This is the endpoint in your AWS IoT console. eg: https://xxxxxxxxxx.iot..amazonaws.com let AWSRegion = AWSRegionType.USWest2 // e.g. AWSRegionType.USEast1 let IOT_ENDPOINT = "https://xxxxxxxxxxxxxxxx.iot.us-west-2.amazonaws.com" let ASWIoTDataManager = "MyIotDataManager"

Environment(please complete the following information):

Device Information (please complete the following information):

If you need help with understanding how to implement something in particular then we suggest that you first look into our developer guide. You can also simplify your process of creating an application, as well as the associated backend setup by using the Amplify CLI.

beilusen commented 5 years ago

How can you solve this problem? I also have this problem.

adanaj commented 5 years ago

I figured it out. If you attempted the connection, and one of the credentials was incorrect, it creates some variable that stores the info for future connection attempts. I made sure the credentials were correct, also permissions on the AWS server, and uninstall the app, then reinstall. It worked!