0

I need list of things in group or list of things from AWS with that I tried to find solution from AWSIoT Reference So i have used below code to get it. Previously i used to get it using normal API call from our backend service but i need fully use with AWS.

   func initializeAWS() {

       let credentialsProvider = AWSCognitoCredentialsProvider(regionType:AWS_REGION,
                                                               identityPoolId:IDENTITY_POOL_ID)
       initializeControlPlane(credentialsProvider: credentialsProvider)

   }

   func initializeControlPlane(credentialsProvider: AWSCredentialsProvider) {

       let controlPlaneServiceConfiguration = AWSServiceConfiguration(region:AWS_REGION, credentialsProvider:credentialsProvider)

       AWSServiceManager.default().defaultServiceConfiguration = controlPlaneServiceConfiguration
       iot = AWSIoT.default()

       let request = AWSIoTListThingsInThingGroupRequest()
       request?.thingGroupName = "XXXGroupName"
       let output = iot.listThings(inThingGroup: request!)
       print("output is \(output.result)")
       print("error is \(output.error)")

   }

I have used here AWSIoT & AWSIoTListThingsInThingGroupRequest object to get list of things may i know is this right way to fetch ? if it is I'm output and error both objects getting nil.

I tried to find solution for the AWS IOT example from Github, I didnt get anything relevant answer to this. Or is there anything in iotDataManager that will give list of things ? Please can you help me on this ? For more info I have raised question on AWS Github Fetching list of things in things group

Shrikant K
  • 1,988
  • 2
  • 23
  • 34

1 Answers1

0

I've checked log level output was getting, All configurations as well was right only thing i wasn't aware about is how to get response of things, the way to get things is as below.

let credentialsProvider = AWSCognitoCredentialsProvider(regionType:AWS_REGION,
                                                        identityPoolId:IDENTITY_POOL_ID)

let controlPlaneServiceConfiguration = AWSServiceConfiguration(region:AWS_REGION, credentialsProvider:credentialsProvider)

AWSServiceManager.default().defaultServiceConfiguration = controlPlaneServiceConfiguration
iot = AWSIoT.default()

let request = AWSIoTListThingsInThingGroupRequest()
request?.thingGroupName = "XXXGroupName"
let output = iot.listThings(inThingGroup: request!)

output.continueOnSuccessWith { (response) -> Any? in

    if let result = response.result, let things = result.things {
        self.awsDevices = things
        completionHandler(true)
    }
    return self.awsDevices

}
Shrikant K
  • 1,988
  • 2
  • 23
  • 34