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, 2019 in IoT (Internet of Things) by Upasana
• 8,620 points
1,529 views

1 answer to this question.

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, 2019 by Shubham
• 13,490 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,240 points
950 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,250 points
1,182 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,240 points
1,516 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,240 points
1,008 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,240 points
1,264 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,130 points
1,546 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,472 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,240 points
757 views
0 votes
1 answer

MQTT : Web Socket in python

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

answered Apr 15, 2019 in IoT (Internet of Things) by Shubham
• 13,490 points
2,907 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
• 13,490 points
3,363 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