+ All Categories
Home > Documents > Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart...

Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart...

Date post: 19-Jun-2020
Category:
Upload: others
View: 6 times
Download: 0 times
Share this document with a friend
19
Software Engineering 2 A practical course in software engineering Ekkart Kindler
Transcript
Page 1: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

Software Engineering 2 A practical course in software engineering

Ekkart Kindler

Page 2: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

Tutorial 5:

M2M Interaction with openHAB

Page 3: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

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

Page 4: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

Ekkart Kindler

Concepts

4 SE2 (02162 e17), T05

Page 5: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

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

Page 6: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

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

Page 7: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

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

Page 8: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

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

Page 9: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

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

Page 10: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

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

Page 11: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

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

Page 13: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

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

Page 14: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

Ekkart Kindler ECA-Rules

ECA (Event Condition Action) rule:

WHEN <event>

IF <condition>

DO <action>

14 SE2 (02162 e17), T05

Page 15: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

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

Page 16: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

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

Page 17: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

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

Page 18: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

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

Page 19: Software Engineering 2 (02162) · s/http1/readme.html SE2 (02162 e17), T05 12 . Overview Ekkart Kindler MQTT (MQ Telemetry Transport): Lightweight pub/sub messaging protocol MQTT:

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


Recommended