MQTT Connection lost on MQTT subscriber to Internet of Things Server

0 votes

Currently writing a Java application to publish/subscribe to the 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 the same seems to be the publish... What gives me the error is the subscribe:

Trying it by mosquitto_sub command line, 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)
...

and so on.

When I try with java with a MqttAsyncClient, the subcribe() method returns, but then the waitForCompletion() method instantly follows.

Connection lost (32109) - java.io.EOFException

My code goes like this.

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 sure that the lib does not release the persistence path used by the AsyncClient, making it 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 don't know how to access the IoT-side mqtt server to realize what's going on in there.

Any ideas? 

Oct 3, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
4,565 views

1 answer to this question.

0 votes

An invalid topic "matteo" seems to be causing the problem.

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

answered Oct 3, 2018 by Annie97
• 2,160 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

Working of IoT under weak to no internet connection

A few projects are currently going on ...READ MORE

answered Mar 11, 2019 in IoT (Internet of Things) by Upasana
• 8,620 points
695 views
0 votes
1 answer

I want to restrict the opening of Browser on URL Click

You can call it as a web ...READ MORE

answered Aug 7, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
5,369 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

MQTT broker for Google App Engine

You had a hard time finding anything ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,410 views
0 votes
1 answer

Eclipse Paho: read data from MQTT Broker

From what I could analyze, you've been ...READ MORE

answered Aug 9, 2018 in IoT (Internet of Things) by DataKing99
• 8,250 points
2,363 views
0 votes
1 answer

Need to enclose MQTTCLient Instance in try catch block

The instance doesn't need to be surrounded by try/catch, but ...READ MORE

answered Aug 21, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
1,211 views
0 votes
1 answer

Server connection to iot device

It depends on the kind of socket, ...READ MORE

answered Oct 3, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
1,541 views
0 votes
1 answer

How to Uniquely identify Thingworx things?

No, Thing identifier does not account for ...READ MORE

answered Sep 19, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
819 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP