2017-04-14 4 views
-3

amazon 기반 웹 서비스에서 Amazon IOT에 정보를 보내고받은 다음 거기에서 메시지를 수신해야합니다. IOT에 연결하는 데 문제가 있습니다. MQTT와 IOT를 도와 줄 수있는 사람이 있습니다.Amazon Web Services MQTT

답변

-1

시도해보십시오. 그것은 당신을 도울 수 있습니다.

credentialsProvider = new CognitoCachingCredentialsProvider(
      getApplicationContext(), // context 
      COGNITO_POOL_ID, // Identity Pool ID 
      MY_REGION // Region); 

    Region region = Region.getRegion(MY_REGION); 

    // MQTT Client 
    mqttManager = new AWSIotMqttManager(clientId, CUSTOMER_SPECIFIC_ENDPOINT); 

    // Set keepalive to 10 seconds. Will recognize disconnects more quickly but will also send 
    // MQTT pings every 10 seconds. 
    mqttManager.setKeepAlive(10); 
    mIotAndroidClient = new AWSIotClient(credentialsProvider); 
    mIotAndroidClient.setRegion(region); 
    try { 
      mqttManager.connect(clientKeyStore, new AWSIotMqttClientStatusCallback() { 
       @Override 
       public void onStatusChanged(final AWSIotMqttClientStatus status, 
         final Throwable throwable) { 
        Log.d(LOG_TAG, "Status = " + String.valueOf(status)); 

        runOnUiThread(new Runnable() { 
         @Override 
         public void run() { 
          if (status == AWSIotMqttClientStatus.Connecting) { 
                   } else if (status == AWSIotMqttClientStatus.Connected) { 
           tvStatus.setText("Connected"); 

          } else if (status == AWSIotMqttClientStatus.Reconnecting) { 
           if (throwable != null) { 
            Log.e(LOG_TAG, "Connection error.", throwable); 
           } 
           tvStatus.setText("Reconnecting"); 
          } else if (status == AWSIotMqttClientStatus.ConnectionLost) { 
           if (throwable != null) { 
            Log.e(LOG_TAG, "Connection error.", throwable); 
           } 
                        } 
         } 
        }); 
       } 
      }); 
     } catch (final Exception e) { 
       } 
+0

감사합니다. :) –