Code Monkey home page Code Monkey logo

Comments (9)

xuaninbox avatar xuaninbox commented on September 25, 2024

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?

from amazon-freertos-ble-ios-sdk.

noblerabbit avatar noblerabbit commented on September 25, 2024

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):

  1. 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.

from amazon-freertos-ble-ios-sdk.

xuaninbox avatar xuaninbox commented on September 25, 2024

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

AWSIoT.default().attachPrincipalPolicy(attachPrincipalPolicyRequest, completionHandler: { error in

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)

from amazon-freertos-ble-ios-sdk.

noblerabbit avatar noblerabbit commented on September 25, 2024

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.

from amazon-freertos-ble-ios-sdk.

noblerabbit avatar noblerabbit commented on September 25, 2024

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.

awsiotpolicy

fyi if i put the iphone to airplane mode, then it does not crash and I can connect to the microcontroller through the app...

from amazon-freertos-ble-ios-sdk.

xuaninbox avatar xuaninbox commented on September 25, 2024

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.

from amazon-freertos-ble-ios-sdk.

noblerabbit avatar noblerabbit commented on September 25, 2024

Thanks Xuan. Here is the link with my credentials. https://github.com/noblerabbit/amazon-freertos-ble-ios-sdk-beta.

from amazon-freertos-ble-ios-sdk.

xuaninbox avatar xuaninbox commented on September 25, 2024

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": [ "*" ] } ] }

from amazon-freertos-ble-ios-sdk.

noblerabbit avatar noblerabbit commented on September 25, 2024

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!

from amazon-freertos-ble-ios-sdk.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.