Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] (no subject)

Hi,
 
Yes I've installed emqqt in a vm and followed the instructions here (http://emqtt.io/docs/v2/guide.html) to set up auth and set allow_anonymous to false in the configuration.
 
./bin/emqttd_ctl plugins load emq_auth_username 
 
./bin/emqttd_ctl users add james password
 
I then tested with mosquitto_sub and mosquitto_pub to verify that the new auth configuration was working
 
Finally, I Use the example here, but set the host to the plain MQTT port (1883) and added the username and password using:
 
            connOpts.setUserName("james");
            connOpts.setPassword("password".toCharArray());
 
When I compiled and ran it, everything worked and I saw the message published to the correct topic.
 
 
I'm not an expert on emqtt (this being the first time I've ever used it), could it be that your configuration is not complete for all of your listeners? As you've confirmed that the _javascript_ client (Using websockets) works, it might be a good idea to use the mosquitto_pub and mosquitto_sub tools to verify that the plain MQTT over TCP port is also using the auth configuration correctly. E.g.
 
mosquitto_sub -t test -u james -P password
 
mosquitto_pub -t test -m Hello -u james -P password
 
 
 
Kind regards,
 
James Sutton
Software Engineer - IoT Foundation - MQTT Open Source Projects
Ops Team - Wimbledon Project

Phone: 01962 815438 | Extension: x372454
E-mail: 
Personal Website: www.jsutton.co.uk
Find me on:     
IBM

Hursley Park
HursleySO212JN
United Kingdom
 
IBM United Kingdom Limited Registered in England and Wales with number 741598 Registered office: PO Box 41, North Harbour, Portsmouth, Hants. PO6 3AU
 
 
----- Original message -----
From: manish kumar <mkj.online@xxxxxxxxx>
Sent by: paho-dev-bounces@xxxxxxxxxxx
To: General development discussions for paho project <paho-dev@xxxxxxxxxxx>
Cc:
Subject: Re: [paho-dev] (no subject)
Date: Tue, Apr 11, 2017 8:13 AM
 
Any update on this issue?
 
On Apr 10, 2017 4:38 PM, "manish kumar" <mkj.online@xxxxxxxxx> wrote:
Can you please try with emqttd broker also
 
On Apr 10, 2017 4:24 PM, "manish kumar" <mkj.online@xxxxxxxxx> wrote:
I am using emqttd broker
 
On Apr 10, 2017 4:17 PM, "James Sutton1" <james.sutton@xxxxxxxxxx> wrote:
Hi,
 
I can't see any issues with your code, it's exactly what I would do. What MQTT Broker are you using? I tested the following against mosquitto which worked fine:
 

import org.eclipse.paho.client.mqttv3.IMqttToken;

import org.eclipse.paho.client.mqttv3.MqttAsyncClient;

import org.eclipse.paho.client.mqttv3.MqttConnectOptions;

import org.eclipse.paho.client.mqttv3.MqttException;

import org.eclipse.paho.client.mqttv3.MqttMessage;

import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;

 

public class AuthTest {

public static void main( String[] args )

    {

 

      String topic        = "auth_test";

        String content      = "Message from MqttPublishSample";

        int qos             = 0;

        String broker       = "tcp://localhost";

        String clientId     = "auth_test";

        MemoryPersistence persistence = new MemoryPersistence();

 

        try {

            MqttAsyncClient sampleClient = new MqttAsyncClient(broker, clientId, persistence);

            MqttConnectOptions connOpts = new MqttConnectOptions();

            connOpts.setCleanSession(true);

            connOpts.setMaxInflight(1000);

            connOpts.setUserName("USERNAME");

            connOpts.setPassword("PASSWORD".toCharArray());

            System.out.println("Connecting to broker: "+broker);

            IMqttToken conToken = sampleClient.connect(connOpts);

            conToken.waitForCompletion();

            System.out.println("Connected");

            System.out.println("Publishing message: "+content);

            System.out.println("About to send messages");

            for(int i = 0; i < 10; i++){

            sampleClient.publish(topic, new MqttMessage(content.getBytes()));

            }

            sampleClient.disconnect();

            System.out.println("Disconnected");

            System.exit(0);

        } catch(MqttException me) {

            System.out.println("reason "+me.getReasonCode());

            System.out.println("msg "+me.getMessage());

            System.out.println("loc "+me.getLocalizedMessage());

            System.out.println("cause "+me.getCause());

            System.out.println("excep "+me);

            me.printStackTrace();

        }

    }

}

 
 
Kind regards,
 
James Sutton
Software Engineer - IoT Foundation - MQTT Open Source Projects
Ops Team - Wimbledon Project

Phone: 01962 815438 | Extension: x372454
E-mail: james.sutton@xxxxxxxxxm
Personal Website: www.jsutton.co.uk
Find me on:     
IBM

Hursley Park
HursleySO212JN
United Kingdom
 
IBM United Kingdom Limited Registered in England and Wales with number 741598 Registered office: PO Box 41, North Harbour, Portsmouth, Hants. PO6 3AU
 
 
----- Original message -----
From: manish kumar <mkj.online@xxxxxxxxx>
Sent by: paho-dev-bounces@xxxxxxxxxxx
To: General development discussions for paho project <paho-dev@xxxxxxxxxxx>
Cc:
Subject: [paho-dev] (no subject)
Date: Mon, Apr 10, 2017 9:50 AM
 
 

Is there some issue with java client when connecting with username & password ???

paho JS client it works but from java client it doesn't.
I have this code

    MqttConnectOptions conOpt = new MqttConnectOptions();
    conOpt.setCleanSession(false);
    conOpt.setUserName("test5");
    conOpt.setPassword("123".toCharArray());
    MqttDefaultFilePersistence filePersistence = new MqttDefaultFilePersistence("/home/manish/Downloads/mqttPersist");
    client = new MqttAsyncClient(appProps.getProperty("mqtt.broker"),
            appProps.getProperty("mqtt.clientId"), filePersistence);
    client.setCallback(this);
    client.connect(conOpt, new IMqttActionListener() {
        @Override
        public void onSuccess(IMqttToken imt) {
            try {
                client.subscribe(Constants.INTERNAL_TOPICS, Constants.INTERNAL_TOPIC_QOS);
            } catch (MqttException ex) {
                ex.printStackTrace();
            }
        }

        @Override
        public void onFailure(IMqttToken imt, Throwable thrwbl) {
            thrwbl.printStackTrace();
        }
    });

i am getting this exception

Bad user name or password (4)
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:28)
at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:885)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:118)
at java.lang.Thread.run(Thread.java:745)

emqt console

06:47:36.456 [error] Client(notification_subs_bot@127.0.0.1:50741): Username 'undefined' login failed for username_or_password_undefined
06:47:36.463 [error] Client(notification_subs_bot@127.0.0.1:50742): Username 'undefined' login failed for username_or_password_undefined

According paho documentation public void setPassword(char[] password) So here i am passing char[] as paasword

--
Thanks,
Manish Kumar
_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev
 
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU


_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev
_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev
 
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU


Back to the top