투케이2K

971. (Android/Java) [간단 소스] Aws Iot Core 프로비저닝으로 생성 된 사물 목록 리스트 확인 - Thing Name List 본문

Android

971. (Android/Java) [간단 소스] Aws Iot Core 프로비저닝으로 생성 된 사물 목록 리스트 확인 - Thing Name List

투케이2K 2025. 4. 10. 18:48

[개발 환경 설정]

개발 툴 : AndroidStudio

개발 언어 : Java / Kotlin

 

[소스 코드]

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

- 언어 : Java / Kotlin

- 개발 툴 : AndroidStudio

- 기술 구분 : Aws / Iot / Provisioning

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






// --------------------------------------------------------------------------------------
[사전) 필요 설정 정리] : 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 [ListThingsRequest 사용해 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 [리젼 정보 설정]


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


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

            // [Thing 목록 요청 수행]
            ListThingsResult result = iotClient.listThings(request);

            List<ThingAttribute> things = result.getThings();

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

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

                    ThingAttribute thing = things.get(i);

                    String thingName = thing.getThingName();
                    String thingArn = thing.getThingArn();

                    S_Log.w("KWON_TWOK", ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ["+String.valueOf(thingName)+"] : ["+String.valueOf(thingArn)+"] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

                }

            }
            else {
                S_Log._E_(ACTIVITY_NAME + " :: device_Thing_Name_List :: [디바이스] :: 생성 된 Thing Name 리스트 목록 확인 실패", new String[]{"Thing 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

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