31. Show me the code!
var mqtt = require('mqtt');
var c = mqtt.createClient(1883,
'm2m.eclipse.org');
client.on('message’, cb);
client.subscribe('/kettle232/switch');
client.publish('/kettle232/temp', '21.3');
var cb = function(topic, message) {
// turn the kettle on/off
}
32. Show me the code!
var mqtt = require('mqtt');
var c = mqtt.createClient(1883,
'm2m.eclipse.org');
client.on('message’, cb);
client.subscribe('/kettle232/switch');
client.publish('/kettle232/temp', '21.3');
var cb = function(topic, message) {
// turn the kettle on/off
}
33. Show me the code!
var mqtt = require('mqtt');
var c = mqtt.createClient(1883,
'm2m.eclipse.org');
client.on('message’, cb);
client.subscribe('/kettle232/switch');
client.publish('/kettle232/temp', '21.3');
var cb = function(topic, message) {
// turn the kettle on/off
}
34. Show me the code!
var mqtt = require('mqtt');
var c = mqtt.createClient(1883,
'm2m.eclipse.org');
client.on('message’, cb);
client.subscribe('/kettle232/switch');
client.publish('/kettle232/temp', '21.3');
var cb = function(topic, message) {
// turn the kettle on/off
}
36. Show me the code!
MqttClient mqttClient = new MqttClient
(
"tcp://m2m.eclipse.org:1883",
MqttClient.generateClientId()
);
mqttClient.setCallback(…);
mqttClient.connect();
mqttClient.subscribe("/teapot24232/#");
// the rest of your app
37. Show me the code!
MqttClient mqttClient = new MqttClient
(
"tcp://m2m.eclipse.org:1883",
MqttClient.generateClientId()
);
mqttClient.setCallback(…);
mqttClient.connect();
mqttClient.subscribe("/teapot24232/#");
// the rest of your app
38. Show me the code!
MqttClient mqttClient = new MqttClient
(
"tcp://m2m.eclipse.org:1883",
MqttClient.generateClientId()
);
mqttClient.setCallback(…);
mqttClient.connect();
mqttClient.subscribe("/teapot24232/#");
// the rest of your app
39. Show me the code!
MqttClient mqttClient = new MqttClient
(
"tcp://m2m.eclipse.org:1883",
MqttClient.generateClientId()
);
mqttClient.setCallback(…);
mqttClient.connect();
mqttClient.subscribe("/teapot24232/#");
// the rest of your app
40. Show me the code!
Callback code:
mqttClient.setCallback(new MqttCallback() {
@Override
public void messageArrived(String topic,
MqttMessage message)
throws Exception {
// process received message
// e.g. display temperature value
}
// ...
});
41. Show me the code!
Callback code:
mqttClient.setCallback(new MqttCallback() {
@Override
public void messageArrived(String topic,
MqttMessage message)
throws Exception {
// process received message
// e.g. display temperature value
}
// ...
});
42. Simple but not Stupid
• QoS
– at most once, at least once, exactly once, …
• “Last will & Testament”
– automatically publish a message when a client
goes offline