【问题标题】:Amazon Web Services MQTT亚马逊网络服务 MQTT
【发布时间】:2017-04-14 10:43:12
【问题描述】:

我正在开发基于亚马逊的网络服务,我必须在其中向 Amazon IOT 发送和接收一些信息,然后从那里接收一些消息。我在连接 IOT 时遇到问题,谁能帮我处理 MQTT 和 IOT。

【问题讨论】:

    标签: amazon iot


    【解决方案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) {
                    }
    

    【讨论】:

    • 不错不错不错不错
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-29
    • 2017-11-29
    • 2012-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多