M2M for Java DevelopersMQTT with Eclipse Paho
17-07-2013 -- #democampstuttgartDominik Obermaier -- dc-square GmbH
Dominik Obermaier@dobermai
MQTT Enthusiastloves OSS
passionateArchitect & Maker Co-Founder dc-square
likes Open Source Hardware
Dominik Obermaier@dobermai
MQTT Enthusiastloves OSS
passionateArchitect & Maker Co-Founder dc-square
likes Open Source HardwareK Who not?!?
M2M?
TECHNOLOGY THAT SUPPORTS WIRED
OR WIRELESS COMMUNICATION
BETWEEN DEVICES
Why should
we care?
2010 2015 2020
~6.909.000.000 ~7.302.000.000 ~7.675.000.000
~12.500.000.000 ~25.000.000.000 ~50.000.000.000
[1]Source: http://www.un.org/esa/population/publications/wpp2008/wpp2008_highlights.pdf
[1]
[2]Source: http://share.cisco.com/internet-of-things.html
[2]
“Things” in the Internet
Things?
Which protocol
?
Why MQTT?✓ Simple
✓ Efficient
✓ Publish / Subscribe
✓ Quality of Service Levels
✓ Last Will and Testament
✓ Designed for unreliable networks
Why MQTT?✓ Simple
✓ Efficient
✓ Publish / Subscribe
✓ Quality of Service Levels
✓ Last Will and Testament
✓ Designed for unreliable networksK Wireless? Yep, then it probably is unreliable
Publish / Subscribe
OMG! Sounds like programming in C!
What about Java?
What is Paho?
✓ Scalable Open Source Implementations of M2M standard protocols
✓ Focus on MQTT
✓ Implementations in Java, Javascript, Lua and C
✓ Eclipse Incubator
What is Paho?
✓ Scalable Open Source Implementations of M2M standard protocols
✓ Focus on MQTT
✓ Implementations in Java, Javascript, Lua and C
✓ Eclipse Incubator
KRead: What is Paho at the moment
Code! public void start() throws Exception { final String clientId = "eclipse_stuttgart_sub";
final MqttClient mqttClient = new MqttClient(BROKER_URL, clientId, new MemoryPersistence());
mqttClient.setCallback(new SubscribeCallback(mqttClient));
mqttClient.connect();
mqttClient.subscribe(TOPIC_SUBSCRIPTION, QUALITY_OF_SERVICE_LEVEL);
}
Moar Code!public class SubscribeCallback implements MqttCallback {
@Override public void connectionLost(Throwable cause) {}
@Override public void deliveryComplete(MqttDeliveryToken token) {}
@Override public void messageArrived(MqttTopic topic,
MqttMessage message)throws Exception {
System.out.println("Message arrived. Topic: "
topic.getName() + ", QoS: " + message.getQos() + ", message: " + new String(message.getPayload(), Charset.forName("UTF-8")));
}}
DEMO!
Other Eclipse M2M Projects
Credits✓ Scared Cat Picture by http://www.flickr.com/photos/dat-pics/
✓ Thanks Vincent Le Moign for the awesome Icon Set
✓ Rest of pictures licensed from different people from 500px.com
✓ MQTT Logo by http://www.mqtt.org