Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
681 B
21
Indexable
Never
String brokerUrl = "tcp://192.168.1.22:1883";
String clientId = "myClientId";
MqttClient mqttClient = new MqttClient(brokerUrl, clientId);
mqttClient.connect();

String topic = "my/topic";
mqttClient.subscribe(topic);

mqttClient.setCallback(new MqttCallback() {
    public void messageArrived(String topic, MqttMessage message) {
        String payload = new String(message.getPayload());
        
        // vale to payload sth vash dedomenwn

    public void connectionLost(Throwable cause) {
        System.out.println("Connection lost: " + cause.getMessage());
    }

    public void deliveryComplete(IMqttDeliveryToken token) {
        // Not used in this example
    }
});