Стараюсь подключиться к MQTT серверу (Cloud MQTT) с помощью библиотеки PahoMqtt.
Выдает следующие ошибки:
Reason code - 5, по документации REASON_CODE_NOT_AUTHORIZED.
Message code: нет прав на подключение.
Привожу код:
public static void main(String[] args) {
String topic = "Lesson_MQTT_server";
String broker = "tcp://m15.cloudmqtt.com:18594";
char [] pass = "qmaoaTfDebag".toCharArray(); // Fake pass
String userId = "oelmanhl";
String content = "Hello world!";
int qos = 0;
try {
MqttClient client = new MqttClient (broker, userId, new MemoryPersistence());
MqttConnectOptions options = new MqttConnectOptions ();
//options.setAutomaticReconnect(true);
options.setCleanSession(true);
options.setPassword(pass);
System.out.println ("Connecting...");
client.connect(options); // Stop here, can't connect to MQTT server.
System.out.println ("Conntected!");
MqttMessage message = new MqttMessage ();
message.clearPayload();
message.setPayload(content.getBytes());
message.setQos(qos);
System.out.println ("Publishing message...");
client.publish(topic, message);
System.out.println ("Message published!");
client.disconnect();
} catch (MqttException ex) {
System.out.println ("Reason code: " + ex.getReasonCode());
System.out.println ("Cause code: " + ex.getCause());
System.out.println ("Message code: " + ex.getMessage());
}