Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection lost on MQTT subscribe to Internet of Things Server

I'm writing a Java application to publish/subscribe to Internet of Things MQTT server using the Eclipse Paho Lib (org.eclipse.paho.client.mqtt3-1.0.2.jar), both on Device and Application side.

Connect works well with both credential types, and same seems to be the publish... What gives me the error is the subscribe:

Trying it by mosquitto_sub command line, it loops like this:

Client a:u5o0ux:tws sending CONNECT
Client a:u5o0ux:tws received CONNACK
Client a:u5o0ux:tws sending SUBSCRIBE (Mid: 1, Topic: matteo, QoS: 0)
Client a:u5o0ux:tws sending CONNECT
Client a:u5o0ux:tws received CONNACK
Client a:u5o0ux:tws sending SUBSCRIBE (Mid: 2, Topic: matteo, QoS: 0)
Client a:u5o0ux:tws sending CONNECT
Client a:u5o0ux:tws received CONNACK
Client a:u5o0ux:tws sending SUBSCRIBE (Mid: 3, Topic: matteo, QoS: 0)
Client a:u5o0ux:tws sending CONNECT
Client a:u5o0ux:tws received CONNACK
Client a:u5o0ux:tws sending SUBSCRIBE (Mid: 4, Topic: matteo, QoS: 0)
...

And so on.

When trying from java with an MqttAsyncClient, the subcribe() method returns, but then the waitForCompletion() method istantly trows:

Connection lost (32109) - java.io.EOFException

This is the code I am running:

String tmpDir = System.getProperty("java.io.tmpdir");
MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir); 

...

// Construct a non blocking MQTT client instance
client = new MqttAsyncClient(getMQTTBrokerURL(), clientId, dataStore);

// Set this wrapper as the callback handler
client.setCallback(this);

and then:

connect();

...

IMqttToken subToken = client.subscribe(topic, qos, null, null);
subToken.waitForCompletion();

Also, this error makes the lib to not relese the persistence path user by the AsyncClient, making it to trow a "Persistence Already in Use" exception on every retry, until I stop the JVM and manually clear that path, but i suppose this to be some sort of library bug.

Unfortunately, I can't (or don't know how) access the IoT-side mqtt server to realize what's going on in there.

Any ideas? Thank you

like image 673
Drackmord Avatar asked Dec 06 '25 02:12

Drackmord


1 Answers

It appears your problem is likely due to invalid topic "matteo".

For connecting to the IoT Foundation in Bluemix, you will need to follow the topic format as outlined in the IBM Internet of Things Foundation documentation here: https://docs.internetofthings.ibmcloud.com/messaging/applications.html

like image 178
ValerieLampkin Avatar answered Dec 08 '25 16:12

ValerieLampkin