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

IoT sample for Android? (for IoT Android SDK) #3633

Closed
tonytonchev opened this issue Aug 30, 2024 · 6 comments
Closed

IoT sample for Android? (for IoT Android SDK) #3633

tonytonchev opened this issue Aug 30, 2024 · 6 comments
Labels
pending-maintainer-response Issue is pending response from an Amplify team member question General question

Comments

@tonytonchev
Copy link

State your question

In your mobile SDK samples, you provide an "IoT-Sample" for iOS:
https://github.com/awslabs/aws-sdk-ios-samples/tree/main/IoT-Sample/Swift/

This sample demonstrates use of the AWS IoT APIs to securely publish to and subscribe from an MQTT topic. It uses Cognito authentication with identity pool id, without requiring a user login. It works.

You used to have a similar sample for Android (AndroidPubSubWebSocket) which used to be located here:
https://github.com/awslabs/aws-sdk-android-samples/tree/main/AndroidPubSubWebSocket
but it's not available anymore on the official sdk site for some reason.

The same sample is available over Internet from some previous AWS SDK demo backups, but it seems like that code doesn't work anymore.
The problem with that old sample is reported on a few places, and you have a (closed) ticket without resolution for the same problem:
#750
(the aWSIotMqttManager consistently reconnects and doesn't make a connection).
The same approach, with same values, pool id and policies works with the iOS sample.

Here is my question:

Can we currently use the same approach for Android (to use the moblie IoT SDK, and cognito without user login for the connection, subscription and publishing of messages?), or it's not possible?

If we can, is there a guide, tutorial or simple app who does that and it works?

Thanks,
Tony

Which AWS Services are you utilizing?
AWS IOT / Android

Provide code snippets (if applicable)
Your previous sample : https://github.com/felipemeriga/aws-sdk-android-samples/tree/master/AndroidPubSubWebSocket

Environment(please complete the following information):

  • SDK Version: 2.77.0

Device Information (please complete the following information):
Multiple Pixel devices and simulators (Pixel 7 / API 34, Pixel 6. API 33, etc)

If you need help with understanding how to implement something in particular then we suggest that you first look into our developer guide. You can also simplify your process of creating an application, as well as the associated backend setup by using the Amplify CLI.

The link above is not valid.
We went over https://docs.aws.amazon.com/iot/latest/developerguide/what-is-aws-iot.html

Thanks,
Tony

@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 Aug 30, 2024
@tylerjroach
Copy link
Member

While the AWS Android SDK library is still supported, it is being replaced by https://github.com/aws/aws-iot-device-sdk-java-v2?tab=readme-ov-file. Here, you will find a few samples: https://github.com/aws/aws-iot-device-sdk-java-v2/blob/main/documents/ANDROID.md. You may want to go ahead and look at that library instead.

If you want to continue using aws-android-sdk, please provide logs specific to your connection attempts and we can take a look to see what may be the issue.

Our documentation for the IoT library can be found here: https://docs.amplify.aws/gen1/android/sdk/pubsub/

@tylerjroach tylerjroach added the question General question label Aug 30, 2024
@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Aug 30, 2024
@tylerjroach tylerjroach removed the pending-triage Issue is pending triage label Aug 30, 2024
@tonytonchev
Copy link
Author

Thank you very much for the prompt response. We will investigate the java sdk per your note.

Regarding the androd aws sdk,I'm attaching the console log (without the actual end point, let me know if you need it).
the AWSIoTFullAccess policy is attached to the role (screen shot attached)

As I mentioned, with the same AWS settings, the iOS sample works just fine (using the IoTWebSocket flow)
Screenshot 2024-08-30 at 9 11 36 AM
android_amazon_error_log.txt

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Aug 30, 2024
@tylerjroach
Copy link
Member

Please double check the url/port you are using. You are getting java.net.UnknownHostException which would indicate the url is not valid.

@github-actions github-actions bot added pending-maintainer-response Issue is pending response from an Amplify team member and removed pending-maintainer-response Issue is pending response from an Amplify team member labels Aug 30, 2024
@tylerjroach
Copy link
Member

tylerjroach commented Aug 30, 2024

remove the https. You are communicating over mqtt not https

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Aug 30, 2024
@tonytonchev
Copy link
Author

@tylerjroach , thank you so very much! I added https just because it says so in the comments in the example:
//For both connecting over websockets and cert, IOT_ENDPOINT should look like
//https://xxxxxxx-ats.iot.REGION.amazonaws.com

Removing the https resolved the problem. Thank you again!

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Aug 30, 2024
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
pending-maintainer-response Issue is pending response from an Amplify team member question General question
Projects
None yet
Development

No branches or pull requests

2 participants