aws / aws-iot-device-sdk-java Goto Github PK
View Code? Open in Web Editor NEWJava SDK for connecting to AWS IoT from a device.
Home Page: https://aws.amazon.com/iot/sdk/
License: Apache License 2.0
Java SDK for connecting to AWS IoT from a device.
Home Page: https://aws.amazon.com/iot/sdk/
License: Apache License 2.0
I am using aws iot sdk on a device which needs to send out messages at a very high rate, say 100 messages per second.
Initially I used the blocking publish(QOS 1), but I observed that it takes around 200ms for one publish which was not acceptable for my use case. Next I used the non blocking publish which gave me a performance of around 50 messages per sec, but the rest of the messages started throwing exceptions saying too many publishes.
I understand that this is a limitation caused by the default 10 maxInflight of underlying Mqtt paho client but they have provided an option to change this max inflight, wheras aws iot sdk has just absctracted it.
I would hence like to raise an issue to be provided with such an option to set the max inflight queue size as I feel it would help achieve a way higher rate of sending messages.
Hi,
I have two questions for the AWS MQTT Java client. Since I read from the AWS guide https://docs.aws.amazon.com/iot/latest/developerguide/protocols.html that AWS MQTT broker does not support clean session = false, does it mean that once connection lost I have to re-subscribe to all the topics again?
Besides, is there any callback method we can invoke on connection lost? So that I will have the event triggered by the client instance.
Thanks
Jason
Hi,
I have below usecase 👍
Connecting to AWS iot client
Publishing to a topic
the message being published to topic has been subscribed by another client and do the processing and publishes the response on to another topic .I will have to subscribe to that topic to get response and send the response to front end .All this flow should be synchronous as I have to wait for certain time interval until I recieve response after I publish the request on to initial topic .Could you help with some sample example how to solve this issue ?
Regards,
Brahmaiah
The IOT Hub with all the things was created on us-west-2 region and the code to create the iot client used us-east-1 by mistake.
The update shadow simply returned ok-200 and obviously nothing changed on the shadow but finding why it didn't work was very painful.
I would expect to get an exception if an update to a shadow with a thingName does not exist in a specific region that the client was created.
iotClient = AWSIotClientBuilder.standard().
withRegion(Regions.US_EAST_1).
withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(awsAccessKeyId, awsSecretAccessKey))).build();
iotDataClient = AWSIotDataClientBuilder.standard().
withRegion(Regions.US_EAST_1).
withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(awsAccessKeyId, awsSecretAccessKey))).build();
mqttClient = new AWSIotMqttClient(awsClientEndpoint, awsClientId, awsAccessKeyId, awsSecretAccessKey);
private void updateShadow(String thingName, Map<String, ?> attributes) {
try {
UpdateThingShadowResult result = iotDataClient.updateThingShadow(new UpdateThingShadowRequest().withThingName(thingName.trim()).withPayload(ByteBuffer.wrap(
new JSONObject().put("state", new JSONObject().put("desired", new JSONObject(attributes))).toString().getBytes())));
System.out.println(result.toString());
} catch (ConflictException ex) {
ex.printStackTrace();
}
}
Are there any jobs examples available for java sdk which are similar to js sdk found here?
https://github.com/aws/aws-iot-device-sdk-js/blob/master/examples/jobs-agent.js
https://github.com/aws/aws-iot-device-sdk-js/blob/master/examples/jobs-example.js
Hi! I'm working a project that connect to aws iot over Embedded Java J2ME. Did you a plan for release SDK for Java Me?
When I partly change a nested JSON object in the desired state, the simplified shadow access model cannot correctly deserialize the corresponding delta.
{
"desired": {
"foobar": {
"foo": true,
"bar": true
}
},
"reported": {
"foobar": {
"foo": false,
"bar": true
}
},
"delta": {
"foobar": {
"foo": true
}
}
}
For the first level the SDK will use "AwsIotJsonDeserializer" to map individual fields to setters of annotated properties (@AWSIotDeviceProperty), but anything deeper will be deserialized as a whole.
Object value = jsonObjectMapper.treeToValue(node, field.getType());
When a partial delta is deserialized all the fields that are not represented in the delta will contain the default values as specified in the class. This causes all kinds of problems like an endless loop where the reported state can never match the desired state.
The problem we are experiencing is that the MQTT connection is permanently lost after a successful reconnect. This only happens if we filled the offline message queue while disconnected.
After deep diving into the software stack I noticed the following. After the internet connection is back the IoT client will correctly try to reconnect and onConnectionSuccess() is called in com.amazonaws.services.iot.client.core.AwsIotConnection.java.
@Override
public void onConnectionSuccess() {
LOGGER.info("Connection successfully established");
connectionStatus = AWSIotConnectionStatus.CONNECTED;
retryTimes = 0;
cancelRetry();
// process offline messages
try {
while (subscribeQueue.size() > 0) {
AWSIotMessage message = subscribeQueue.poll();
subscribeTopic(message);
}
while (unsubscribeQueue.size() > 0) {
AWSIotMessage message = unsubscribeQueue.poll();
unsubscribeTopic(message);
}
while (publishQueue.size() > 0) {
AWSIotMessage message = publishQueue.poll();
publishMessage(message);
}
} catch (AWSIotException | AwsIotRetryableException e) {
// should close the connection if we can't send message when
// connection is good
LOGGER.log(Level.WARNING, "Failed to send queued messages, will disconnect", e);
try {
closeConnection(null);
} catch (AWSIotException ie) {
LOGGER.log(Level.WARNING, "Failed to disconnect", ie);
}
}
client.onConnectionSuccess();
if (connectCallback != null) {
connectCallback.onSuccess();
connectCallback = null;
}
}
In that callback it will try to loop on the messages stored in the publishQueue and send them. These are the messages that were tried to be send during the no internet connection period. If we get an exception during that phase, the catch section will be executed and closeConnection(null) will be called. That will consequently close the MQTT connection. The exception that causes the catch section to execute is: "too many publishes in progress (32202)"
At some point the callback onSucess() from AwsIotMqttConnectionListener.java will be called and since the MQTT connection is closed it will call client.getConnection().onConnectionClosed() which is implemented in com.amazonaws.services.iot.client.core. onConnectionClosed.
onConnectionClosed will permanently close the aws iot connection.
If I understand correctly what is happening is that the actual in flight messages in Paho are more than the maxInFlight messages. That is caused when AWS tries to send all the messages stored in the offline queue (publishQueue) asynchronously, without any delay. Since we cannot change the MqttOptions from AWS I have no control over the maxInFlight variable.
Do you have any solution for this problem?
maxOfflineMqttQueueSize: 64 (default value)
maxInflight: 10 (default value)
Hi! Our AWS support team has changed its policy, so our teams are no longer able to create users in the AWS console. All access should be handled by roles, which generally seems like a good idea.
But our backend system (hosted in AWS ECS) needs to subscribe to a MQTT topic that is used as a command channel. To establish this subscription, I'm using AWSIotMqttClient, which is my only choice for MQTT subscriptions, as far as I understand. But to establish this connection I either need AWS credentials or certificates, and to use certificates for internal communication seems like a hassle.
Do I need to try to get an exception from their new policy, so I can create users, or is there something in my reasoning that is wrong? Or is there some updates in the near future that should resolve this, e.g. AWS SDK's getting support for MQTT over roles etc.?
https://us-west-2.console.aws.amazon.com/iotv2/home?region=us-west-2#/connectdevice/
To configure and test the device, perform the following steps.
Step 1: Unzip the connection kit on the device
unzip connect_device_package.zip
Step 2: Add execution permissions
chmod +x start.sh
Step 3: Run the start script. Messages from your thing will appear below
./start.sh
when run the ./start.sh
....
Downloaded: http://repo2.maven.org/maven2/org/codehaus/plexus/plexus-utils/3.0.20/plexus-utils-3.0.20.jar (0 B at 0.0 KB/sec)
Downloaded: http://repo2.maven.org/maven2/org/apache/commons/commons-exec/1.3/commons-exec-1.3.jar (0 B at 0.0 KB/sec)
[WARNING]
java.lang.ClassNotFoundException: com.amazonaws.services.iot.client.sample.pubSub.PublishSubscribeSample
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:281)
at java.lang.Thread.run(Thread.java:745)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 56.256 s
[INFO] Finished at: 2016-12-19T15:56:43+08:00
[INFO] Final Memory: 16M/130M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:java (default-cli) on project aws-iot-device-sdk-java-samples: An exception occured while executing the Java class. com.amazonaws.services.iot.client.sample.pubSub.PublishSubscribeSample -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Hi, I'm using the SDK on a Raspberry PI 3, Java 8 and having issues with listening on a Topic.
Basically, my code is:
public class TestTopicListener extends AWSIotTopic {
public TestTopicListener(String topic, AWSIotQos qos) {
super(topic, qos);
System.out.println("Listener: Connecting to " + topic);
}
@Override
public void onMessage(AWSIotMessage message) {
System.out.println(System.currentTimeMillis() + ": <<< " + message.getStringPayload());
if ( message.getStringPayload().equalsIgnoreCase("restart"))
System.exit(0);
}
}
And I'm just getting the following messages on the console:
Jul 19, 2016 11:07:07 AM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure INFO: Connection temporarily lost Jul 19, 2016 11:07:07 AM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure INFO: Client connection lost: rpi001 Jul 19, 2016 11:07:10 AM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run INFO: Connection is being retried Jul 19, 2016 11:07:11 AM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionSuccess INFO: Connection successfully established Jul 19, 2016 11:07:11 AM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionSuccess INFO: Client connection active: rpi001 Jul 19, 2016 11:07:12 AM com.amazonaws.services.iot.client.mqtt.AwsIotMqttMessageListener onFailure WARNING: Request failed for topic $aws/things/rpi001/shadow/update: Connection lost (32109) - java.io.EOFException Jul 19, 2016 11:07:12 AM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure INFO: Connection temporarily lost Jul 19, 2016 11:07:12 AM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure INFO: Client connection lost: rpi001 Jul 19, 2016 11:07:15 AM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run INFO: Connection is being retried Jul 19, 2016 11:07:15 AM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionSuccess INFO: Connection successfully established
I'm subscribing to $aws/things/rpi001/shadow/update. It does seem like the very first message I publish on that topic from the client, the client also receives. But after that one, nothing...
The strange thing is that my publications to another topic seem to be working fine along with publishing to $aws/things/rpi001/shadow/update from the client. I'm seeing the updates in the IoT console.
Any help would be appreciated!
Thanks,
Mac
I'm using this library for android. I have an all certificates but I can't implement. I need your help.
String certificateFile = "/Users/Yusuf/AwsCert/xxxxxxxx-certificate.pem.crt"
String privateKeyFile = "/Users/Yusuf/AwsCert/xxxxxxxx-private.pem.key"
val pair = SampleUtil.getKeyStorePasswordPair(certificateFile,privateKeyFile)
//pair object getting is null
val client = AWSIotMqttClient(clientEndpoint, clientId, pair.keyStore, pair.keyPassword)
client.connect()
I'm getting this error:
Private key file not found: /Users/Yusuf/AwsCert/xxxxxxxx-private.pem.key
Certificate file: /Users/Yusuf/AwsCert/xxxxxxxx-certificate.pem.crt is not found.
Where is my mistake ?
Hi All,
I am using aws-iot-device-sdk-java-1.1.1 and org.eclipse.paho.client.mqttv3-1.1.0.jar. I am able to connect to AWS MQTT broker using awsAccessKeyId and awsSecretAccessKey.
But when i try to use certificateFile and privateKeyFile, i am getting below errors consistently:
Cert file:696f7b626b-certificate.pem.crt Private key: 696f7b626b-private.pem.key
Oct 11, 2017 10:44:45 AM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
Connection lost (32109) - java.io.EOFException
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:267)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107)
... 1 more
Oct 11, 2017 10:44:45 AM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Oct 11, 2017 10:44:45 AM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: sampleopc2
Oct 11, 2017 10:44:48 AM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
After following few threads i decided to upgrade paho jar to org.eclipse.paho.client.mqttv3-1.2.0.jar (Java Client), but getting same error consistently.
After eclipse paho jar upgrade even websocket connectivity stops working and getting error as below:
Oct 11, 2017 10:42:32 AM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
MqttException (0) - java.io.IOException: WebSocket Response header: Incorrect upgrade.
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:715)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: WebSocket Response header: Incorrect upgrade.
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.receiveHandshakeResponse(WebSocketHandshake.java:148)
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.execute(WebSocketHandshake.java:76)
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketSecureNetworkModule.start(WebSocketSecureNetworkModule.java:63)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:701)
... 7 more
Oct 11, 2017 10:42:32 AM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Oct 11, 2017 10:42:32 AM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: sampleopc2
Oct 11, 2017 10:42:35 AM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
For the time being i can live with org.eclipse.paho.client.mqttv3-1.1.0.jar since atleast awsAccessKeyId and awsSecretAccessKey works.
Sample Code:
String clientEndpoint = arguments.getNotNull("clientEndpoint", SampleUtil.getConfig("clientEndpoint"));
String clientId = arguments.getNotNull("clientId", SampleUtil.getConfig("clientId"));
String certificateFile = arguments.get("certificateFile", SampleUtil.getConfig("certificateFile"));
String privateKeyFile = arguments.get("privateKeyFile", SampleUtil.getConfig("privateKeyFile"));
if (awsIotClient == null && certificateFile != null && privateKeyFile != null) {
String algorithm = arguments.get("keyAlgorithm", SampleUtil.getConfig("keyAlgorithm"));
KeyStorePasswordPair pair = SampleUtil.getKeyStorePasswordPair(certificateFile, privateKeyFile, algorithm);
awsIotClient = new AWSIotMqttClient(clientEndpoint, clientId, pair.keyStore, pair.keyPassword);
awsIotClient.setKeepAliveInterval(30000);
}
if (awsIotClient == null) {
String awsAccessKeyId = arguments.get("awsAccessKeyId", SampleUtil.getConfig("awsAccessKeyId"));
String awsSecretAccessKey = arguments.get("awsSecretAccessKey", SampleUtil.getConfig("awsSecretAccessKey"));
String sessionToken = arguments.get("sessionToken", SampleUtil.getConfig("sessionToken"));
if (awsAccessKeyId != null && awsSecretAccessKey != null) {
awsIotClient = new AWSIotMqttClient(clientEndpoint, clientId, awsAccessKeyId, awsSecretAccessKey,
sessionToken);
}
}
if (awsIotClient == null) {
throw new IllegalArgumentException("Failed to construct client due to missing certificate or credentials.");
}
awsIotClient.connect();
AWSIotTopic topic = new TestTopicListener(TestTopic, TestTopicQos);
awsIotClient.subscribe(topic, true);
Certificate as :
Hi
I am trying to run the PublishSubscribeSample. I set up everything in the aws-iot-sdk-samples.properties.
It failed on line 137 awsIotClient.connect();
The configuration is pretty straight forward. Could you help me check if I missed anything, please?
Sep 08, 2016 3:37:06 AM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
Connection lost (32109) - java.io.EOFException
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:267)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107)
... 1 more
I am trying to establish the connection with AWSIotMqttClient, the connection is established successfully. But I am constantly seeing the log's of connection lost, established, retired in console as mentioned below. I am currently in Texas regions.
I tried establishing the connection using both ways certificates as well as using access Key ID and secret access key. In both cases I am seeing the same problem.
Security Policy which is attached my Device certification ->
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "iot:*", "Resource": "*" } ] }
AWSIotMqttClient connection Java Code ->
`public AWSIotMqttClient getAWSIoTClient() {
String clientEndpoint = getClientEndpoint();
String clientId = getClientId();
String certificateFile = getCertificateFile();
String privateKeyFile = getPrivateKeyFile();
if (certificateFile != null && privateKeyFile != null) {
AWSUtil.KeyStorePasswordPair pair = AWSUtil.getKeyStorePasswordPair(certificateFile, privateKeyFile);
awsIotClient = new AWSIotMqttClient(clientEndpoint, clientId, pair.keyStore, pair.keyPassword);
if(awsIotClient.getConnectionStatus().equals(AWSIotConnectionStatus.DISCONNECTED))
try {
awsIotClient.connect();
} catch (AWSIotException e) {
throw new IllegalArgumentException("Failed to connect to AWS IoT Client.");
}
}
if (awsIotClient == null) {
throw new IllegalArgumentException("Failed to construct client due to missing certificate or credentials.");
}
return awsIotClient;
}`
Console Logs ->
`2017-08-09 18:42:15.896 INFO [-,,,] 85753 --- [pool-3-thread-1] c.a.s.iot.client.core.AwsIotConnection : Connection successfully established
2017-08-09 18:42:15.896 INFO [-,,,] 85753 --- [pool-3-thread-1] c.a.s.i.c.core.AbstractAwsIotClient : Client connection active: DEVICE_IOT_PLATFORM
2017-08-09 18:42:15.940 INFO [-,,,] 85753 --- [pool-2-thread-1] c.a.s.iot.client.core.AwsIotConnection : Connection temporarily lost
2017-08-09 18:42:15.940 INFO [-,,,] 85753 --- [pool-2-thread-1] c.a.s.i.c.core.AbstractAwsIotClient : Client connection lost: DEVICE_IOT_PLATFORM
2017-08-09 18:42:16.541 INFO [-,,,] 85753 --- [pool-1-thread-1] c.a.s.iot.client.core.AwsIotConnection : Connection is being retried
2017-08-09 18:42:16.872 INFO [-,,,] 85753 --- [pool-1-thread-1] c.a.s.iot.client.core.AwsIotConnection : Connection successfully established
2017-08-09 18:42:16.872 INFO [-,,,] 85753 --- [pool-1-thread-1] c.a.s.i.c.core.AbstractAwsIotClient : Client connection active: DEVICE_IOT_PLATFORM
2017-08-09 18:42:16.898 INFO [-,,,] 85753 --- [pool-3-thread-1] c.a.s.iot.client.core.AwsIotConnection : Connection temporarily lost
2017-08-09 18:42:16.898 INFO [-,,,] 85753 --- [pool-3-thread-1] c.a.s.i.c.core.AbstractAwsIotClient : Client connection lost: DEVICE_IOT_PLATFORM
2017-08-09 18:42:18.945 INFO [-,,,] 85753 --- [pool-2-thread-1] c.a.s.iot.client.core.AwsIotConnection : Connection is being retried
2017-08-09 18:42:19.415 INFO [-,,,] 85753 --- [pool-2-thread-1] c.a.s.iot.client.core.AwsIotConnection : Connection successfully established
2017-08-09 18:42:19.415 INFO [-,,,] 85753 --- [pool-2-thread-1] c.a.s.i.c.core.AbstractAwsIotClient : Client connection active: DEVICE_IOT_PLATFORM
2017-08-09 18:42:19.504 INFO [-,,,] 85753 --- [pool-1-thread-1] c.a.s.iot.client.core.AwsIotConnection : Connection temporarily lost
2017-08-09 18:42:19.504 INFO [-,,,] 85753 --- [pool-1-thread-1] c.a.s.i.c.core.AbstractAwsIotClient : Client connection lost: DEVICE_IOT_PLATFORM
2017-08-09 18:42:19.901 INFO [-,,,] 85753 --- [pool-3-thread-1] c.a.s.iot.client.core.AwsIotConnection : Connection is being retried
2017-08-09 18:42:20.245 INFO [-,,,] 85753 --- [pool-3-thread-1] c.a.s.iot.client.core.AwsIotConnection : Connection successfully established
2017-08-09 18:42:20.245 INFO [-,,,] 85753 --- [pool-3-thread-1] c.a.s.i.c.core.AbstractAwsIotClient : Client connection active: DEVICE_IOT_PLATFORM
2017-08-09 18:42:20.291 INFO [-,,,] 85753 --- [pool-2-thread-1] c.a.s.iot.client.core.AwsIotConnection : Connection temporarily lost
2017-08-09 18:42:20.291 INFO [-,,,] 85753 --- [pool-2-thread-1] c.a.s.i.c.core.AbstractAwsIotClient : Client connection lost: DEVICE_IOT_PLATFORM`
Hello guys. I found one problem.
Lib crashed if it used on Android API less than 24.
Calling this constructor:
public AWSIotMqttClient(String clientEndpoint, String clientId, KeyStore keyStore, String keyPassword) {
super(clientEndpoint, clientId, keyStore, keyPassword);
}
Will cause following exception:
java.lang.NoSuchMethodError: No virtual method setEndpointIdentificationAlgorithm(Ljava/lang/String;)V in class Ljavax/net/ssl/SSLParameters; or its super classes (declaration of 'javax.net.ssl.SSLParameters' appears in /system/framework/core-libart.jar)
at com.amazonaws.services.iot.client.util.AwsIotTlsSocketFactory.ensureTls(AwsIotTlsSocketFactory.java:124)
at com.amazonaws.services.iot.client.util.AwsIotTlsSocketFactory.createSocket(AwsIotTlsSocketFactory.java:80)
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:69)
at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:86)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650)
at java.lang.Thread.run(Thread.java:818)
if you will look into the AwsIotTlsSocketFactory#ensureTls
method, you'll see next code:
private Socket ensureTls(Socket socket) {
if (socket != null && (socket instanceof SSLSocket)) {
((SSLSocket) socket).setEnabledProtocols(new String[] { TLS_V_1_2 });
// Ensure hostname is validated againt the CN in the certificate
SSLParameters sslParams = new SSLParameters();
sslParams.setEndpointIdentificationAlgorithm("HTTPS");
((SSLSocket) socket).setSSLParameters(sslParams);
}
return socket;
}
So lib crashed in line: sslParams.setEndpointIdentificationAlgorithm("HTTPS");
if app was launched on android api less than 24.
Here is official docs: SSLParameters#setEndpointIdentificationAlgorithm(java.lang.String)
Direct link to file in repo
mvn exec:java -pl aws-iot-device-sdk-java-samples -Dexec.mainClass="com.amazonaws.services.iot.client.sample.pubSub.PublishSubscribeSample" -Dexec.args="-clientEndpoint a3b3bee1v25lqs.iot.us-west-2.amazonaws.com -clientId sdk-java -certificateFile ../caokun.cert.pem -privateKeyFile ../caokun.private.key"
[INFO] Scanning for projects...
[INFO] Inspecting build with total of 1 modules...
[INFO] Installing Nexus Staging features:
[INFO] ... total of 1 executions of maven-deploy-plugin replaced with nexus-staging-maven-plugin
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building aws-iot-device-sdk-java-samples 1.1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.5.0:java (default-cli) @ aws-iot-device-sdk-java-samples ---
Dec 19, 2016 8:07:25 PM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
MqttException (0) - java.net.SocketTimeoutException: connect timed out
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:664)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:70)
at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:86)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650)
... 1 more
Dec 19, 2016 8:07:25 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Dec 19, 2016 8:07:25 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: sdk-java
Dec 19, 2016 8:07:28 PM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
Dec 19, 2016 8:08:28 PM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
MqttException (0) - java.net.SocketTimeoutException: connect timed out
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:664)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:70)
at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:86)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650)
... 1 more
Dec 19, 2016 8:08:28 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Dec 19, 2016 8:08:28 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: sdk-java
Dec 19, 2016 8:08:34 PM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
Dec 19, 2016 8:09:34 PM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
MqttException (0) - java.net.SocketTimeoutException: connect timed out
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:664)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:70)
at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:86)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650)
... 1 more
Dec 19, 2016 8:09:34 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Dec 19, 2016 8:09:34 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: sdk-java
Dec 19, 2016 8:09:46 PM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
Dec 19, 2016 8:10:48 PM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
MqttException (0) - java.net.SocketTimeoutException: connect timed out
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:664)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:70)
at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:86)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650)
... 1 more
Dec 19, 2016 8:10:48 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Dec 19, 2016 8:10:48 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: sdk-java
Dec 19, 2016 8:11:12 PM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
Dec 19, 2016 8:12:12 PM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
MqttException (0) - java.net.SocketTimeoutException: connect timed out
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:664)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:70)
at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:86)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650)
... 1 more
Dec 19, 2016 8:12:12 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Dec 19, 2016 8:12:12 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: sdk-java
Dec 19, 2016 8:12:42 PM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
Dec 19, 2016 8:13:42 PM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
MqttException (0) - java.net.SocketTimeoutException: connect timed out
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:664)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:70)
at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:86)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650)
... 1 more
Dec 19, 2016 8:13:42 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Dec 19, 2016 8:13:42 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection retry cancelled or exceeded maximum retries
[WARNING]
Dec 19, 2016 8:13:42 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionClosed
INFO: Client connection closed: sdk-java
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.amazonaws.services.iot.client.AWSIotException
at com.amazonaws.services.iot.client.core.AwsIotCompletion.get(AwsIotCompletion.java:213)
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.connect(AbstractAwsIotClient.java:112)
at com.amazonaws.services.iot.client.AWSIotMqttClient.connect(AWSIotMqttClient.java:501)
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.connect(AbstractAwsIotClient.java:93)
at com.amazonaws.services.iot.client.AWSIotMqttClient.connect(AWSIotMqttClient.java:463)
at com.amazonaws.services.iot.client.sample.pubSub.PublishSubscribeSample.main(PublishSubscribeSample.java:137)
... 6 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 07:21 min
[INFO] Finished at: 2016-12-19T20:13:42+08:00
[INFO] Final Memory: 17M/193M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:java (default-cli) on project aws-iot-device-sdk-java-samples: An exception occured while executing the Java class. null: InvocationTargetException: AWSIotException -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Currently the device reporting to the shadow is time-based. For e.g, the device SDK would 'sync' with the shadow based on a time-interval set using setReportInterval(reportInterval)
.
However, there may be cases where such time-interval based syncing is not required.
Its possible to turn periodic syncing off by setting reportInterval = 0
.
But by doing so, one has to then first manually build the JSON message (including the other headers likeversion, state, reported
... ) & later may be use --
public void update(String jsonState, long timeout)
to update the shadow.
private void sendDeviceReport(long reportVersion, String jsonState)
method already does the functionality of building the JSON message & updating the shadow.
It would be beneficial if a similar method is made (public
) & is made available to use for event-based reporting.
AWSIotTlsSocketFactory
has a constructor to use a custom SocketFactory
, but the front end class AWSIotMqttClient
has no constructors that use this functionality. Is it possible to create extra constructors to add this feature as in #52 ??
Is there a reason why device doesn't update shadow only on changes.
Seams like inefficient and implementation doesn't provide simple way to override behavior.
Hi,
I'm using the java SDK to create an Mqtt client to publish and subscribe.
While attempting to connect, I receive the following error:
FINE: sdk-java: connect failed: unexpected exception javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names matching IP address 35.162.54.21 found at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1506) at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216) at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979) at sun.security.ssl.Handshaker.process_record(Handshaker.java:914) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387) at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:93) at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) at java.lang.Thread.run(Thread.java:745) Caused by: java.security.cert.CertificateException: No subject alternative names matching IP address 35.162.54.21 found at sun.security.util.HostnameChecker.matchIP(HostnameChecker.java:167) at sun.security.util.HostnameChecker.match(HostnameChecker.java:93) at sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:455) at sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:436) at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:200) at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1488) ... 10 more
I obtained the client certificates from the AWS thing creation procedure, and I'm using them in the sample client founded on github. Like exmplained in the guide, I'm using a clientEndpoint like <prefix>.iot.<region>.amazonaws.com
. The example I'm using can be found at https://github.com/aws/aws-iot-device-sdk-java/blob/master/aws-iot-device-sdk-java-samples/src/main/java/com/amazonaws/services/iot/client/sample/pubSub/PublishSubscribeSample.java
I verified on the server certificate (via openssl) if the hostname used was supported, and i found Inc./CN=*.iot.us-west-2.amazonaws.com, that lead me to think that all is ok.
In the debugger, I followed the hostname field, and I verified that it is correctly passed to the Mqtt library.
Usually, that error is related to the use of an IP instead of an hostname, so I suppose that can be a problem to the SDK.
In paho sdk, in the below issue, user said client.reconnect() solved his problem when he got client keeps on disconnecting and reconnecting issue.
eclipse/paho.mqtt.java#258
I'm unable to find reconnect method in AWSIotMqttClient class
Can you guys look into that please?
Hi,
The first time I ran the Java subscriber it ran fine and read the data from "MyThing". I published to "MyThing" using a Python script. But after that anytime I run it it keeps losings connection and retrying to establish connection. Would anybody be able to help me?
Mar 10, 2017 9:05:20 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionSuccess
INFO: Connection successfully established
Mar 10, 2017 9:05:20 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionSuccess
INFO: Client connection active: JavaClient
Listener: Connecting to MyThing
Mar 10, 2017 9:05:21 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Mar 10, 2017 9:05:21 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: JavaClient
Mar 10, 2017 9:05:24 PM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
Mar 10, 2017 9:05:24 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionSuccess
INFO: Connection successfully established
Mar 10, 2017 9:05:24 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionSuccess
INFO: Client connection active: JavaClient
Mar 10, 2017 9:05:25 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Mar 10, 2017 9:05:25 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: JavaClient
Mar 10, 2017 9:05:28 PM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
Mar 10, 2017 9:05:28 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionSuccess
INFO: Connection successfully established
Mar 10, 2017 9:05:28 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionSuccess
INFO: Client connection active: JavaClient
Mar 10, 2017 9:05:29 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Mar 10, 2017 9:05:29 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: JavaClient
Mar 10, 2017 9:05:32 PM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
Mar 10, 2017 9:05:32 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionSuccess
INFO: Connection successfully established
Mar 10, 2017 9:05:32 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionSuccess
INFO: Client connection active: JavaClient
Mar 10, 2017 9:05:33 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Mar 10, 2017 9:05:33 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: JavaClient
Thanks,
Jack :)
I'm trying to use the java sdk to connect to the aws iot. The following code line is throwing error:
AWSIotMqttClient client = new AWSIotMqttClient(clientEndpoint, clientId, awsAccessKeyId, awsSecretAccessKey);
Error:
java.lang.IllegalArgumentException: wss://a2c6oqrhqoygg.iot.us-west-2.amazonaws.com:443
at org.eclipse.paho.client.mqttv3.MqttConnectOptions.validateURI(MqttConnectOptions.java:470)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.(MqttAsyncClient.java:273)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.(MqttAsyncClient.java:167)
at com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnection.(AwsIotMqttConnection.java:49)
at com.amazonaws.services.iot.client.core.AwsIotWebsocketConnection.(AwsIotWebsocketConnection.java:40)
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.(AbstractAwsIotClient.java:74)
at com.amazonaws.services.iot.client.AWSIotMqttClient.(AWSIotMqttClient.java:156)
at com.pramati.aws.iot.demo.testrunner.main(testrunner.java:18)
Publishing a message in a response to a message is very typical case but AWSIotMqttClient#publish
stucks in ScheduledThreadPoolExecutor
if it's run inside AWSIotMessage#onMethod
callback for AWSIotMqttClient#subscribe
:
"pool-2-thread-1@1516" prio=5 tid=0x13 nid=NA waiting
java.lang.Thread.State: WAITING
at java.lang.Object.wait(Object.java:-1)
at java.lang.Object.wait(Object.java:502)
at com.amazonaws.services.iot.client.core.AwsIotCompletion.get(AwsIotCompletion.java:203)
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.publish(AbstractAwsIotClient.java:154)
at com.amazonaws.services.iot.client.AWSIotMqttClient.publish(AWSIotMqttClient.java:651)
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.publish(AbstractAwsIotClient.java:144)
at com.amazonaws.services.iot.client.AWSIotMqttClient.publish(AWSIotMqttClient.java:627)
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.publish(AbstractAwsIotClient.java:135)
at com.amazonaws.services.iot.client.AWSIotMqttClient.publish(AWSIotMqttClient.java:580)
at com.amazon.aws.iot.SdkBugMain.sendHelloWordlSync(SdkBugMain.java:45)
at com.amazon.aws.iot.SdkBugMain.access$000(SdkBugMain.java:15)
at com.amazon.aws.iot.SdkBugMain$1.onMessage(SdkBugMain.java:37)
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient$1.run(AbstractAwsIotClient.java:293)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
public class SdkBugMain {
private static final String KEYSTORE_RESOURCE_FILE = "keystore";
private static final String KEYSTORE_PASSWORD = "password";
private static final String ENDPOINT = "idididididididid.iot.eu-central-1.amazonaws.com";
private static final AWSIotQos QOS = AWSIotQos.QOS1; // doesn't matter
private static final String INBOUND_TOPIC = "in";
private static final String OUTBOUND_TOPIC = "out";
public static void main(String[] args) throws Exception {
InputStream keystoreStream = resourceAsStream(KEYSTORE_RESOURCE_FILE);
KeyStore keyStore = readKeyStore(keystoreStream, KEYSTORE_PASSWORD);
AWSIotMqttClient mqttClient = new AWSIotMqttClient(ENDPOINT, UUID.randomUUID().toString(), keyStore, KEYSTORE_PASSWORD);
mqttClient.connect();
mqttClient.subscribe(new AWSIotTopic(INBOUND_TOPIC, QOS) {
@Override
public void onMessage(AWSIotMessage message) {
System.out.println("Msg arrived = " + message.getStringPayload() + " from topic = " + INBOUND_TOPIC);
sendHelloWordlSync(mqttClient);
//sendHelloWordlAsync(mqttClient); //works fine
}
});
}
private static void sendHelloWordlSync(AWSIotMqttClient client) {
try {
client.publish(OUTBOUND_TOPIC, "HELLO WORLD");
System.out.println("Hello sent to topic = " + OUTBOUND_TOPIC); // won't be printed if Sync
} catch (AWSIotException e) {
e.printStackTrace();
}
}
private static void sendHelloWordlAsync(AWSIotMqttClient client) {
ForkJoinPool.commonPool().execute(() -> sendHelloWordlSync(client));
}
private static InputStream resourceAsStream(String filename) {
return Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
}
private static KeyStore readKeyStore(InputStream in, String pass) {
try {
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(in, pass.toCharArray());
return keyStore;
} catch (Exception e) {
throw new RuntimeException("Failed to read keystore", e);
}
}
}
Expected result
onMessage
callback is called on each message arrival to a 'in' topicActual result:
onMessage
reacts on the first message arrived onlyonMessage
thread is blocked by AwsIotCompletion#get:203
waitScheduledExecutorService
by AbstractAwsIotClient#dispatch
but won't be ever processed.Run a publish method in a separate thread (uncomment sendHelloWordlAsync, comment sendHelloWordlSync).
While I'm sure Lombok is very clever, I don't think its a great idea to use it in the way you do in the IoT SDK in this kind of open source project. Coming to this fresh, you can't just import the project into Eclipse to see how the classes are put together. Instead, I find that nothing compiles, and I'm forced to read the pom files, and then understand how the Lombok library works to figure out that basically someone couldn't be bothered to add getter/setter methods to their classes. That's just lazy and in no way makes the code more readable or maintainable.
Hi,
i am following the tutorial https://github.com/aws/aws-iot-device-sdk-java/blob/master/README.md to connect from Java to IoT through MQTT over WebSocket. I am using the simple main:
AWSIotMqttClient client = new AWSIotMqttClient(clientEndpoint, clientId, awsAccessKeyId, awsSecretAccessKey);
client.connect();
But i get error:
WARNING: Connect request failure
MqttException (0) - java.io.IOException: WebSocket Response header: Incorrect connection header
....
I am using my AWS credential. My user is also admin and i have policy for full access to IoT:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iot:",
"Resource": ""
}
]
}
can you pls help?
thanks lot.
I have tried connecting to an MQTT endpoint with the java sdk but always get a connection refused. I tried using the python and c sdk's and they are able to connect, but both of those libraries have a parameter for the RootCA for TLS authentication. I've looked through the java sdk and I don't see any way to include RootCA as a parameter.
Can anyone tell me if this is something I am overlooking or if the java MQTT over TLS is not possible in it's current implementation?
-Max
I cannot get my sdk to connect properly to AWS IoT, either with my own code or with the samples. Here is my aws-iot-sdk-samples.properties file:
# Client endpoint, e.g. <prefix>.iot.us-east-1.amazonaws.com
clientEndpoint=xxx.iot.us-east-1.amazonaws.com
# Client ID, unique client ID per connection
clientId=thing1
# Client certificate file
certificateFile=/Users/Ken/workspace/IotTest/src/main/resources/certs/thing1/1215d8c24d-certificate.pem.crt
# Client private key file
privateKeyFile=/Users/Ken/workspace/IotTest/src/main/resources/certs/thing1/1215d8c24d-private.pem.key
# Thing name
thingName=thing1
The certs were generated in the IoT console. They are active and have this policy attached:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iot:*",
"Resource": "arn:aws:iot:us-east-1:123456789:topic/test/*"
}
]
}
My endpoint has ACTIVE status.
This is the error I get locally:
[INFO] --- exec-maven-plugin:1.5.0:java (default-cli) @ aws-iot-device-sdk-java-samples ---
Feb 15, 2017 12:10:06 PM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
Connection lost (32109) - java.io.EOFException
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:267)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107)
... 1 more
Cloudwatch logs say
[INFO] EVENT:MQTT Client Connect MESSAGE:Connect Status: AUTHORIZATION_ERROR
I think I'm using the SDK properly. However, there doesn't seem to be a way to use the CA cert with the SDK (I used IoT's default root VeriSign cert).
Sorry for the noob question, but what am I missing here?
It is not clear to me how this project relates to https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-iot
Should I build my client based on this SDK (aws-iot-device-sdk-java), or the other SDK (aws-java-sdk-iot)?
Sorry if it's a dumb question, but honestly, I am quite lost...
I receive an unhandled java.util.concurrent.RejectedExecutionException
when:
client.setMaxConnectionRetries(2)
client.connect(10000)
client.connect(10000)
againThe issue appears to be similar to this one with aws-sdk-android.
Exception in thread "main" java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@758c83d8 rejected from java.util.concurrent.ScheduledThreadPoolExecutor@129b4fe2[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 5] at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2063) at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830) at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:326) at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:533) at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.scheduleTimeoutTask(AbstractAwsIotClient.java:392) at com.amazonaws.services.iot.client.core.AwsIotCompletion.get(AwsIotCompletion.java:187) at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.connect(AbstractAwsIotClient.java:112) at com.amazonaws.services.iot.client.AWSIotMqttClient.connect(AWSIotMqttClient.java:501) at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.connect(AbstractAwsIotClient.java:101) at com.amazonaws.services.iot.client.AWSIotMqttClient.connect(AWSIotMqttClient.java:480)
I am using this code in my android project for IoT
AWSIotMqttClient a = new AWSIotMqttClient(clientEndpoint, clientId, awsAccessKeyId,awsSecretAccessKey);
Below is stackTrace I am getting while running my App on the above line
java.lang.VerifyError: com/amazonaws/services/iot/client/mqtt/AwsIotMqttConnection
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.(AbstractAwsIotClient.java:74)
at com.amazonaws.services.iot.client.AWSIotMqttClient.(AWSIotMqttClient.java:156)
at com.synerzip.rohitd.CameraSpyActivity.onCreate(CameraSpyActivity.java:207)
at android.app.Activity.performCreate(Activity.java:5242)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
Can you help me to solve this issue?
AWSIotMqttClient does not acknowledge the client network connectivity has been disrupted, even if Paho recognizes the timeout.
Below, I have a scheduled task to check connection status and reestablish as necessary. Unfortunately, awsClient.getConnectionStatus() continues to return AWSIotConnectionStatus.CONNECTED even when the WiFi is off. Hence the client cannot recover after WiFi is back on.
I would appreciate any help how to do this properly, if the SDK behavior is intentional.
The code;
@FXML
public void initialize() {
<code skipped ...>
awsClient = new MyAWSIotMqttClient(AWSHOST, AWSCLIENTID, AWSCLIENTKEY, AWSCLIENTSECRET);
mqttConnectTask = new Timer();
mqttConnectTask.schedule(new TimerTask() {
@Override
public void run() {
System.out.println("\n(I) >>> " + System.currentTimeMillis() / 1000 + ": Scheduled AWS connection checker");
System.out.println(awsClient.getConnectionStatus());
if (awsClient.getConnectionStatus() != AWSIotConnectionStatus.CONNECTED) {
System.out.println("\n(I) >>> " + System.currentTimeMillis() / 1000 + ": attempting to reconnect to AWS...");
mqttConnect();
}
}
}, 0, 15000);
}
void mqttConnect() {
Task<Void> task = new Task<Void>() {
@Override
protected Void call() throws Exception {
try {
awsClient.connect();
if (awsClient.getConnectionStatus() == AWSIotConnectionStatus.CONNECTED)
updateProgress(1L, 1L);
awsClient.subscribe(new TopicListener(AWSSHADOWGETACCEPT, true), true);
awsClient.subscribe(new TopicListener(AWSSHADOWUPDACCEPT, true), true);
System.out.println("\n(I) >>> " + System.currentTimeMillis() / 1000 + ": Sending shadow get request...");
awsClient.publish(new IotMessage(AWSSHADOWGET, AWSIotQos.QOS0, ""));
}
catch (AWSIotException e) {
e.printStackTrace();
}
return null;
}
};
task.progressProperty().addListener((observable, oldValue, newValue) -> {
if ( newValue.longValue() == 1L) {
fLedAwsConnIndicator.setLedColor(Color.GREEN);
fLedAwsConnIndicator.setOn(true);
}
});
new Thread(task).start();
}
The output:
(I) >>> 1520919481: Scheduled AWS connection checker
DISCONNECTED
(I) >>> 1520919481: attempting to reconnect to AWS...
Mar 13, 2018 8:38:03 AM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionSuccess
INFO: Connection successfully established
Mar 13, 2018 8:38:03 AM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionSuccess
INFO: Client connection active: demouser
(I) >>> 1520919484: Sending shadow get request...
(I) <<< 1520919484: Message arrived
[$aws/things/<name skipped>/shadow/get/accepted]
{"state":{"reported":{"connected" <rest skipped ...>
(I) >>> 1520919496: Scheduled AWS connection checker
CONNECTED
***** Turned WIFI OFF at this point
(I) >>> 1520919511: Scheduled AWS connection checker
CONNECTED
(I) >>> 1520919526: Scheduled AWS connection checker
CONNECTED
(I) >>> 1520919541: Scheduled AWS connection checker
CONNECTED
Mar 13, 2018 8:39:04 AM org.eclipse.paho.client.mqttv3.internal.ClientState checkForActivity
SEVERE: demouser: Timed out as no activity, keepAlive=30,000 lastOutboundActivity=1,520,919,514,095 lastInboundActivity=1,520,919,484,319 time=1,520,919,544,101 lastPing=1,520,919,514,095
(I) >>> 1520919556: Scheduled AWS connection checker
CONNECTED
(I) >>> 1520919571: Scheduled AWS connection checker
CONNECTED
***** Turned WIFI ON at this point
(I) >>> 1520919586: Scheduled AWS connection checker
CONNECTED
***** Terminated the application
com.amazonaws.services.iot.client.AWSIotException: Client is currently disconnecting (32102)
at com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnection.closeConnection(AwsIotMqttConnection.java:77)
at com.amazonaws.services.iot.client.core.AwsIotConnection.disconnect(AwsIotConnection.java:263)
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.disconnect(AbstractAwsIotClient.java:130)
at com.amazonaws.services.iot.client.AWSIotMqttClient.disconnect(AWSIotMqttClient.java:557)
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.disconnect(AbstractAwsIotClient.java:125)
at com.amazonaws.services.iot.client.AWSIotMqttClient.disconnect(AWSIotMqttClient.java:536)
at com.innodron.awsclient.MainAppController.shutdown(MainAppController.java:227)
at com.innodron.awsclient.Main.lambda$0(Main.java:27)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at com.sun.javafx.stage.WindowPeerListener.closing(WindowPeerListener.java:88)
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.run(GlassWindowEventHandler.java:122)
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.run(GlassWindowEventHandler.java:40)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.lambda$handleWindowEvent$422(GlassWindowEventHandler.java:151)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.handleWindowEvent(GlassWindowEventHandler.java:149)
at com.sun.glass.ui.Window.handleWindowEvent(Window.java:1270)
at com.sun.glass.ui.Window.notifyClose(Window.java:1174)
Caused by: Client is currently disconnecting (32102)
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:31)
at org.eclipse.paho.client.mqttv3.internal.ClientComms.disconnect(ClientComms.java:455)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.disconnect(MqttAsyncClient.java:632)
at com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnection.closeConnection(AwsIotMqttConnection.java:75)
... 25 more
The latest version is 1.2.0.
Is there any plan to upgrade?
I received this exception multiple times when I disconnect and reconnect the internet on my computer.
After this appears, the client can no longer receive push notifications. Is there anything I can do to prevent this without having to recompile the source code into my own library? Thanks.
Error:
com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
MqttException (0) - java.lang.NullPointerException
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:664)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.receiveHandshakeResponse(WebSocketHandshake.java:133)
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.execute(WebSocketHandshake.java:74)
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketSecureNetworkModule.start(WebSocketSecureNetworkModule.java:77)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650)
... 1 more
Code: (upgradeHeader is null)
String upgradeHeader = (String) headerMap.get(HTTP_HEADER_UPGRADE);
if(!upgradeHeader.toLowerCase().contains(HTTP_HEADER_UPGRADE_WEBSOCKET)){
throw new IOException("WebSocket Response header: Incorrect upgrade.");
}
Steps to reproduce:
...
com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
...
I have been trying to run the AWS IOT samples. After doing whatever was necessary on the AWS IOT site and using the AWS MQTT client to test publish and subscribe, I tried to connect from my laptop using both nodejs and java. Both do not seem to work and I am unable to figure out what is wrong. While nodsjs just hangs with no clue what is going on, java throws the following on the console. I have no idea what to try or do.
\aws-iot-device-sdk-java-master>mvn exec:java -pl aws-iot-device-sdk-java-samples -Dexec.mainClass="com.amazonaws.services.iot.client.sample.pubSub.PublishSubscribeSample" -Dexec.args="-clientEndpoint a18ddgj0v6owjf.iot.us-west-2.amazonaws.com:8883 -clientId AKIAI4QCZFKU7LECMIEA -certificateFile ..\cert\f2539b98b0-certificate.pem.crt -privateKeyFile ..\cert\f2539b98b0-private.pem.key"
[INFO] Scanning for projects...
[INFO] Inspecting build with total of 1 modules...
[INFO] Installing Nexus Staging features:
[INFO] ... total of 1 executions of maven-deploy-plugin replaced with nexus-staging-maven-plugin
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building aws-iot-device-sdk-java-samples 1.1.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.6.0:java (default-cli) @ aws-iot-device-sdk-java-samples ---
Cert file:..\cert\f2539b98b0-certificate.pem.crt Private key: ..\cert\f2539b98b0-private.pem.key
Aug 29, 2017 2:19:50 PM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
Connection lost (32109) - java.io.EOFException
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:267)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107)
... 1 more
Aug 29, 2017 2:19:50 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Aug 29, 2017 2:19:50 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: AKIAI4QCZFKU7LECMIEA
Aug 29, 2017 2:19:53 PM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
Aug 29, 2017 2:19:56 PM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
Connection lost (32109) - java.io.EOFException
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:267)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107)
... 1 more
Aug 29, 2017 2:19:56 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Aug 29, 2017 2:19:56 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: AKIAI4QCZFKU7LECMIEA
Aug 29, 2017 2:20:02 PM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
Aug 29, 2017 2:20:04 PM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
Connection lost (32109) - java.io.EOFException
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:267)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107)
... 1 more
Aug 29, 2017 2:20:04 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Aug 29, 2017 2:20:04 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: AKIAI4QCZFKU7LECMIEA
Aug 29, 2017 2:20:16 PM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
Aug 29, 2017 2:20:19 PM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
Connection lost (32109) - java.io.EOFException
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:267)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107)
... 1 more
Aug 29, 2017 2:20:19 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Aug 29, 2017 2:20:19 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: AKIAI4QCZFKU7LECMIEA
Aug 29, 2017 2:20:43 PM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
Aug 29, 2017 2:20:46 PM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
Connection lost (32109) - java.io.EOFException
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:267)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107)
... 1 more
Aug 29, 2017 2:20:46 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Aug 29, 2017 2:20:46 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: AKIAI4QCZFKU7LECMIEA
Aug 29, 2017 2:21:16 PM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
Aug 29, 2017 2:21:18 PM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
Connection lost (32109) - java.io.EOFException
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:267)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107)
... 1 more
Aug 29, 2017 2:21:18 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Aug 29, 2017 2:21:18 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection retry cancelled or exceeded maximum retries
[Aug 29, 2017 2:21:18 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionClosed
INFO: Client connection closed: AKIAI4QCZFKU7LECMIEA
WARNING]
com.amazonaws.services.iot.client.AWSIotException
at com.amazonaws.services.iot.client.core.AwsIotCompletion.get(AwsIotCompletion.java:213)
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.connect(AbstractAwsIotClient.java:112)
at com.amazonaws.services.iot.client.AWSIotMqttClient.connect(AWSIotMqttClient.java:501)
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.connect(AbstractAwsIotClient.java:93)
at com.amazonaws.services.iot.client.AWSIotMqttClient.connect(AWSIotMqttClient.java:463)
at com.amazonaws.services.iot.client.sample.pubSub.PublishSubscribeSample.main(PublishSubscribeSample.java:138)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:282)
at java.lang.Thread.run(Thread.java:745)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:34 min
[INFO] Finished at: 2017-08-29T14:21:18+05:30
[INFO] Final Memory: 19M/184M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project aws-iot-device-sdk-java-samples: An exception occured while executing the Java class. null: AWSIotException -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Hi, Im using this sdk examples to the AWS IoT.
I'm having a problem when trying to connect two clients.
My point is to make one application "subscriber" the messages the other application "publisher" publishes to a certain topic.
My problem is that when one client connects the other disconnects, and so on.
The message is never received by the "subscriber" application.
Does anyone has a possible solution for this problem?
Some configuration needed to make this approach works?
Thanks in advance!
Are there any plans on supporting AWS Greengass Discovery in the near future?
Would love to use Java for my GG devices as well.
throws follow Exception when use "awsAccessKeyId" and "awsSecretAccessKey" to access AWS IoT in China
same issue as #41
Hi All,
Since mqtt ports are blocked in my org I am trying to use websockets. I tested it with telnet and it is works fine.
I am able to run the same application with websockets from my laptop and it works fine but when i try to run from raspberry pi i am getting the following error.
I tried to change versions of paho mqtt lib and aws sdks but no use.
the following lib versions used.
aws-iot-device-sdk-java-1.1.0
org.eclipse.paho.client.mqttv3-1.1.0
trying to connect to AWS IOT
Feb 01, 2018 4:03:11 PM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
MqttException (0) - java.lang.NullPointerException
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:664)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.receiveHandshakeResponse(WebSocketHandshake.java:133)
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.execute(WebSocketHandshake.java:74)
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketSecureNetworkModule.start(WebSocketSecureNetworkModule.java:77)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650)
... 1 more
Feb 01, 2018 4:03:11 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Feb 01, 2018 4:03:11 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: TrackAndTraceClientId
Feb 01, 2018 4:03:14 PM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
Feb 01, 2018 4:03:17 PM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
MqttException (0) - java.lang.NullPointerException
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:664)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.receiveHandshakeResponse(WebSocketHandshake.java:133)
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.execute(WebSocketHandshake.java:74)
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketSecureNetworkModule.start(WebSocketSecureNetworkModule.java:77)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650)
... 1 more
Feb 01, 2018 4:03:17 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Feb 01, 2018 4:03:17 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: TrackAndTraceClientId
Hi,
things are working for me, but I see warnings like this:
Dec 13, 2016 11:30:29 AM com.amazonaws.services.iot.client.shadow.AwsIotDeviceCommandManager onCommandAck
WARNING: Unknown command received from topic $aws/things/3d621cd1-aeac-4fa3-8a7f-560ebca7473f/shadow/update/accepted
The problem seems to originate in AwsIotDeviceCommandManager, line 268, where it returns null because it can't find a particular command in pendingCommands. Is this normal? Everything seems to work as I expect otherwise.
Use Case - My Client application has a TrustStore Loaded in its Java Application Thread which has nothing to do with Certificates required for AWS IOT connectivity.
I am Trying to connect to AWS IoT MQTT Broker as "MQTT over WebSocket with AWS Signature Version 4 authentication".
But i am getting below error:
Exception in thread "main" com.amazonaws.services.iot.client.AWSIotException: MqttException (0) - java.io.IOException: Invalid keystore format
at com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnection.openConnection(AwsIotMqttConnection.java:68)
at com.amazonaws.services.iot.client.core.AwsIotConnection.connect(AwsIotConnection.java:246)
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.connect(AbstractAwsIotClient.java:111)
at com.amazonaws.services.iot.client.AWSIotMqttClient.connect(AWSIotMqttClient.java:501)
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.connect(AbstractAwsIotClient.java:93)
at com.amazonaws.services.iot.client.AWSIotMqttClient.connect(AWSIotMqttClient.java:463)
at com.emeter.PublishSubscribeSample.main(PublishSubscribeSample.java:110)
Caused by: MqttException (0) - java.io.IOException: Invalid keystore format
at org.eclipse.paho.client.mqttv3.internal.security.SSLSocketFactoryFactory.getSSLContext(SSLSocketFactoryFactory.java:1284)
at org.eclipse.paho.client.mqttv3.internal.security.SSLSocketFactoryFactory.createSocketFactory(SSLSocketFactoryFactory.java:1344)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.createNetworkModule(MqttAsyncClient.java:446)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.createNetworkModules(MqttAsyncClient.java:349)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.connect(MqttAsyncClient.java:557)
at com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnection.openConnection(AwsIotMqttConnection.java:66)
... 6 more
Caused by: java.io.IOException: Invalid keystore format
at sun.security.provider.JavaKeyStore.engineLoad(Unknown Source)
at sun.security.provider.JavaKeyStore$JKS.engineLoad(Unknown Source)
at sun.security.provider.KeyStoreDelegator.engineLoad(Unknown Source)
at sun.security.provider.JavaKeyStore$DualFormatJKS.engineLoad(Unknown Source)
at java.security.KeyStore.load(Unknown Source)
at org.eclipse.paho.client.mqttv3.internal.security.SSLSocketFactoryFactory.getSSLContext(SSLSocketFactoryFactory.java:1259)
... 11 more
After our analysis we found eclipse paho tries to create SSLSocketFactoryFactory and tries to read KeyStore and TrustStore. In getSSLContext() method of SSLSocketFactoryFactory its doing so. Please go through code.
We also found in the constructor of AwsIotWebsocketConnection as shown below, SocketFactory is passed as null.:
public AwsIotWebsocketConnection(AbstractAwsIotClient client, String awsAccessKeyId, String awsSecretAccessKey,
String sessionToken) throws AWSIotException {
super(client, null, "wss://" + client.getClientEndpoint() + ":443");
// Port number must be included in the endpoint for signing otherwise
// the signature verification will fail. This is because the Paho client
// library always includes port number in the host line of the
// HTTP request header, e.g "Host: data.iot.us-east-1.amazonaws.com:443".
urlSigner = new AwsIotWebSocketUrlSigner(client.getClientEndpoint() + ":443");
urlSigner.updateCredentials(awsAccessKeyId, awsSecretAccessKey, sessionToken);
}
Due to Null socketFactory, eclipse paho tries to create a socket factory which in turn leads to this problem. Ideally AWS must have provided way to input socket factory.
I have already tried not setting TrustStore which is my application trust store certificate file. After removing trust store everythign works.
com.amazonaws.services.iot.client.AWSIotException: Too many publishes in progress (32202)
at com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnection.publishMessage(AwsIotMqttConnection.java:92)
at com.amazonaws.services.iot.client.core.AwsIotConnection.publish(AwsIotConnection.java:161)
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.publish(AbstractAwsIotClient.java:186)
at com.amazonaws.services.iot.client.AWSIotMqttClient.publish(AWSIotMqttClient.java:793)
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.publish(AbstractAwsIotClient.java:181)
this is how i'm sending messages to shadow. i'm executing the method which sends out data to the aws for 3 times without an time interval, and i'm getting this error saying too many publishes, is there a solution for this error.
deviceMsg.setQos(AWSIotQos.QOS0);
deviceMsg.setStringPayload(shadow);
deviceMsg.setTopic(updateTopic);
awsIotClient.publish(deviceMsg);
Hi everyone,
is there a way to make the AWSIotMqttClient with WebSocket working behind a proxy?
The client is behind an HTTPS proxy and the settings are passed to the application through the http.proxyHost and http.proxyPort JVM options.
The problem we are facing right now is that the client is unable to resolve the AWS Iot Endpoint, receiving an UnknownHostException
. Is there a way to solve this issue without local access to a DNS?
For a couple of weeks now I've been fighting with AWS IoT to get it to work somewhat reliably - w/o success so far. My sensor is publishing results every 15 minutes or so via MQTT over TLS. After a few hours I get:
10:48:04.467 [MQTT Ping: pi] ERROR o.e.p.c.m.i.ClientState - pi: Timed out as no activity, keepAlive=30,000 lastOutboundActivity=1,486,032,454,464 lastInboundActivity=1,486,032,424,570 time=1,486,032,484,445 lastPing=1,486,032,454,464
10:48:04.516 [pool-1-thread-1] INFO c.a.s.i.c.c.AwsIotConnection - Connection temporarily lost
10:48:04.521 [pool-1-thread-1] INFO c.a.s.i.c.c.AwsIotConnection - Connection retry cancelled or exceeded maximum retries
10:48:04.525 [pool-1-thread-1] INFO c.a.s.i.c.c.AbstractAwsIotClient - Client connection closed: pi
After this error, publish() always fails with:
11:01:04.847 [PmMeter] WARN c.o.s.a.AWSIotDataCollector - cannot publish result
java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@1c4089b rejected from java.util.concurrent.ScheduledThreadPoolExecutor@1fb9ffb[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 141]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2047)
This happens despite awsIotClient.setMaxConnectionRetries(Integer.MAX_VALUE);
Now, I have no idea how to recover from such error except creating a new AwsIotClient instance - because previous executor thread pool was shutdown and it is useless.
Please, test AWS IoT java sdk with long-lasting connections with rare inactivity.
This is a very often scenario for IoT.
Hi,
We have been doing some performance testing and facing an issue almost on daily basis. After close to 2-3 million message processing via MQTT broker using AWS Java based Client SDK, our application stops receiving messages.
In CloudWatch Management Logs we are able to see below messages.
Please provide inputs why this may be happening. We are Using AWSIOT Connect with timeout and Subscribe method with timeout and blocking as shown below:
awsIotClient.connect(timeout);
if(logger.isDebugEnabled()) {
logger.debug("Successfully Connected to AWS Broker");
}
awsIotClient.subscribe(mqttMessageCallback, timeout, blocking);
-Sumit
Today suddenly AWSIotMqttClient::connect started failing with:
com.amazonaws.services.iot.client.AWSIotException: null
at com.amazonaws.services.iot.client.core.AwsIotCompletion.get(AwsIotCompletion.java:213) ~[hdm-push-server-1.3.1-standalone.jar:1.3.1]
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.connect(AbstractAwsIotClient.java:112) ~[hdm-push-server-1.3.1-standalone.jar:1.3.1]
at com.amazonaws.services.iot.client.AWSIotMqttClient.connect(AWSIotMqttClient.java:501) ~[hdm-push-server-1.3.1-standalone.jar:1.3.1]
at com.amazonaws.services.iot.client.core.AbstractAwsIotClient.connect(AbstractAwsIotClient.java:93) ~[hdm-push-server-1.3.1-standalone.jar:1.3.1]
at com.amazonaws.services.iot.client.AWSIotMqttClient.connect(AWSIotMqttClient.java:463) ~[hdm-push-server-1.3.1-standalone.jar:1.3.1]
It seems org.eclipse.paho.client.mqttv3 got upgraded from 1.1.0 to 1.1.1. When forced back to 1.1.0 the connection works again
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.