Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackson (Myriad)


Published on

OSGi Community Event 2018 Presentation by Bruce Jackson (Myriad)

Abstract: Node-RED is often used as a protyping tool for IoT systems. However, there are also a large number of OSGi components that have already been built to interface to devices, sensors and systems. In this talk I will show how two completely different runtime environments (OSGi and Node-RED) can be combined into a single platform for prototyping (and more) combining the strengths of both languages and systems.

Being able to quickly and simply prototype IoT application is extremely useful, and to this end many people have adopted Node-Red, a Node.js based runtime with extensive support for plugins to interface to various IoT hardware and protocols. However, this requires these services/protocols to be developed in Javascript, and there is already a significant body of code developed in Java/OSGi that it would be desirable to re-use.

The talk will explain how it is possible to:

Create and manage a Node-Red runtime from within an OSGi bundle

Share OSGi components and object into the Node-Red runtime

Interact and build Node-Red flows that exchange data and call methods between Node.js and OSGi
This is obviously useful for the original purpose: prototyping IoT systems, but also demonstrates some interesting techniques for bridging between different languages and runtimes.

Published in: Technology
  • Be the first to comment

Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackson (Myriad)

  1. 1. Prototyping IoT systems with a hybrid OSGi/Node-RED platform Bruce Jackson - CTO
  2. 2. The problem • OSGi is a widely used platform in IoT edge devices ‣ supported by multiple device vendors ‣ many reliable components have been developed for integration into northbound (enterprise) and southbound protocols/devices/etc ‣ not easy to rapidly prototype without writing code ‣ runs on the JVM • Node-red is a ‘code free’ programming environment for IoT that is very popular for prototyping ‣ easy and quick ‣ many components for common southbound protocols/devices/etc ‣ based on Node.js (V8 + Javascript)
  3. 3. OSGi vs Node-red
  4. 4. How to combine these two different solutions? • Both systems have their advantages, but use very different technologies • However - there was a possible solution: ‣ J2V8 - an Eclipsesource project that: “We developed ... as a high performance engine for our multi-platform mobile toolkit tabris.js and it is a great choice for executing JavaScript on Android devices” • An initial test showed that it was possible to use J2V8 to create and run the Node-red environment from Java ‣ turning that into an OSGi bundle wasn’t hard ‣ for our purposes, additional V8 runtime and native bindings needed ‣ bridging code and interfaces to map OSGi components onto the Node-red lifecycle required
  5. 5. How does J2V8 work? Export and import values between domains: • Objects, values Register and call functions across domains: • callback functions from Java to Javascript • execute functions defined in Javascript
  6. 6. Mapping service interfaces to Node-red To allow OSGi components to appear as Node-red nodes, they need to implement a suitable lifecycle service interface - NodeComponent: public void onCreate(String nodeId, JsonNode config); public void onClose(String nodeId); public JsonNode[] onMessage(String nodeId, JsonNode msg); Note also the use of Jackson classes to transfer Javascript objects between domains
  7. 7. Demonstration • A simple node component ‣ 1 in and 1 out ‣ simple configuration for all instances • A more complex example using Paho MQTT client ‣ wrapping an existing library in a NodeComponent ‣ multiple configurations ‣ message creation
  8. 8. Can this work the other way around? • This example shows how OSGi services can be exported into a javascript runtime and work together ‣ although the Javascript runtime is created via OSGi, Node-red is “the boss” ‣ OSGi components play into the Node-red world • Can this work in reverse - with Javascript components in the OSGi world? • Javascript components for OSGi ‣ modularise Javascript runtime as a service (so you can implement via J2V8 or GraalVM) ‣ create component pattern for Javascript
  9. 9. Demonstration • A simple component model for Javascript components in the OSGi world • Javascript component registry ‣ JS components managed via a registry bundle that creates dynamic proxies over the service interface(s) they implement ‣ marshalls calls between environments ‣ exports OSGi services to the Javascript runtime through reflective call creation on Javascript objects ‣ processes bundle metadata
  10. 10. References and contacts OSGi: Node-red: J2V8: Node-red-osgi: Bruce Jackson: