Closed kosuodhmwa closed 2 years ago
Code formatting does not work correctly on GitHub with Java code.
Why?
->
That problem seems to persist since years...
@admin
To use for both PUBLISH & SUBSCRIBE 2 seprate connection, also with 2 SEPARATE (!!) client-ids, does also not seem to work:
`
this.clientId = "test-client-id-123456";
System.out.println("MQTT client ID for publish: " + this.clientId);
this.client = new MqttClient(this.url, this.clientId, this.mqttDefaultFilePersistence);
this.client.connect(this.mqttConnectOptions);
publishTopic(this.client);
Thread.sleep(3000);
this.client.disconnect();
this.clientId = "test-client-id-654321";
System.out.println("MQTT client ID for subscribe: " + this.clientId);
this.client = new MqttClient(this.url, this.clientId, this.mqttDefaultFilePersistence);
this.client.connect(this.mqttConnectOptions);
subscribeToTopic(this.client);
Thread.sleep(3000);
this.client.disconnect();
`
Why!?
Got it!! ;-)
Version: Most current release one on 2022-04-13
PROBLEM: I publish the value 'TEST-TEST-TEST' to the topic on my remote MQTT server. That works - MQTT Explorer show me the Topic "a/b/c" with its value "TEST-TEST-TEST"...
BUT: The "Subscribe" action does not work... none of the overriden methods in MqttCallback object will be called. NONE. -> What's the problem here? Do i need a separate "connect" / "disconnect" for each case: "publish to topic" AND "subscribe to topic"
VERY VERY STRANGE the whole thing...
CODE HERE:
`package test.mqtt.lora.swisscom;
import java.util.concurrent.Flow.Subscriber; import java.util.logging.Level; import java.util.logging.Logger;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; import org.eclipse.paho.client.mqttv3.MqttCallback; import org.eclipse.paho.client.mqttv3.MqttClient; import org.eclipse.paho.client.mqttv3.MqttConnectOptions; import org.eclipse.paho.client.mqttv3.MqttMessage; import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
public class LoRaMqtt {
}`