Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

andorid cannot connect mqtt #3658

Closed
Wlazly opened this issue Jan 15, 2025 · 5 comments
Closed

andorid cannot connect mqtt #3658

Wlazly opened this issue Jan 15, 2025 · 5 comments
Labels
question General question

Comments

@Wlazly
Copy link

Wlazly commented Jan 15, 2025

Describe the bug

the logcat is:
I/AWSIotMqttManager(16659): resetting reconnect attempt and retry time
D/AWSIotMqttManager(16659): MQTT broker: wss://xxxxxx-ats.iot.ap-southeast-1.amazonaws.com/mqtt:443
D/AWSIotMqttManager(16659): ready to do mqtt connect
I/AWSIotMqttManager(16659): metrics collection is enabled, username: ?SDK=Android&Version=2.77.1
I/AWSIotMqttManager(16659): resetting reconnect attempt and retry time
D/AWSIotMqttManager(16659): Setting up Callback for MqttClient
W/AWSIotMqttManager(16659): onFailure: connection failed.

I/AWSIotMqttManager(16659): schedule Reconnect attempt 0 of 10 in 4 seconds.
D/AWSIotMqttManager(16659): TID: 19822 trying to reconnect to session
I/AWSIotMqttManager(16659): attempting to reconnect to mqtt broker
D/AWSIotMqttManager(16659): Reconnect to mqtt broker: wss://xxxxx-ats.iot.ap-southeast-1.amazonaws.com/mqtt mqttWebSocketURL: wss://wss://xxxxxx-ats.iot.ap-southeast-1.amazonaws.com/mqtt:443/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA2ZIOM6VNJBWZGRCI%2F20250115%2Fap-southeast-1%2Fiotdata%2Faws4_request&X-Amz-Date=20250115T035520Z&X-Amz-SignedHeaders=host&X-Amz-Signature=3a2e39e084d9895eadf487969b04ef7efd27bdddcefa4366781590a878d0c7ac&X-Amz-Security-Token=FwoGZXIvYXdzED0aDA1rOP6ik6NJUGNgECK9A2%2FMWDxqbJNBkAYELrQzzpUnQfK8WBePgE1zypa9LjlnhuIMVwI5NBEFwyjq%2FArxMkg1YnjzB5rsQUVkAKPkw4hN0jPJJiEaMPoYtjR2XpBovK3%2F3rzS9wAlKomwFzWPHfVdtHHoB3lHslEFNTpTr0sdHJzlt3EUwbeKQxx3K6oTBnOkrMy32ALRpyHYHtb4udYCFA3noNEBjjQsSBh4U4e8QVzdHRU0GaUes9geawPV7tz%2B277UK9C5voSPAQSTFzPIyFPr5dXNAIN0sc22Bk9MO3Y61l0kI7GUkgg8B%2FvWnIPnbSK0OkxDPr6B6M%2FRsLRn7wEIRzYHROy6BA1oExSBXQk3xzIDya6OB%2BcBIVnqmipt78pJQwu0%2FNaGjwx3aSkNyAUh%2Bn%2BDs%2FYQGKj5%2By6KEADJGO6OHErcckxeyNWivzii6PqhvLVPJ6dVpxWPaovBhc8xBfVg07vrihEZwg18DtGFUZ7hTlQR5Mm8kTtg70FMV5Efnq94prB8eamPYxlYN3bLtOe1W%2BuG4z70arCDPya5kUa5NQtVyoyLBXfZ1tTfp1ni4Hg58%2BquSJCI4ylm0fQxgbw0H5h%2F0Z0oo%2BOcvAYyLdg%2Bbqwn48vRIv%2B6hGJrOQFXPM7vHDUBdy0gb7q70XEn6Li60Ii45J%2BKP2RGdQ%3D%3D
D/AWSIotMqttManager(16659): Setting up Callback for MqttClient
D/AWSIotMqttManager(16659): mqtt reconnecting attempt 1
W/AWSIotMqttManager(16659): Reconnect failed

I/AWSIotMqttManager(16659): schedule Reconnect attempt 1 of 10 in 8 seconds.
D/AWSIotMqttManager(16659): TID: 19827 trying to reconnect to session
I/AWSIotMqttManager(16659): attempting to reconnect to mqtt broker
D/AWSIotMqttManager(16659): Reconnect to mqtt broker: wss://xxxxxx-ats.iot.ap-southeast-1.amazonaws.com/mqtt mqttWebSocketURL: wss://wss://xxxxxx-ats.iot.ap-southeast-1.amazonaws.com/mqtt:443/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA2ZIOM6VNJBWZGRCI%2F20250115%2Fap-southeast-1%2Fiotdata%2Faws4_request&X-Amz-Date=20250115T035528Z&X-Amz-SignedHeaders=host&X-Amz-Signature=4306b5c197afe94cb42941ebabf11ca1c4596c5d6fbc4c23679b903e7824167e&X-Amz-Security-Token=FwoGZXIvYXdzED0aDA1rOP6ik6NJUGNgECK9A2%2FMWDxqbJNBkAYELrQzzpUnQfK8WBePgE1zypa9LjlnhuIMVwI5NBEFwyjq%2FArxMkg1YnjzB5rsQUVkAKPkw4hN0jPJJiEaMPoYtjR2XpBovK3%2F3rzS9wAlKomwFzWPHfVdtHHoB3lHslEFNTpTr0sdHJzlt3EUwbeKQxx3K6oTBnOkrMy32ALRpyHYHtb4udYCFA3noNEBjjQsSBh4U4e8QVzdHRU0GaUes9geawPV7tz%2B277UK9C5voSPAQSTFzPIyFPr5dXNAIN0sc22Bk9MO3Y61l0kI7GUkgg8B%2FvWnIPnbSK0OkxDPr6B6M%2FRsLRn7wEIRzYHROy6BA1oExSBXQk3xzIDya6OB%2BcBIVnqmipt78pJQwu0%2FNaGjwx3aSkNyAUh%2Bn%2BDs%2FYQGKj5%2By6KEADJGO6OHErcckxeyNWivzii6PqhvLVPJ6dVpxWPaovBhc8xBfVg07vrihEZwg18DtGFUZ7hTlQR5Mm8kTtg70FMV5Efnq94prB8eamPYxlYN3bLtOe1W%2BuG4z70arCDPya5kUa5NQtVyoyLBXfZ1tTfp1ni4Hg58%2BquSJCI4ylm0fQxgbw0H5h%2F0Z0oo%2BOcvAYyLdg%2Bbqwn48vRIv%2B6hGJrOQFXPM7vHDUBdy0gb7q70XEn6Li60Ii45J%2BKP2RGdQ%3D%3D
D/AWSIotMqttManager(16659): Setting up Callback for MqttClient
D/AWSIotMqttManager(16659): mqtt reconnecting attempt 2
W/AWSIotMqttManager(16659): Reconnect failed

I/AWSIotMqttManager(16659): schedule Reconnect attempt 2 of 10 in 16 seconds.
xxx
xxx
xxxx
xxxx
xxxx
xxxxx

code is:

`

   LogFactory.setLevel(LogFactory.Level.ALL);
    // 替换为你的 AWS IoT 配置
    val endpoint = "wss://xxxxxx-ats.iot.ap-southeast-1.amazonaws.com/mqtt" // 替换为 AWS IoT Core 的端点
    val clientId = UUID.randomUUID().toString()
    // 配置凭证
    val sessionCredentials = BasicSessionCredentials(
        accessKey,
        secretKey,
        sessionToken
    )

    // 初始化 MQTT Manager
    mqttManager = AWSIotMqttManager(clientId, endpoint)
    mqttManager?.keepAlive = 10
    mqttManager?.resetReconnect();
    mqttManager?.isAutoReconnect=true
    mqttManager?.isOfflinePublishQueueEnabled = false   
    mqttManager?.connect(StaticCredentialsProvider(sessionCredentials)) { status, throwable ->
        when (status) {
            AWSIotMqttClientStatus.Connecting -> {
                println("mqtt Connecting to AWS IoT")
            }

            AWSIotMqttClientStatus.Connected -> {
                println("mqtt Connected to AWS IoT")
            }

            AWSIotMqttClientStatus.ConnectionLost -> {
                println("mqtt Connection lost: ${throwable?.message}")
            }

            AWSIotMqttClientStatus.Reconnecting -> {
                println("mqtt Reconnecting to AWS IoT")                 
            }

            else -> {
                println("mqtt Connection status: $status")
            }
        }
    }

`

build.gradle is
`

    implementation 'com.amazonaws:aws-android-sdk-core:2.77.1' // 确保与其他模块版本一致
    implementation 'com.amazonaws:aws-android-sdk-apigateway-core:2.77.1'
    implementation 'com.amazonaws:aws-android-sdk-mobile-client:2.77.1'
    implementation 'com.amazonaws:aws-android-sdk-iot:2.77.1'

`

No response

SDK version used

targetsdk android 34,minsdk 26

Environment details (OS name and version, etc.)

android studio

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Jan 15, 2025
@thisisabhash
Copy link
Member

Thank you for posting this - our team will take a look and post updates here.

@thisisabhash thisisabhash added the bug Something isn't working label Jan 15, 2025
@github-actions github-actions bot removed pending-maintainer-response Issue is pending response from an Amplify team member pending-triage Issue is pending triage labels Jan 15, 2025
@Wlazly
Copy link
Author

Wlazly commented Jan 17, 2025

does has any resolution @thisisabhash

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Jan 17, 2025
@tylerjroach
Copy link
Member

Please remove the wss:// in front of your endpoint. You can see from your logs that it is getting added twice wss://wss://xxxxxx-ats.iot.ap-southeast-1.amazonaws.com

@tylerjroach tylerjroach added question General question and removed bug Something isn't working labels Jan 21, 2025
@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Jan 21, 2025
@Wlazly
Copy link
Author

Wlazly commented Jan 22, 2025

@tylerjroach thanks,fix it

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Jan 22, 2025
@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Jan 22, 2025
Copy link
Contributor

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question General question
Projects
None yet
Development

No branches or pull requests

3 participants