Paho MQTT : Exception in Thread

0 votes

So, I downloaded a Java code to demonstrate Paho MQTT.

 public class Thermometer {

    public static final String BROKER_URL = "tcp://test.mosquitto.org:1883";

    public static final String TOPIC = "xyz.abc";

    private MqttClient client;


    public Thermometer() {
        try {
            MemoryPersistence per = new MemoryPersistence();
            String clientId = UUID.randomUUID().toString();
            client = new MqttClient(BROKER_URL, clientId, per);
        } catch (MqttException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

But when I try to run it, it locates at client = new MqttClient(BROKER_URL, clientId, per);with

Exception in thread "main" java.lang.IllegalArgumentException at org.eclipse.paho.client.mqttv3.MqttClient.(MqttClient.java:170) at mqtt_pub.Thermometer.(Thermometer.java:26) at mqtt_pub.Thermometer.main(Thermometer.java:65)

Can anyone fix this?

Apr 4 in IoT (Internet of Things) by Upasana
• 7,600 points
14 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

So, I'd reckon you try to take a look at the source code of MttqClient, where, you shall see that the uuid can only have a length of up to 23 characters.

if (clientId == null || clientId.length() == 0 || clientId.length() > 23)  
{
      throw new IllegalArgumentException();
}

But here, the UUID.randomUUID().toString() returns a string with the length of 36 characters.

answered Apr 4 by Shubham
• 12,230 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

How to read data from MQTT in Eclipse Paho?

You don't read data from a MQTT ...READ MORE

answered Aug 9, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
47 views
0 votes
1 answer

Changing message format in KURA MQTT cloud client

The Eclipse Kura communicates with a MQTT ...READ MORE

answered Jul 29, 2018 in IoT (Internet of Things) by DataKing99
• 8,100 points
88 views
0 votes
1 answer

Publishing commands to device in IBM IoT using MQTT in Java

If you are publishing from an application, ...READ MORE

answered Jul 27, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
317 views
0 votes
1 answer

The MQTT folder is missing in Bluemix IoT NodeJS code,

IoT-Workbench now uses new improved code generation ...READ MORE

answered Aug 8, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
37 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,260 points
44 views
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,040 points
144 views
0 votes
1 answer

Eclipse Paho: read data from MQTT Broker

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

answered Aug 8, 2018 in IoT (Internet of Things) by DataKing99
• 8,100 points
398 views
0 votes
1 answer

Building KAA on Operating System X

Actually, it does not depend on OS. ...READ MORE

answered Sep 11, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
25 views
0 votes
1 answer

MQTT : Web Socket in python

You can simply create a configuration file ...READ MORE

answered Apr 15 in IoT (Internet of Things) by Shubham
• 12,230 points
39 views
0 votes
1 answer

How to detect presence of a device in a WiFi network?

Finding the mac-address would probably work. Basically, ...READ MORE

answered Nov 16, 2018 in IoT (Internet of Things) by Shubham
• 12,230 points
29 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.