software engineering 2 (02162) · s/http1/readme.html se2 (02162 e17), t05 12 . overview ekkart...
TRANSCRIPT
Software Engineering 2 A practical course in software engineering
Ekkart Kindler
Tutorial 5:
M2M Interaction with openHAB
Ekkart Kindler Task
Based on task from Tutorial 5,
develop an Android App, which triggers a
switch in openHAB when the mobile enters or
exits the proximity of DTU or your home
e.g. using a Mosquito server, MQTT client on
the mobile side, and the openHAB MQTT
bindings
3 SE2 (02162 e17), T05
Ekkart Kindler
Concepts
4 SE2 (02162 e17), T05
Ekkart Kindler Overview
MQTT (MQ Telemetry Transport):
Lightweight pub/sub messaging protocol
MQTT: servers and (Java) clients
openHAB MQTT binding:
Items receiving and sending MQTT messages
openHAB Rules:
Event Condition Action-like rule enigne
openHAB REST API
5 SE2 (02162 e17), T05
Ekkart Kindler MQ Telemetry Transport
Publication and subscription service (pub/sub) for
messages
Messages arranged in hierarchical topics: e.g.
dk.dtu.se2.e17.grA/home1/proximity
Message content is user defined
(technically an array of bytes)
6 SE2 (02162 e17), T05
Ekkart Kindler MQ Telemetry Transport
Clients can publish messages on topics
Topics do not need to be explicitly defined
Clients can subscribe for topics and will be notified
when a message on the topic are published
Wildcards for subscription:
+ for an arbitrary level: e.g. dk.dtu.se2.e17.grA/+/proximity
# for a complete subtree: e.g. dk.dtu.se2.e17.grA/#
7 SE2 (02162 e17), T05
Ekkart Kindler MQTT: server
There are different MQTT servers available:
Mosquitto
HiveMQ
For the task and project you can either install a
server on your VM or use an freely available server
(e.g. http://test.mosquitto.org/)
8 SE2 (02162 e17), T05
Ekkart Kindler MQTT: clients
For programming clients (publish/subscribe), there
are different libraries available
For Java (including Android): e.g. Paho
For messages the client subscribed to, a listener
can be registered. This listener is invoked when a
message of the respective topic is received
9 SE2 (02162 e17), T05
Ekkart Kindler MQTT: openHab binding
OpenHAB comes with an MQTT binding
The MQTT binding allows to configure openHAB
items to send (publish) and receive MQTT
messages (subscribe to)
10 SE2 (02162 e17), T05
Ekkart Kindler MQTT Links
MQTT: http://mqtt.org/
Paho: https://www.eclipse.org/paho/clients/j
ava/
Paho API: http://www.eclipse.org/paho/files/java
doc/index.html
Paho Example (at Git Hub): https://github.com/eclipse/paho.mqtt.j
ava/tree/master/org.eclipse.paho.sampl
e.mqttv3app/src/main/java/org/eclipse/
paho/sample/mqttv3app 11 SE2 (02162 e17), T05
Ekkart Kindler MQTT Links
MQTT openHAB binding: http://docs.openhab.org/addons/binding
s/mqtt1/readme.html
HTTP openHAB binding: http://docs.openhab.org/addons/binding
s/http1/readme.html
12 SE2 (02162 e17), T05
Ekkart Kindler Overview
MQTT (MQ Telemetry Transport):
Lightweight pub/sub messaging protocol
MQTT: servers and (Java) clients
openHAB MQTT binding:
Items receiving and sending MQTT messages
openHAB Rules:
Event Condition Action-like rule enigne
openHAB REST API
13 SE2 (02162 e17), T05
Ekkart Kindler ECA-Rules
ECA (Event Condition Action) rule:
WHEN <event>
IF <condition>
DO <action>
14 SE2 (02162 e17), T05
Ekkart Kindler openHAB rules
openHAB comes with a rule engine for ECA-rules
Rules can be set up in openHAB,
and will then be executed by the openHAB rule
engine
15 SE2 (02162 e17), T05
Ekkart Kindler Example
rule "corLightOn"
when
Item corMotion changed
from OFF to ON or
Item corFrontDoor changed
from CLOSED to OPEN
then
if(corBright.state < 40) {
sendCommand(corLightCeil, ON) }
end
16 SE2 (02162 e17), T05
Ekkart Kindler openHAB Rules
Events can refer to
item-events events
time
state changes of system
state changes of things
Actions formulated in Xtend, a language based on
and interoperable with Java
Actions can
change states
issue commands
use state
17 SE2 (02162 e17), T05
Ekkart Kindler Links
More examples: https://github.com/openhab/openhab1-
addons/wiki/Samples-Rules
https://github.com/openhab/openhab1-
addons/wiki/Rule-example:-Combining-
different-items
Technical information and setup: http://docs.openhab.org/configuration/
rules-dsl.html
18 SE2 (02162 e17), T05
Ekkart Kindler openHAB Rest API
openHAB can also be accessed from other
programs via a REST API
For details, see
http://docs.openhab.org/configuration/restdocs.html
19 SE2 (02162 e17), T05