Created
April 6, 2018 09:37
-
-
Save jtuttas/b31f07f679dde22ad90650f14cf87214 to your computer and use it in GitHub Desktop.
MQTT mit Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package mmbbs; | |
| 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.MqttException; | |
| import org.eclipse.paho.client.mqttv3.MqttMessage; | |
| public class MQTT { | |
| public static void main(String[] args) { | |
| MqttClient client; | |
| try { | |
| client = new MqttClient("tcp://service.joerg-tuttas.de", "clientId"); | |
| client.connect(); | |
| System.out.println("Connected"); | |
| client.setCallback(new MqttCallback() { | |
| public void connectionLost(Throwable cause) { | |
| System.out.println("Connection Lost"); | |
| } | |
| public void messageArrived(String topic, MqttMessage message) throws Exception { | |
| System.out.println("Message arived topic:"+topic+" message:"+message.toString()); | |
| } | |
| public void deliveryComplete(IMqttDeliveryToken token) { | |
| System.out.println("deliveryCompleted"); | |
| } | |
| }); | |
| client.subscribe("esp32/temp"); | |
| while(true) { | |
| } | |
| } catch (MqttException e) { | |
| // TODO Auto-generated catch block | |
| e.printStackTrace(); | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Zu installieren via Maven im pom.xml