Connection lost on MQTT subscribe to Internet Things Server

I am writing a Java application to publish / subscribe to an Internet Things MQTT server using the Eclipse Paho Lib (org.eclipse.paho.client.mqtt3-1.0.2.jar), both device side and application.

The connection works well with both types of credentials and it looks like it's a post ... Which gives me the error message:

Tried it with the mosquitto_sub command, it looks 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)
...

      

Etc.

When trying from java with MqttAsyncClient, the subscribe () method returns, but then the waitForCompletion () method istantly running:

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 causes the lib to not delete the persistence path user in the AsyncClient causing it to throw a "Persistence Already in Use" exception on every try until I stop the JVM and clear the path manually, but I will assume this is some kind of library error.

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

Any ideas? Thanks you

+3


source to share


2 answers


Your problem is probably related to the wrong topic "matteo".



To connect to the IoT Foundation on Bluemix, you will need to follow the theme format as described in the IBM Internet of Things Foundation documentation: https://docs.internetofthings.ibmcloud.com/messaging/applications.html

+2


source


If both mosquitto_sub and your Paho Java client have problems at the same point (SUBSCRIBE), this implies a problem with your broker.

I tried to run this:

mosquitto_sub -t matteo -i 'a:u5o0ux:tws' -d -h test.mosquitto.org

      



And got the output:

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 received SUBACK
Subscribed (mid: 1): 0

      

Perhaps you can try connecting your client to test.mosquitto.org

, iot.eclipse.org

or to one of the other public MQTT brokers. Or you can run your own copy of the broker locally for testing.

0


source







All Articles