How to publish IoT data/services from your own IoT environment (Node-Red)

41
Tutorial showing how to publish your own IoT services/data using the O-MI/O-DF reference implementation 1

Transcript of How to publish IoT data/services from your own IoT environment (Node-Red)

Tutorial showing how to publish your own IoT services/data using the

O-MI/O-DF reference implementation

1

© bIoTope Consortium 2

Tutorial showing how to publish your own IoT services/data using the O-MI/O-DF reference implementation

Internal Agent External Agents

Node-Red Shell scripts …

Available Tutorials

Scala (see GitHub)

Java (see GitHub)

https://github.com/AaltoAsia/O-MI

bIoTope 3

Prerequisites1 computer Windows ou Linux/MAC with the following tools installed:

• the O-MI reference implementation: https://github.com/AaltoAsia/O-MI ✦ direct URL: https://github.com/AaltoAsia/O-MI/releases/tag/0.6.4 (choose “o-mi-node-0.6.4.zip”)

=> Note: Java 1.8 is required.

• Node-red: http://nodered.org/docs/getting-started/installation ✴ Many video tutorial can be found online, e.g:

IoT Services - Node-RED Installation guide on Windows on Youtube

• Node-red libraries: ✦ Philips Hue: http://flows.nodered.org/node/node-red-contrib-hueplus ✦ O-MI node: https://github.com/skubler/Node-Red-OMI ✦ O-DF node: https://github.com/skubler/Node-Red-ODF

Build the O-DF Service Tree related to the Philips Hue light using the O-MI

reference implementation

4

Build the O-DF Service Tree related to the Philips Hue light using the O-MI reference implementation

5

1. Start your O-MI node

To start the O-MI ref. implem., run the corresponding startup script from the bin directory for your OS:• Windows: double-click on the file o-mi-node.bat in the bin/ directory• Unix and Mac: open a terminal, and run the file o-mi-node in the bin/ directory (Might be needed to add

the Write access to the directory: chmod +x)

Exemple for Mac

6

2. Launch the reference implementation in your favorite browser at the following URL: http://localhost:8080/html/webclient/index.html

Build the O-DF Service Tree related to the Philips Hue light using the O-MI reference implementation

NOTE: In this demo, everything is done locally. If you want to use the O-MI write request on remote O-MI reference implementations, you will need to specify/add the write access rights to a configuration file in the O-MI reference implementation (See Appendix A)

7

3. Add the O-DF structure related to the Philips Hue light

The following O-DF structure will be created by following the guidelines given in the next slides:

the postal address of the Object named “JeremysHouse”the Object related to the Smart Light (Philips Hue Light in our case)

the state of the light’s brightness (Philips Hue Light’s property)value: "Specify the brightness of the light” (for human understanding)Two Metadata: range of accepted Values & additional Documentation

the state of the light (on or off)value: "Switch on/off the light"

Build the O-DF Service Tree related to the Philips Hue light using the O-MI reference implementation

8

3. Add the O-DF structure related to the Philips Hue Light A. Add the Object JeremysHouse to the root Objects. To do so:

• Right-click on Objects —> Add an Object

Build the O-DF Service Tree related to the Philips Hue light using the O-MI reference implementation

9

3. Add the O-DF structure related to the Philips Hue Light A. Add the Object JeremysHouse in the root Objects. To do so:

• Right-click on Objects —> Add an Object• Add a name for the Object: JeremysHouse

Build the O-DF Service Tree related to the Philips Hue light using the O-MI reference implementation

10

3. Add the O-DF structure related to the Philips Hue Light A. Add the Object JeremysHouse in the root Objects. B. Add an infoItem Location in the Object JeremysHouse. To do so:

• Right-click on JeremysHouse —> Add an InfoItem

Build the O-DF Service Tree related to the Philips Hue light using the O-MI reference implementation

11

3. Add the O-DF structure related to the Philips Hue Light A. Add the Object JeremysHouse in the root ObjectsB. Add an infoItem Location in the Object JeremysHouse. To do so:

• Right-click on JeremysHouse —> Add an InfoItem• Fill out the form with a Name (here, Location), and corresponding Value (e.g., your own postal address), choose a

type (e.g., select the type string) and click on Add to request

Build the O-DF Service Tree related to the Philips Hue light using the O-MI reference implementation

12

3. Add the O-DF structure related to the Philips Hue Light A. Add the Object JeremysHouse in the root ObjectsB. Add an infoItem Location in the Object JeremysHouse. To do so:

• Right-click on JeremysHouse —> Add an InfoItem• Fill out the form with a Name (here, Location), the value (e.g., your own postal address), choose a type (e.g., let the

type string) and click on Add to request• Save your new infoItem by sending a Write request: select the new infoItem Location and the O-MI operation Write,

click Send

Build the O-DF Service Tree related to the Philips Hue light using the O-MI reference implementation

13

3. Add the O-DF structure related to the Philips Hue Light A. Add the Object JeremysHouse in the root ObjectsB. Add an infoItem Location in the Object JeremysHouse. C. Add the Object SmartLight (related to the product Philips Hue Light) in the Object JeremysHouse. To do so:

• Right-click on JeremysHouse —> Add an Object

Build the O-DF Service Tree related to the Philips Hue light using the O-MI reference implementation

14

3. Add the O-DF structure related to the Philips Hue Light A. Add the Object JeremysHouse in the root ObjectsB. Add an infoItem Location in the Object JeremysHouse. C. Add the Object SmartLight (related to the product Philips Hue Light) in the Object JeremysHouse. To do so:

• Right-click on JeremysHouse —> Add an Object• Add a name for the Object: SmartLight

Build the O-DF Service Tree related to the Philips Hue light using the O-MI reference implementation

15

3. Add the O-DF structure related to the Philips Hue Light A. Add the Object JeremysHouse in the root ObjectsB. Add an infoItem Location in the Object JeremysHouse. C. Add the Object SmartLight (related to the product Philips Hue Light) in the Object JeremysHouseD. Add an infoItem On in the SmartLight object. To do so:

• Right-click on SmartLight —> Add an InfoItem

Build the O-DF Service Tree related to the Philips Hue light using the O-MI reference implementation

16

3. Add the O-DF structure related to the Philips Hue Light A. Add the Object JeremysHouse in the root ObjectsB. Add an infoItem Location in the Object JeremysHouse. C. Add the Object SmartLight (related to the product Philips Hue Light) in the Object JeremysHouseD. Add an infoItem On in the SmartLight object. To do so:

• Right-click on SmartLight —> Add an InfoItem • Fill out the form with a Name (here, On), the value (e.g., false), choose a type (boolean) and click on Add to request

Build the O-DF Service Tree related to the Philips Hue light using the O-MI reference implementation

17

Build the O-DF Service Tree related to the Philips Hue light using the O-MI reference implementation

3. Add the O-DF structure related to the Philips Hue Light A. Add the Object JeremysHouse in the root ObjectsB. Add an infoItem Location in the Object JeremysHouse. C. Add the Object SmartLight (related to the product Philips Hue Light) in the Object JeremysHouseD. Add an infoItem On in the SmartLight object. To do so:

• Right-click on SmartLight —> Add an InfoItem • Fill out the form with a Name (here, On), the value (e.g., false), choose a type (e.g., boolean) and click on Add to

request• Save your new infoItem by sending a Write request: select the new infoItem Location and the O-MI operation Write,

click on Send

18

3. Add the O-DF structure related to the Philips Hue Light A. Add the Object JeremysHouse in the root ObjectsB. Add an infoItem Location in the Object JeremysHouse. C. Add the Object SmartLight (related to the product Philips Hue Light) in the Object JeremysHouseD. Add an infoItem On in the SmartLight objectE. Add an infoItem Brightness in the SmartLight object. To do so:

• Right-click on SmartLight —> Add an InfoItem

Build the O-DF Service Tree related to the Philips Hue light using the O-MI reference implementation

19

Build the O-DF Service Tree related to the Philips Hue light using the O-MI reference implementation

3. Add the O-DF structure related to the Philips Hue Light A. Add the Object JeremysHouse in the root ObjectsB. Add an infoItem Location in the Object JeremysHouse. C. Add the Object SmartLight (related to the product Philips Hue Light) in the Object JeremysHouseD. Add an infoItem On in the SmartLight objectE. Add an infoItem Brightness in the SmartLight object. To do so:

• Right-click on SmartLight —> Add an InfoItem • Fill out the form with a Name (here, Brightness), the value (e.g., 0), choose a type (e.g., Integer), add two metadata

(click on + button) with the following properties: Metadata1: - name: range; - Value: [0 ; 255]; - Type: string Metadata2: - name: documentation; - Value: https://en.wikipedia.org/wiki/Brightness; - Type: stringand click on Add to request

20

3. Add the O-DF structure related to the Philips Hue Light A. Add the Object JeremysHouse in the root ObjectsB. Add an infoItem Location in the Object JeremysHouse. C. Add the Object SmartLight (related to the product Philips Hue Light) in the Object JeremysHouseD. Add an infoItem On in the SmartLight objectE. Add an infoItem Brightness in the SmartLight object. To do so:

• Right-click on SmartLight —> Add an InfoItem • Fill out the form with a Name (here, Brightness), the value (e.g., 0), choose a type (e.g., Integer), add two metadata

(click on + button) with the following properties: Metadata1: - name: range; - Value: [0 ; 255]; - Type: string Metadata2: - name: documentation; - Value: https://en.wikipedia.org/wiki/Brightness; - Type: stringand click on Add to request

• Save your new infoItem by sending a write request: select the new infoItem Brightness, the description, the metadata and the O-MI operation Write, click on Send

Now, you have created your Service Tree, but you still need to push real-time data from your vendor-specific platform (Philips Hue light in our case) to the corresponding InfoItems. This is done and described in the following slides using Node-Red.

Build the O-DF Service Tree related to the Philips Hue light using the O-MI reference implementation

Creation of the “External agent” for updating and listening the state of the smart light

21

Creation of the “External agent” for updating and listening the state of the smart light

22

1. Write/Update the OMI node (i.e., InfoItem) with the current state of the light

Hue API

O-MI/O-DF

23

1. Write the current state of the light in the OMI node A. Add the proprietary Philips Hue node to get the state of the light

Hue API

Get Hue State

Creation of the “External agent” for updating and listening the state of the smart light

24

1. Write the current state of the light in the OMI node A. Add the proprietary Philips Hue node to get the state of the light B. Configure it with the Philips Bridge properties

Hue API

Get Hue State(Configuration)

Creation of the “External agent” for updating and listening the state of the smart light

25

1. Write the current state of the light in the OMI node A. Add the proprietary Philips Hue node to get the state of the light B. Configure it with the Philips Bridge propertiesC. Monitor each property (On & Brightness) of the light

Hue API

Get Hue State(JSON parsing)

Creation of the “External agent” for updating and listening the state of the smart light

26

1. Write the current state of the light in the OMI node A. Add the proprietary Philips Hue node to get the state of the light B. Configure it with the Philips Bridge propertiesC. Monitor each property’s value (On & Brightness) of the lightD. Write the value in the appropriate infoItem in the O-MI node

Hue API

O-MI/O-DF Send (Write req.) the Hue Stateto the corresponding InfoItem

Creation of the “External agent” for updating and listening the state of the smart light

27

1. Write the current state of the light in the OMI node A. Add the proprietary Philips Hue node to get the state of the light B. Configure it with the Philips Bridge propertiesC. Monitor each property’s value (On & Brightness) of the lightD. Write the value in the appropriate infoItem in the O-MI nodeE. Repeat this action periodically (e.g., every minute)

Hue API

O-MI/O-DF

Creation of the “External agent” for updating and listening the state of the smart light

28

1. Write the current state of the light in the OMI node A. Add the proprietary Philips Hue node to get the state of the light B. Configure it with the Philips Bridge propertiesC. Monitor each property’s value (On & Brightness) of the lightD. Write the value in the appropriate infoItem in the O-MI nodeE. Repeat this action periodically (e.g., every minute)F. Print the result of the flow (debug mode)

Hue API

O-MI/O-DFEvery time the state of the Philips Hue Light is “crawled/checked”, the O-MI ref. implem., or the corresponding InfoItems to be more precise (named “Brightness” & “ON” in our O-DF Service Tree), will be updated accordingly!

Creation of the “External agent” for updating and listening the state of the smart light

2. "Listen" if any change occurs on the OMI ref. implem. so as to propagate it up to the Smart Hue light

29

O-MI/O-DF

Hue API

Sylvain sends an O-MI Write request to turn Smart bulb OFF!NOTE: Sylvain is not aware of and doesn’t have to care about what Smart Bulb technology Jérémy is using as backend platform (the Write message will remain the same!!)

External actor(Sylvain)

Our Node-Red agent will update the state as requested (if Sylvain has the

sufficient access rights)

Jéré

my’

s Io

T en

viro

nmen

t

Creation of the “External agent” for updating and listening the state of the smart light

1. "Listen" the modification of the OMI node to modify the state of the light A. Read/Subscribe to the object SmartLight

30

O-MI/O-DF

Creation of the “External agent” for updating and listening the state of the smart light

Jéré

my’

s Io

T en

viro

nmen

t

1. "Listen" the modification of the OMI node to modify the state of the light A. Read/Subscribe to the object SmartLightB. Parse the O-DF payload (output is an array with [the_name_of_the_parent_object, the_name_of_the_infoItem, value])

31

O-MI/O-DF

Creation of the “External agent” for updating and listening the state of the smart light

Jéré

my’

s Io

T en

viro

nmen

t

1. "Listen" the modification of the OMI node to modify the state of the light A. Read/Subscribe to the object SmartLightB. Parse the O-DF payload (output is an array with [the_name_of_the_parent_object, the_name_of_the_infoItem, value])C. Isolate the value of each infoItem and create the message to the light

32

msg.omi=msg.payload;

var len=msg.omi.length; diff1=0; diff2=0;

for(i=0;i<len;i++){ if (msg.omi[i][1] == "Brightness"){ msg.bri1 = msg.omi[i][2]; diff1 = 1; } else {

diff1 = 0; } if (msg.omi[i][1] == "On"){ if (msg.omi[i][2] == "true"){ val=true; } else { val=false; } msg.on1 = val; diff2 = 1; } else { diff2 = 0; } }

if (diff1 == 1 || diff2 == 1){ console.log("test"); msg.payload={ "on": msg.on1, "bri": msg.bri1 };

return msg; }

Hue API

O-MI/O-DF

Creation of the “External agent” for updating and listening the state of the smart light

Jéré

my’

s Io

T en

viro

nmen

t

1. "Listen" the modification of the OMI node to modify the state of the light A. Read/Subscribe to the object SmartLightB. Parse the O-DF payload (output is an array with [the_name_of_the_parent_object, the_name_of_the_infoItem, value])C. Isolate the value of each infoItem and create the message to the lightD. Add the proprietary Philips Hue node to set the state of the light

33

Hue API

O-MI/O-DF

Creation of the “External agent” for updating and listening the state of the smart light

Jéré

my’

s Io

T en

viro

nmen

t

1. "Listen" the modification of the OMI node to modify the state of the light A. Read/Subscribe to the object SmartLightB. Parse the O-DF payload (output is an array with [the_name_of_the_parent_object, the_name_of_the_infoItem, value])C. Isolate the value of each infoItem and create the message to the lightD. Add the proprietary Philips Hue node to set the state of the light E. Repeat this action periodically (e.g., every 10 secondes) —> to note: when web socket will be better managed in the ref.

implem. and node-red… the Timestamp will be substituted by the “Event-Based subscription” interface supported by the O-MI node, thus enabling to be notified every time an InfoItem ifs written/updated on the o-mi ref. implem.

34

Hue API

O-MI/O-DF

Creation of the “External agent” for updating and listening the state of the smart light

Jéré

my’

s Io

T en

viro

nmen

t

1. "Listen" the modification of the OMI node to modify the state of the light A. Read/Subscribe to the object SmartLightB. Parse the O-DF payload (output is an array with [the_name_of_the_parent_object, the_name_of_the_infoItem, value])C. Isolate the value of each infoItem and create the message to the lightD. Add the proprietary Philips Hue node to set the state of the light E. Repeat this action periodically (e.g., every 10 secondes) —> to note: when web socket will be better managed in the ref.

implem. and node-red… the Timestamp will be substituted by the “Event-Based subscription” interface supported by the O-MI node, thus enabling to be notified every time an InfoItem ifs written/updated on the o-mi ref. implem.

F. Print the result of the flow (debug mode)

35

Hue API

O-MI/O-DF

Creation of the “External agent” for updating and listening the state of the smart light

Jéré

my’

s Io

T en

viro

nmen

t

Hue API

O-MI/O-DF

That’s all… Just deploy and play with your ref. implem. ;-)

36

O-MI/O-DF

Jéré

my’

s Io

T en

viro

nmen

t

37

Standardised Service Description & Messaging Interfaces (O-MI/O-DF)

Smart City

●!

●✇ ●●

●!

●✇ ●● ●!

"●●

ABot

tle

Bank

●● ●●

###

Shopping Center

$$$

%&&%

'❍

●!"!!!

!School

%&&

%●School Bus

●●

Manufacturer

●✇ ●●

●✇ ●●

●✇ ●●

✚●● ●●

H

●●●

ALandfill site

Information-as-a-Service

O-MI n

ode U

RL

1

bIoTope Service Marketplace: IoTBnB

$

http://85.171.192.185

Join the bIoTope ecosystem and Share amazing services &

IoT data with our members

© bIoTope Consortium 38

BIOTOPE H2020 R&I GRANT: N° 688203

Tutorial created by: • Dr. Jérémy ROBERT • Dr. Sylvain KUBLER

© bIoTope Consortium 39

APPENDIX A

40

1. To be written A. To be written

41

Specify/add the write access rights to a configuration file in the O-MI reference implementation