KEMBAR78
End-to-end IoT solutions with Java and Eclipse IoT | PDF
End-to-end IoT solutions with 
Java and Eclipse IoT 
Benjamin Cabé 
Eclipse Foundation
Java for IoT? 
9+ million Java developers 
Java 8 & embedded are fun 
Lots of IoT devices running on ARM 
Tooling
Eclipse IoT 
A vivid open-source community 
13* projects across the whole IoT chain 
* and counting...
Your typical IoT solution 
Actuators/Sensors 
+ 
Gateway 
+ 
[ Cloud ] 
+ 
User front-end
IOT
IOT
1. Sensors / Actuators 
• Sense the physical environment 
• Act on it
1. Sensors / Actuators 
• Sense the physical environment 
• Act on it 
Well… that was easy!
1. Sensors / Actuators 
• Manipulate sysfs directly with the File API 
• Use Pi4J (hint: ♥︎) to have full support of 
GPIO/I2C/SPI 
• Use MIDlets with Java ME embedded
1. Sensors / Actuators 
• Manipulate sysfs directly with the File API 
• Use Pi4J (hint: ♥︎) to have full support of 
GPIO/I2C/SPI 
• Use MIDlets with Java ME embedded
Pi4J – http://pi4j.com 
• Complete access to GPIOs/I2C/SPI 
• Very mature codebase, based on WiringPi 
• Support for popular shields (PiFace, 
Gertboard, …) 
• Lots of code samples
Pi4J in action 
GpioController gpio = GpioFactory.getInstance(); 
GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin( 
RaspiPin.GPIO_01, "MyLED", PinState.HIGH); 
Thread.sleep(5000); 
pin.low(); 
Thread.sleep(5000); 
pin.toggle(); 
gpio.shutdown();
2. Gateway 
Network by Nicholas Menghini from The Noun Project
2. Gateway 
Connect 
sensors to the world 
Network by Nicholas Menghini from The Noun Project
2. Gateway 
Connect 
sensors to the world 
Network by Nicholas Menghini from The Noun Project 
Manage the hardware 
and software running 
at the edge
Connect? 
CoAP? 
– « HTTP over UDP » 
– Expose your device as a resource to the Internet 
of Things 
MQTT? 
– Publish/Subscribe model 
– More room for local processing
CoAP with Californium 
CoapServer, CoapResource, CoapExchange 
1. Implement custom resources 
(extend CoapResource) 
2. Add resources to the CoAP server 
3. Start the server
CoAP with Californium 
import static org.eclipse.californium.core.coap.CoAP.ResponseCode.*; // shortcuts 
public class MyResource extends CoapResource { 
@Override 
public void handleGET(CoapExchange exchange) { 
exchange.respond("hello world"); // reply with 2.05 payload (text/plain) 
} 
@Override 
public void handlePOST(CoapExchange exchange) { 
exchange.accept(); // make it a separate response 
if (exchange.getRequestOptions() ...) { 
// do something specific to the request options 
} 
exchange.respond(CREATED); // reply with response code only (shortcut) 
} 
}
MQTT with Paho 
MqttClient c = new MqttClient("tcp://m2m.eclipse.org:1883", 
MqttClient.generateClientId()); 
mqttClient.setCallback(new MqttCallback() { 
@Override 
public void messageArrived(String topic, MqttMessage message) 
throws Exception { 
// process received message 
// ... 
} 
}); 
mqttClient.connect(); 
mqttClient.subscribe("mygateway/#"); 
Read more: https://www.eclipse.org/paho/clients/java/
Manage? 
• Gateway itself 
– wireless modem, firewall, … 
• Applications 
– Install/Uninstall software packages 
– Start/Stop applications 
• Sensors 
– H/W abstraction layer
Eclipse Kura 
Applications 
App 1 App 2 . . . . App n 
Network Configuration 
Network Management Field 
Gateway Basic Services 
Device Abstraction 
OSGi Application Container 
Java VM 
Protocols 
Connectivity and Delivery 
Administration GUI 
Operation & Management 
Linux 
Hardware
OSGi with Concierge 
OSGi? 
– A dynamic component system for Java 
– Many standard services 
• Eventing, configuration management, UPnP, … 
– A target of choice for modular IoT software 
Eclipse Concierge provides low footprint 
implementation (~300-400kb JAR files) 
http://eclipse.org/concierge
Eclipse Kura
Eclipse Kura
Eclipse Kura
Eclipse Kura
Eclipse Kura
Eclipse Kura
Eclipse Kura
Eclipse Kura
Your typical Kura component 
• Uses Modbus, CAN-Bus, etc. built-in device 
abstraction services 
– Or implement your own service
Your typical Kura component (2) 
• Uses Kura built-in transport services to talk 
to the cloud 
– TransportService – « raw » protocol 
– DataService – local storage, auto reconnect 
– CloudService – optimized binary payload, 
advanced device management
Your typical Kura component (3) 
• Implements ConfigurableComponent 
– Enables configuration from the UI 
– … as well as from the cloud
Your typical Kura component (4) 
• Bundled with other bundles/components in 
a deployment package 
– Zip file containing a Manifest & OSGi bundles 
• Can be deployed from Kura Web UI or over 
the air 
Read more: https://wiki.eclipse.org/Kura/Getting_Started
3. Cloud backend 
• Allow virtual point-to-point communication 
between the IoT devices 
• Provide device management capabilities to 
manage fleets of devices on the field
MQTT broker with Moquette 
• Supports QoS 0, 1 and 2 
• Aligned with latest MQTT 3.1.1 specification 
• Ready to be deployed in OSGi containers 
• WebSockets 
• Leverages LMAX Disruptor buffer
MQTT broker with Moquette 
https://code.google.com/p/moquette-mqtt/ 
Very simple to install: 
tar zxf distribution-0.6-bundle-tar.tar.gz 
cd bin 
./moquette.sh 
Note: Moquette has been recently proposed as an 
Eclipse IoT project
4. End-user interaction 
Mobile 
Web 
Other IoT gadgets: wearables, …
Android 
Developing for IoT on Android is dead simple 
– MQTT Android service 
https://www.eclipse.org/paho/clients/android 
– Android Wear: you can easily bridge Google 
Play’s DataLayer to MQTT
Web 
MQTT over Websockets enables direct MQTT 
communication from noBackend web-apps 
– https://www.eclipse.org/paho/clients/js/ 
Eclipse Ponte is also a good way to bridge 
MQTT or CoAP to HTTP 
– https://eclipse.org/ponte
Tooling 
• Java support in the Eclipse IDE from day 1 
• Remote debug 
• Java 8 (lambdas, …) 
• OSGi 
– PDE (Plug-in Development Environment) 
– Remote OSGi with mToolkit
Moaaar Eclipse IoT and Java!
See you soon!
See you soon! 
http://www.meetup.com/Virtual-IoT
Thanks! 
<benjamin@eclipse.org> 
@kartben 
http://iot.eclipse.org
Show me the code! 
Kura 
OSGi runtime 
JVM 
Cloud Service 
DataService 
DataTransportService 
Administration GUI

End-to-end IoT solutions with Java and Eclipse IoT

  • 1.
    End-to-end IoT solutionswith Java and Eclipse IoT Benjamin Cabé Eclipse Foundation
  • 2.
    Java for IoT? 9+ million Java developers Java 8 & embedded are fun Lots of IoT devices running on ARM Tooling
  • 3.
    Eclipse IoT Avivid open-source community 13* projects across the whole IoT chain * and counting...
  • 4.
    Your typical IoTsolution Actuators/Sensors + Gateway + [ Cloud ] + User front-end
  • 7.
  • 9.
  • 10.
    1. Sensors /Actuators • Sense the physical environment • Act on it
  • 11.
    1. Sensors /Actuators • Sense the physical environment • Act on it Well… that was easy!
  • 12.
    1. Sensors /Actuators • Manipulate sysfs directly with the File API • Use Pi4J (hint: ♥︎) to have full support of GPIO/I2C/SPI • Use MIDlets with Java ME embedded
  • 13.
    1. Sensors /Actuators • Manipulate sysfs directly with the File API • Use Pi4J (hint: ♥︎) to have full support of GPIO/I2C/SPI • Use MIDlets with Java ME embedded
  • 14.
    Pi4J – http://pi4j.com • Complete access to GPIOs/I2C/SPI • Very mature codebase, based on WiringPi • Support for popular shields (PiFace, Gertboard, …) • Lots of code samples
  • 15.
    Pi4J in action GpioController gpio = GpioFactory.getInstance(); GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin( RaspiPin.GPIO_01, "MyLED", PinState.HIGH); Thread.sleep(5000); pin.low(); Thread.sleep(5000); pin.toggle(); gpio.shutdown();
  • 16.
    2. Gateway Networkby Nicholas Menghini from The Noun Project
  • 17.
    2. Gateway Connect sensors to the world Network by Nicholas Menghini from The Noun Project
  • 18.
    2. Gateway Connect sensors to the world Network by Nicholas Menghini from The Noun Project Manage the hardware and software running at the edge
  • 19.
    Connect? CoAP? –« HTTP over UDP » – Expose your device as a resource to the Internet of Things MQTT? – Publish/Subscribe model – More room for local processing
  • 20.
    CoAP with Californium CoapServer, CoapResource, CoapExchange 1. Implement custom resources (extend CoapResource) 2. Add resources to the CoAP server 3. Start the server
  • 21.
    CoAP with Californium import static org.eclipse.californium.core.coap.CoAP.ResponseCode.*; // shortcuts public class MyResource extends CoapResource { @Override public void handleGET(CoapExchange exchange) { exchange.respond("hello world"); // reply with 2.05 payload (text/plain) } @Override public void handlePOST(CoapExchange exchange) { exchange.accept(); // make it a separate response if (exchange.getRequestOptions() ...) { // do something specific to the request options } exchange.respond(CREATED); // reply with response code only (shortcut) } }
  • 22.
    MQTT with Paho MqttClient c = new MqttClient("tcp://m2m.eclipse.org:1883", MqttClient.generateClientId()); mqttClient.setCallback(new MqttCallback() { @Override public void messageArrived(String topic, MqttMessage message) throws Exception { // process received message // ... } }); mqttClient.connect(); mqttClient.subscribe("mygateway/#"); Read more: https://www.eclipse.org/paho/clients/java/
  • 23.
    Manage? • Gatewayitself – wireless modem, firewall, … • Applications – Install/Uninstall software packages – Start/Stop applications • Sensors – H/W abstraction layer
  • 24.
    Eclipse Kura Applications App 1 App 2 . . . . App n Network Configuration Network Management Field Gateway Basic Services Device Abstraction OSGi Application Container Java VM Protocols Connectivity and Delivery Administration GUI Operation & Management Linux Hardware
  • 25.
    OSGi with Concierge OSGi? – A dynamic component system for Java – Many standard services • Eventing, configuration management, UPnP, … – A target of choice for modular IoT software Eclipse Concierge provides low footprint implementation (~300-400kb JAR files) http://eclipse.org/concierge
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
    Your typical Kuracomponent • Uses Modbus, CAN-Bus, etc. built-in device abstraction services – Or implement your own service
  • 35.
    Your typical Kuracomponent (2) • Uses Kura built-in transport services to talk to the cloud – TransportService – « raw » protocol – DataService – local storage, auto reconnect – CloudService – optimized binary payload, advanced device management
  • 36.
    Your typical Kuracomponent (3) • Implements ConfigurableComponent – Enables configuration from the UI – … as well as from the cloud
  • 37.
    Your typical Kuracomponent (4) • Bundled with other bundles/components in a deployment package – Zip file containing a Manifest & OSGi bundles • Can be deployed from Kura Web UI or over the air Read more: https://wiki.eclipse.org/Kura/Getting_Started
  • 38.
    3. Cloud backend • Allow virtual point-to-point communication between the IoT devices • Provide device management capabilities to manage fleets of devices on the field
  • 39.
    MQTT broker withMoquette • Supports QoS 0, 1 and 2 • Aligned with latest MQTT 3.1.1 specification • Ready to be deployed in OSGi containers • WebSockets • Leverages LMAX Disruptor buffer
  • 40.
    MQTT broker withMoquette https://code.google.com/p/moquette-mqtt/ Very simple to install: tar zxf distribution-0.6-bundle-tar.tar.gz cd bin ./moquette.sh Note: Moquette has been recently proposed as an Eclipse IoT project
  • 41.
    4. End-user interaction Mobile Web Other IoT gadgets: wearables, …
  • 42.
    Android Developing forIoT on Android is dead simple – MQTT Android service https://www.eclipse.org/paho/clients/android – Android Wear: you can easily bridge Google Play’s DataLayer to MQTT
  • 43.
    Web MQTT overWebsockets enables direct MQTT communication from noBackend web-apps – https://www.eclipse.org/paho/clients/js/ Eclipse Ponte is also a good way to bridge MQTT or CoAP to HTTP – https://eclipse.org/ponte
  • 44.
    Tooling • Javasupport in the Eclipse IDE from day 1 • Remote debug • Java 8 (lambdas, …) • OSGi – PDE (Plug-in Development Environment) – Remote OSGi with mToolkit
  • 45.
  • 46.
  • 47.
    See you soon! http://www.meetup.com/Virtual-IoT
  • 48.
  • 49.
    Show me thecode! Kura OSGi runtime JVM Cloud Service DataService DataTransportService Administration GUI