Android

973. (Android/Java) [간단 소스] Aws Iot Core 사물 그룹 리스트 목록 확인 - Aws Thing Group List

투케이2K 2025. 4. 15. 20:16

[개발 환경 설정]

개발 툴 : AndroidStudio

개발 언어 : Java / Kotlin

 

[소스 코드]

// --------------------------------------------------------------------------------------
[개발 및 테스트 환경]
// --------------------------------------------------------------------------------------

- 언어 : Java / Kotlin

- 개발 툴 : AndroidStudio

- 기술 구분 : Aws / Iot / Thing Group

// --------------------------------------------------------------------------------------






// --------------------------------------------------------------------------------------
[사전) 필요 설정 정리] : build.gradle 의존성 부여
// --------------------------------------------------------------------------------------

// [AWS] : [target 31 이상 의존성]
implementation 'com.amazonaws:aws-android-sdk-kms:2.57.0'
implementation 'com.amazonaws:aws-android-sdk-s3:2.57.0'
implementation 'com.amazonaws:aws-android-sdk-iot:2.57.0'
implementation 'com.amazonaws:aws-android-sdk-mobile-client:2.57.0'


// [AWS] : [target 31 미만 의존성]
implementation 'com.amazonaws:aws-android-sdk-kms:2.16.13'
implementation 'com.amazonaws:aws-android-sdk-s3:2.16.13'
implementation 'com.amazonaws:aws-android-sdk-iot:2.16.13'
implementation 'com.amazonaws:aws-android-sdk-mobile-client:2.16.13'

// --------------------------------------------------------------------------------------





// --------------------------------------------------------------------------------------
[Java : 소스 코드]
// --------------------------------------------------------------------------------------

// -------------------------------------------------
// [변수 선언]
// -------------------------------------------------
String ACCESS_KEY = "AK...A6"; 
String SECRET_KEY = "mP...5J"; 
String REGION = "ap-northeast-2"; 



// -------------------------------------------------
// TODO [thing 목록 확인 수행]
// -------------------------------------------------
// TODO [ListThingGroupsRequest 사용해 http 통신을 수행하므로 Thread 처리 수행]
// -------------------------------------------------
new Thread(){
    @Override
    public void run(){

        // [AWS 자격 증명 설정]
        AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);


        // [AWS IoT 클라이언트 생성]
        AWSIot iotClient = new AWSIotClient(credentials);    
        iotClient.setRegion(Region.getRegion(REGION)); // TODO [리젼 정보 설정]


        // [ListThingGroupsRequest 생성] : 최대 30개의 목록만 요청 (withMaxResults)
        ListThingGroupsRequest request = new ListThingGroupsRequest().withMaxResults(30);


        // [로직 처리 수행]
        try {

            // [Thing Group 목록 요청 수행]
            ListThingGroupsResult result = iotClient.listThingGroups(request);

            List<GroupNameAndArn> groups = result.getThingGroups();

            if (groups != null && groups.size()>0){

                for (int i=0; i<groups.size(); i++) {

                    GroupNameAndArn group = groups.get(i);

                    JSONObject groupInfo = new JSONObject();

                    groupInfo.put("groupArn", String.valueOf(group.getGroupArn()));
                    groupInfo.put("groupName", String.valueOf(group.getGroupName()));

                    S_Log.w("KWON_TWOK", ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ["+String.valueOf(groupInfo)+"] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                }

            }
            else {
                S_Log._E_(ACTIVITY_NAME + " :: device_Thing_Group_List :: [디바이스] :: 매핑 될 Thing Group 리스트 확인 실패", new String[]{"ThingGroup List Is Null"});
            }

        } catch (Exception es) {
            es.printStackTrace();
        }

    }
}.start();

// --------------------------------------------------------------------------------------






// --------------------------------------------------------------------------------------
[참고 사이트]
// --------------------------------------------------------------------------------------

[Aws Iot Core 프로비저닝 수행 후 생성 된 사물 확인 및 인증서 정보 확인 방법]

https://blog.naver.com/kkh0977/223690097561


[안드로이드 Aws 프로비저닝 로직 정리]

https://blog.naver.com/kkh0977/223558081843?trackingCode=blog_bloghome_searchlist


[Aws Iot Core 프로비저닝 템플릿 (Template) 설명]

https://blog.naver.com/kkh0977/223698047733?trackingCode=blog_bloghome_searchlist

// --------------------------------------------------------------------------------------
 
반응형