Mqtt connection stuck on Reconnecting - android

I am trying to connect to the Amazon IoT service using an android app following the guide on https://github.com/awslabs/aws-sdk-android-samples/tree/master/AndroidPubSubWebSocket.
I have change the CUSTOMER_SPECIFIC_ENDPOINT to the ENDPOINT value found in SETTINGS section of AWS IoT Console. Additionally I have changed the COGNITO_POOL_ID value to POOL_ID found under the Getting Started with Amazon Cognito.
Unfortunately now everytime I try to connect to the connect, even using the sample code form the above repo, the Connection Status is status keep on trying to Reconnect without providing any throwable object.

In the IoT thing policy did you give appropriate permissions to connect, subscribe and publish. The option can be found in AWS IoT->Security->Policy->Create Policy.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iot:*",
"Resource": "arn:aws:iot:us-east-2:293751794947:topic/replaceWithATopic"
}
]
}
The above policy gives all access to the user. Also, make sure your pool which you created is for unauthenticated users.
UPDATE
In the IAM policies.Do check if you have given appropriate permissions to the cognito pool. If not attach the IoTFullAccess policy to the pool. It will solve the problem.

Related

Google Cloud socket.io server, client not keeping persistent connection

I have a Node.js server using socket.io to connect Android apps and I've been hosting it locally by just running it in my IDE and connecting to my local IPv4 address but I want it to work without me having to keep my PC running constantly so I've tried using Google Cloud and managed to get it mostly working but the client doesn't keep the connection and disconnects consistently.
I followed this tutorial up to step 4 after that I ran gcloud app deploy.
My Node.js server is in one file, it has these declarations at the top.
const express = require("express");
const app = express();
const http = require("http");
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server);
I then have this for the initial client connection.
io.on("connection", (socket) => {
console.log("User connected.");
Everything inside of this is just listeners for what gets emitted by the client so I don't think they're the problem.
And then outside of that I have
server.listen(8080, () => {
console.log("Server is listening");
});
I don't know if anything from the package.json file is relevant but I can provide it if need be.
After deploying to Google Cloud using the tutorial there are a few things in the logs that may be the reason behind the problem.
Waiting for network connection open. Subject:"app/invalid" Address:127.0.0.1:8080
Waiting for network connection open. Subject:"app/invalid" Address:127.0.0.1:8081
Wait successful. Subject:"app/invalid" Address:127.0.0.1:8080 Attempts:97 Elapsed:485.916418ms
App is listening on port 8080. We recommend your app listen on the port defined by the PORT environment variable to take advantage of an NGINX layer on port 8080.
These might have simple solutions but I have very little experience with server hosting.
Once my Android client connects to the server, the log outputs "User connected." as it should, then around 10 seconds later it does it again and this repeats. There's no error I can see between the connections just a few socket.io POST/GET requests.
I tried adding session affinity to the app.yaml but hasn't solved it either.
This is my app.yaml if any changes need to be made here
runtime: nodejs16
env: standard
instance_class: F1
automatic_scaling:
min_idle_instances: automatic
max_idle_instances: automatic
min_pending_latency: automatic
max_pending_latency: automatic
network:
session_affinity: true
Thanks for any help, if I need to provide any other files I can do so.
Socket communication requires persistent network connections. So, App Engine Flexible provides an option to keep the network connection alive.
I think you are deploying your app in App Engine Standard , which does not support this option.
So, you can deploy your app in App Engine Flexible and you need to include the following configuration in your app.yaml
network:
session_affinity: true
For refence on session affinity, please refer to this page https://cloud.google.com/appengine/docs/flexible/nodejs/using-websockets-and-session-affinity#session_affinity
So, your updated app.yaml can look like this
runtime: nodejs
env: flex
network:
session_affinity: true
Please refer to this page for supported yaml configuration for flexible environment - https://cloud.google.com/appengine/docs/flexible/nodejs/reference/app-yaml
Messages you have pasted are most likely not indicating a problem. Your application is running in a sandbox environment for which a container instance and a web server must be initialized the first time that your app engine service receives a request. This is also called Loading request and the messages you see indicate the startup of your container instance and your webserver.
You can take a look at Google's own documentation regarding handling requests in node.js or follow a quickstart guide.
If there are no other logs during the disconnection, I would suggest checking the quotas to see if you're not exceeding any.

Access Not Configured. YouTube Data API has not been used in project 608941808256

I have enabled YouTube data API and Google+ API for my project and change the Android API Key in Auth.java I also entered my playlist info into Constants.java. However I still get this unhelpful error:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code": 403,
"errors": [
{
"domain": "usageLimits",
"message": "Access Not Configured. YouTube Data API has not been used in project 608941808256 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube/overview?project=608941808256 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"reason": "accessNotConfigured",
"extendedHelp": "https://console.developers.google.com/apis/api/youtube/overview?project=608941808256"
}
],
"message": "Access Not Configured. YouTube Data API has not been used in project 608941808256 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube/overview?project=608941808256 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry."
}
can some one help me please
We had the same issue. We resolved it by starting from scratch and creating a brand new API project. For some reason the existing API project didn't work. Steps to check if you have this issue:
Create a new project in the API console (click the project dropdown at the top of the window, and choose "New project").
Enable the APIs required (e.g. YouTube Data).
Go to credentials->Domain verification and enter your domain.
Fill in the OAuth consent screen, and make the "application name" the same as your project name. Also choose the scopes you will be using, add your domain, save it, and submit for verification.
Create credentials of type "OAuth2 client key->Web application" and enter the correct callback uri.
Wait a few hours.
You should now be able to test in the APIs explorer (enter your own client key).
I had the same problem here.
Besides enabling the Google+ API and the Contacts API I have also to create a new OAuth Client Key for Web applications.
When you create it you'll see that the client id will start with the Project Id that you have on the error message.
In summary you'll have to do as follow:
Create an OAuth Client Key with type web application
And the Client Id to you API
Then you should be able to authenticate.
Hope I could help.
I Solved this problem by creating a new project and then creating new credentials

CognitoSyncDemo: Failed to list records in dataset

I downloaded Amazon's samples: CognitoSyncDemo https://github.com/awslabs/aws-sdk-android-samples/tree/master/CognitoSyncDemo and tried to run it in unauthenticated mode. I followed Amazon's guide:
created AWS account;
created Identities Pool in Cognito;
added roles in IAM.
But when I ran the sample app, populate some data into dataset and tried to sync them, it popup that : Failed due to Failed to list records in dataset: XXX(XXX is my dataset name).
The role policy I created for unauthenticate is as follows:
{
"Version": "2012-10-17",
"Statement": [{
"Action": [
"mobileanalytics:PutEvents",
"cognito-sync:*",
"sns:*"
],
"Effect": "Allow",
"Resource": [
"*"
]
}]
}
I am not sure if it was the role's problem.
Does anyone had such problem as well when you ran the CognitoSyncDemo provided by Amazon?
The role policy looks sane. The details you provided are not enough to see what else is causing the problem, so this is a list of things you should verify:
From your Identity Pool in the Cognito Console, go to "Edit Identity Pool" and make sure that "Enable Access to unauthenticated Identities" is checked.
Make sure that the region (US-East or EU-West) in your AWS Console matches the region set in your app's code.
Make sure you have entered the correct roles ARN's in the app's source, together with the identity pool id and your AWS account.

Error 500 from Google Play Android Developer REST API when getting subscription information

I've followed the complete steps to access the API as described by Google here:
https://developers.google.com/android-publisher/authorization.
I have managed to get a refresh token, and am fetching a new access token when my existing one expires. So now I am trying to get information about a valid subscription using:
GET https://www.googleapis.com/androidpublisher/v1/applications/<packageName>/subscriptions/<subscriptionId>/purchases/<token>?access_token=<myAccessToken>
but the only response I get back is:
{
"error": {
"code": 500,
"message": null
}
}
Has anyone come across this problem before? I am currently testing with an unpublished application, although the subscription is published so the packageName, subscriptionId and token should be valid.
change or add again new internet settings ..500 error is due to early timeout of connections by your wrong or mislead network settings
it cannot be solved by clearing data cache ....

How to authenticate user, using the Google account user_id to third party socket server

This tutorial was a grate help in understanding the AccountManager and authToken:
Nick's Blog Authenticating against App Engine from an Android app
I still need to get that to work with a basic Java SSL/TSL socket server where for now
my Android users authenticates themselves with passwords.
UPDATE:
The Server works as relay station for the SPRIID app users.
With the SPRIID app you send files to other devices trough this dedicated java Server.
- Everything work trough C2DM(GCM)
- Backend MongoDb databas register users and frindlist's and handle transfer details
For test trying the app, install it, add yourself as friend, send something..
How can the server pars the authToken return with getAuthToken()?
Must my server run some GAE api?
Is the "Federated Login" the way to go and how?
Not too clear what exactly you are doing, maybe give more details about your server.
Generally, you simply pass the token using your own custom protocol. If you are using ClientLogin tokens, the only way to check if they are valid is to try calling the corresponding Google service (e.g., Calendar) and check if you get a 200 (401 for unauthroized) response. For OAuth tokens, there is an API to validate them.
Also consider using HTTP and use standard authentication protocols.
Think i got it working now warning do Im still learning this
In the Nick's sample code above im replacing the
accountManager.getAuthToken(account, "ah", false, new GetAuthTokenCallback(), null);
with
accountManager.getAuthToken(account,"oauth2:https://www.googleapis.com/auth/userinfo.profile", false, new GetAuthTokenCallback(), null);
Now i get a Token and can in my chrome browser do:
https://www.googleapis.com/oauth2/v1/userinfo?access_token=ya29.AHeS6ZQpS0T0jipB0grWzuqINDdP98zjj-uljvw1GTR1_2s
That will return this json
{
"id": "100864638927226952543326",
"name": "Billy Bob",
"given_name": "Billy",
"family_name": "Bob",
"link": "https://plus.google.com/13444649626952543326",
"picture": "https://lh5.googleusercontent.com/--QPesNgxryI/AAAAAeewAAAI/AAAAAAAAAFo/J-LSwl0bcVU/photo.jpg",
"gender": "male",
"locale": "us"
}
What i wanted was the "id", that is suppose to be unique

Categories

Resources