Closed noblerabbit closed 5 years ago
Hi,
This error seems to be caused by having null in json files, could you check your awsconfiguration.json and see if there's any nulls?
This is the awsconfiguration.json. Thanks.
{
"UserAgent": "MobileHub/1.0",
"Version": "1.0",
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "us-east-2:236xxxxx-xxxx-xxxx-xxxx-47f65c34xxxx",
"Region": "us-east-2"
}
}
},
"IdentityManager": {
"Default": {}
},
"CognitoUserPool": {
"Default": {
"PoolId": "us-east-2_nfuT3xxxx",
"AppClientId": "4edgto1lril04q9j5xxxxxxx",
"AppClientSecret": "5mua76u8s3qfpdf8cjp0xxxxxxxxxxxxx",
"Region": "us-east-2"
}
}
}
I followed the instructions from the tutorial (https://docs.aws.amazon.com/freertos/latest/userguide/ble-demo.html#ble-sdk-app):
- Open amazon-freertos-ble-ios-sdk/Example/AmazonFreeRTOSDemo/AmazonFreeRTOSDemo/Support/awsconfiguration.json.
Under CognitoIdentity, redefine the following variables:
PoolId: Your Amazon Cognito identity pool ID.
Region: Your AWS Region.
Under CognitoUserPool, redefine the following variables:
PoolId: Your Amazon Cognito user pool ID.
AppClientId: Your app client ID.
AppClientSecret: Your app client secret.
Region: Your AWS Region.
That looks correct to me. I just pulled down the repo and tested with my credentials and it works correctly. If the crash happens after you enter username and password and click login, then its most likely due to
trying to attach to your iot policy, which is what you put in the AmazonConstants.swift.
Could you check if that policy is in the same region (us-east-2), the name is correct and also perform a clean build (Xcode > product > clean)
I added Thing through "python SetupAWS.py setup" (https://docs.aws.amazon.com/freertos/latest/userguide/getting_started_espressif.html). MQTT over wifi example is working.
I got IoT policy name from AWS IoT console > Manage > Things > Esp32CapBLE > Security > 8a6ea80ca3f5eef27468... > Policies > Esp32CapBLE_amazon_freertos_policy.
Here is the AmazonConstants.swift:
import AWSCore
import CoreBluetooth
import Foundation
struct AmazonConstants {
struct AWS {
// #error("Replace with your AWS Region. eg: AWSRegionType.USEast1")
static let region = AWSRegionType.USEast2
// #error("Replace with your AWS IoT Policy Name. eg: MyIoTPolicy")
static let iotPolicyName = "Esp32CapBLE_amazon_freertos_policy"
// #error("Also update FreeRTOSDemo/Support/awsconfiguration.json with your credentials.")
static let mqttCustomTopic = "freertos/demos/echo"
}
}
Thanks.
Xuan,
I am still getting the exception.
Can you please let me know if AmazonConstants.swift is ok or not. Thanks. Here is also a screenshot from the aws iot, regarding the iot policy.
fyi if i put the iphone to airplane mode, then it does not crash and I can connect to the microcontroller through the app...
AmazonConstants looks correct. This is very strange, turning on Wifi crash is probably because it send/receive something from the server that has some issue. If you could create a private repo with your credentials and add me as collaborator, I can try it on my side.
Thanks Xuan. Here is the link with my credentials. https://github.com/noblerabbit/amazon-freertos-ble-ios-sdk-beta.
By turning on AWS Debug log
{"Message":"User: arn:aws:xxxxxxxx is not authorized to perform: iot:AttachPrincipalPolicy on resource: us-east-2:xxxxx"}
It says that the cognito role does not have the iot:AttachPrincipalPolicy permission. You could add this by go to IAM -> Roles -> your auth role -> edit policy in ison and make sure its
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:Connect", "iot:Publish", "iot:Subscribe", "iot:Receive", "iot:GetThingShadow", "iot:UpdateThingShadow", "iot:DeleteThingShadow", "iot:AttachPrincipalPolicy" ], "Resource": [ "*" ] } ] }
Xuan,
I added the policy as you wrote and now the app does not crash anymore.
Thanks so much for your help. Have a great day!
Hi,
I have followed the instructions on how to set up the demo ios app (modified awsconfiguration.json, AmazonConstants.swift). The build is successful. The app runs. I am able to create a new account, get SMS confirmation, and then login into the app. This is when I get the following exception: 2019-02-09 18:49:53.712659+0100 AmazonFreeRTOSDemo[18854:7075888] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull _fastCStringContents:]: unrecognized selector sent to instance 0x251c399b0'
Any suggestions?
Thanks.