OSGi Community Event 2018 Presentation by Christer Larsson (Makewave)
Abstract: OSGi was originally designed for Smart Homes and Residential Gateways almost 20 years ago.
This talk will present how the OSGi specifications have evolved over the years, and how you today, in 2018, design an OSGi based Smart Home System.
A real world use case of a Swedish Smart Home start-up company will be used to illustrate different design principles and how OSGi remains as relevant today as it was when it started.
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Christer Larsson (Makewave)
1. Christer Larsson
Makewave AB
It was 20 years ago today
OSGi and Smart Home
Christer Larsson
CEO Makewave
VP EMEA OSGI Alliance
2. Christer Larsson
Makewave AB
It was 20 years ago today…
• Quick introduction to Makewave
• Going back 20 years in time
• Animus Home - a Smart Home system designed
today
• A few words on Remote Management
• Summary / Lessons learnt
2
4. Christer Larsson
Makewave AB
4
Company Spotlight
• Makewave is one of the leading OSGi middleware companies
• Been involved in the business since the inception of OSGi in 1999
• Developed the first commercial platform for Ericsson’s e-box in –
1998/2000
• Makewave is working actively in the OSGi Alliance. CEO Christer
Larsson is the appointedVP EMEA
• Located in Göteborg, Sweden.
• We are the company maintaining Knopflerfish OSGi
• We also make Ubicore - a remote management system for
edge devices
5. Christer Larsson
Makewave AB
It was 20 years ago today…
• Quick introduction to Makewave
• Going back 20 years in time
• Animus Home - a Smart Home system designed
today
• A few words on Remote Management
• Summary / Lessons learnt
5
6. Christer Larsson
Makewave AB
It was 20 years ago today…
• OSGi Alliance dates back 20 years (almost)
• Residential Gateways where the roots of OSGi
• Open Service Gateway initiative
• But work started even earlier…
6
7. Christer Larsson
Makewave AB
Opportunity & Concepts
Home applications
722 October 2018
ISP
eBox
Printer HDD
PC
Web TV
Internet
service
providers
SNMP
~AC
Web server
Mini-PC
Object database
Back up
Intelligent agent
LAN-hub
PC technology
“Black-box” without moving parts
Serviceable via network by ISP
Internal or external modem (RS232)
Firewall
E3 protocol
One per home
Internet terminal
Local intelligence
Maximum price 500€
Distribution via ISP
High volume product
Sensors
Internet
Other
1997-10-18
8. Christer Larsson
Makewave AB
Market Outlook 1997 - a number of trends
illustrate the emergence of ’Things That Talk’
8
Growth of sensors and microsystems
– The market for sensor-based microsystems is expected to grow from 1.3 billion units in 1996 to
5.4 billion in 2002 (source: CEA/LETI)
Growth of embedded Web systems
– Over 20 million non-PC devices could be accessing the Internet by year 2000, and the software
market for embedded Internet is expected to grow to $5.6 billion by year 2001 (source:
Spyglass; Wessels, Arnold and Hendersen)
Emergence of the smart home
– The average number of microprocessors per household will increase from 45 today to over 200
by year 2000 (source: emWare)
Growing connectivity
– Modem penetration of U.S households will grow from 16% in 1996 to 25% in 1999 (source: e-
land)
9. Christer Larsson
Makewave AB
9
The e-box system as defined in 98/99
Service Providers Service Operator End User
Service
Provider 1
Cameras
Telephone
Equipment
White
Goods
Metric
Equipment Sensors
Display
Units
Switches
Service
Provider 2
Service
Provider 3
Service
Provider 4
10. Christer Larsson
Makewave AB
Service Gateway Interface Specification
1022 October 2018
Client
Service Gateway
Wide Area
Network
Local Network
Service Provider
Framework
Service 1 Service 2 DeviceClient
Device
Management
System
Standardized
API
11. Christer Larsson
Makewave AB
Service Gateway Middleware
• Middleware providing remote controlled service platform
• Life cycle management of service bundles
• load
• start
• stop
• resume
• update
• remove
• Communication with:
• framework, other services, local net, clients
• Lives on top of Java Runtime Environment
• Isolates services from OS
11
12. Christer Larsson
Makewave AB
e-box 101
1222 October 2018
Housing: 167x183x42 mm.
Wall mount and desktop use
CPU: 33/66/100 MHz 486
Memory: 8-32M DRAM, 4-16M
FLASH, 128k SRAM, 2k
EEPROM
3W power consumption
(internal 15W PSU)
115 kbps serial port
Integrated powerline modem
Modular network
configuration:
– Slot 1: PCMCIA*, V.90 modem, ISDN
– Slot 2: Ethernet, Bluetooth, USB
* The PCMCIA slot is type III for GSM, DECT,
ISDN etc.
13. Christer Larsson
Makewave AB
13
The e-box did set the original
requirements
• In the e-box system we wanted a:
• CPE Platform
• Open standards based
• Load software / services / applications
dynamically
• Multiple Service Providers can co-exist
• Integrity between applications, no sneaking
• Remotely managed
• And the result was OSGi R1
14. Christer Larsson
Makewave AB
14
But the timing was not right!
• Too early for the market in –99
• Vision was great, but nor technology, nor business
model was mature enough !
• Compared to –99 things have changed:
• BOM for a R/G is now far, far less
• Wireless devices / sensors
• Broadband penetration.
15. Christer Larsson
Makewave AB
15
The e-box system as defined in 98/99
Service Providers Service Operator End User
Service
Provider 1
Cameras
Telephone
Equipment
White
Goods
Metric
Equipment Sensors
Display
Units
Switches
Service
Provider 2
Service
Provider 3
Service
Provider 4
16. Christer Larsson
Makewave AB
16
This concept is used quite successfully...
Service Providers Service Operator End User
Service
Provider 1
Cameras
Telephone
EquipmentNavigation
Metric
Equipment Sensors
Display
Units
Switches
Service
Provider 2
Service
Provider 3
Service
Provider 4
17. Christer Larsson
Makewave AB
Payment models - app store purchases / subscriptions
1722 October 2018
Service
Provider 1
Service
Provider 2
e-box
Operator
Invoices Invoices
Payment Payment
Customer
interface
Operation &
maintenance
InvoicesPayment
Service delivery
End User
Service delivery
18. Christer Larsson
Makewave AB
…as well as “in-app” purchases
1822 October 2018
Service
Provider 1
Service
Provider 2
e-box
Operator
Invoices Invoices
Payment Payment
Operation &
maintenance Service delivery
End User
Service delivery
Customer
interface
Customer
interface
InvoicesInvoices
PaymentPayment
19. Christer Larsson
Makewave AB
Code Style - OSGi R1
• Use services directly, manage and handle everything “by
hand”. Frequent use of service listeners
• Works, but low level and often error prone to handle
all the dynamics
19
public void serviceChanged(ServiceEvent evt)
{
if (evt.getServiceReference() == logSR
&& evt.getType() == ServiceEvent.UNREGISTERING) {
ungetLogService();
}
}
20. Christer Larsson
Makewave AB
Code Style - OSGi R2
• ServiceTracker is added
• Takes care of tracking services you depend upon
20
httpTracker = new ServiceTracker(bc, HttpService.class.getName(), null) {
public Object addingService(final ServiceReference sr)
{
return register(sr);
}
public void removedService(final ServiceReference sr,
final Object service)
{
unregister((HttpService) service);
}
};
httpTracker.open();
21. Christer Larsson
Makewave AB
Code Style - OSGi R4 and later
• SCR / Declarative Services
• Declarative model - almost no need to track services
21
@Component(
immediate = true,
service = { RF433TransmitterService.class, DevicePackage.class,
EventHandler.class },
property = {
EventConstants.EVENT_TOPIC+"="+RF433MessageEvent.RF433_EVENT_OUT_TOPIC
+ "/*" }
)
public class RF433Package extends DevicePackageImpl implements
RF433TransmitterService, EventHandler {….
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy =
ReferencePolicy.DYNAMIC)
public void setRF433ReceiverService(RF433ReceiverService rs) {
// logger.info("Receiver detected: " + rs.getProtocolName());
22. Christer Larsson
Makewave AB
End of history lesson…
• So, how do you design a architecture for a Smart
Home / Residential Gateway solution today?
• Well, you often end up with something like this…
22
23. Christer Larsson
Makewave AB
OSGi Smart Home Solution
2322 October 2018
Client
Service Gateway
Wide Area
Network
Local Network
Service Provider
Framework
Service 1 Service 2 DeviceClient
Device
Management
System
Standardized
API
24. Christer Larsson
Makewave AB
OSGi Smart Home Solution
2322 October 2018
Client
Service Gateway
Wide Area
Network
Local Network
Service Provider
Framework
DeviceClient
Device
Management
System
Standardized
API
Cloud
Declarative
Services
Declarative
Services
“App”
25. Christer Larsson
Makewave AB
Some things have changed
• Device Technologies
• Wired => Wireless
• Price of devices & gateways
• Costly => less costly / cheap
• Smart Phones and Apps
• an “App” is a must for end-user experience
• Cloud
• that fluffy thing outside your home that replaced the WAN
24
26. Christer Larsson
Makewave AB
It was 20 years ago today…
• Quick introduction to Makewave
• Going back 20 years in time
• Animus Home - a Smart Home system
designed today
• A few words on Remote Management
• Summary / Lessons learnt
25
27. Christer Larsson
Makewave AB
Animushome - Smart Home
• A Swedish start-up, crowdfunded
• Has developed a Smart Home solution
• Animus Heart, linux based, Knopflerfish R6 - OSGi
R6 Core and Compendium
• Wifi, Bluetooth, Zwave, RF433 Mhz
• http://www.animushome.com
26
28. Christer Larsson
Makewave AB
Animushome - System Overview
27
Animus Heart
Animus
Cloud
Animus
Heart
Animus
Heart
Other
Clouds
Animus
Heart
Skill
S Skill
Local Device(s)
Zwave, RF433, Bluetooth
Broadcast of “skills”
Animus Heart provides
Skills Animus Heart provides
registered in other clouds
(Alexa / Google Home)
Smart Home App
Local web
access
Management
S1S2 S1S1
29. Christer Larsson
Makewave AB
Animus Heart - OSGi based gw
• OSGi R6 - Core and Compendium (Knopflerfish)
• Package - bundle - like a “device driver”.
• Interacts with devices, set/get values.
• Implements OSGi DAL - Device Abstraction Layer
• Provides additional API:s / wrappers, e.g.
• Bluetooth, Zwave, RF433 Mhz
• hApp - bundle - provides business logic
• typically including a UI / and functions for the end user
• Designed using Declarative Services
28
33. Christer Larsson
Makewave AB
It was 20 years ago today…
• Quick introduction to Makewave
• Going back 20 years in time
• Animus Home - a Smart Home system designed
today
• A few words on Remote Management
• Summary / Lessons learnt
32
34. Security Co.
End User
Management Servers.
Managed and Maintained by a
Gateway Operator
ACME Telecom
My Services
Energy Consumption
Welcome
Anders
My Apartment
Mode
- Home
- Away
- Night
Alarm Service
OK. Nothing to report
health Monitoring
Heart Rate 56
Home Devices
Camera 1
Camera 2
TV
Power Meter
OK
OK
Off
OK
Power Co
Ubicore
Service Centers
Operated by 3rd party service providers
JVM / OS / HW
OSGi Framework
Home
Security
Energy
Mgmt
Health
Monitoring
A
g
e
n
t
L
o
g
C
o
n
f
H
T
T
P
P
r
e
f
s
UP
n
P
Z
i
g
B
e
Energy
Mgmt
Makewave’s Edge and
Enterprise Cloud servers
OSGi inside
Knopflerfish Pro
Hospital
Home
Security
Health
Monitoring
The OSGi App Store
Powered by Makewave’s OSGi Technology
35. Christer Larsson
Makewave AB
Ubicore Design Principles
• Ubicore is designed for managing embedded edge
devices
• With an end-user logged on / interacting via a display
• Without any end-user, just a black box out in the field
• The Ubicore server knows exactly which bundles are
installed & started in which edge device.
• Ubicore pre-resolves and defines what needs to be
installed => software packages for deployment are
created
• can be tested, verified and signed before deploying.
34
36. Christer Larsson
Makewave AB
Ubicore is in control
35
Edge Device with OSGi Container
Protocol
Handler
framework-1.2.3
DMT
Ubicore
Server
Sends a recipe & receives
status updates
•Ubicore send a recipe - you need these bundles
and bundle configurations.
•The mgmt agent will take the recipe and make
sure the platform takes its medicine.
•The agent then report back to status to
Ubicore
./Bundles
framework-1.2.3
event-4.3.2
log-6.7.7 (U)
Ubicore
Mgmt
Agent
event-4.3.2
log-6.7.6
framework.update(log)
37. Christer Larsson
Makewave AB
Ubicore Concepts
• OSGi Firmware
• The framework and a core set of bundles, including the
management agent.
• The functions needed to make a platform “remotely manageable”
• Service Applications
• A group of bundles that typically is performing some logical
function or service
• A gateway or user subscribes to Service Applications.
• Pre-resolve on the server
• Signing firmwares / bundles / configurations
36
38. Christer Larsson
Makewave AB
Ubicore Concepts
• Management Agent on the edge device
• Is responsible for all management operations.
• It’s the field agent for Ubicore
• Local edge device bundle cache (repo)
• It is normally the management agent that initiates and establish
the connection.Typically at fixed intervals, e.g. every N minutes.
• There is a Management Agent API
• Edge device business logic may want to take decisions on when
to upgrade / downgrade
• Local installation / local management
37
39. Christer Larsson
Makewave AB
OSGi Firmware
Gateway
Ubicore
38
OSGi
Firmware
v.1.0.0
OSGi Firmware
v.1.0.0
<firmware>
<version=”1.0.0”>
<components>
<component id=”framework-6.1.1.jar”/>
<component id=”log-1.2.3.jar”/>
<component id=”eventadmin-1.1.0.jar”/>
<component id=”cm-2.0.0.jar”/>
......
The OSGi firmware makes the gateway
manageable by Ubicore and typically also
provides a basic set of OSGi services, e.g. Log,
Event Admin, CM, DS.
The OSGi Firmware is a core set of
bundles and bundle configurations.
Packaged as single JAR.
log-1.2.3
eventadmin-1.1.0 cm-2.0.0
framework-6.1.1
40. Gateway
OSGi
Firmware
v.1.0.1
Christer Larsson
Makewave AB
OSGi Firmware Update
Ubicore
39
OSGi
Firmware
v.1.0.0
<firmware>
<version=”1.0.0”>
<components>
<component id=”framework-6.1.1.jar”/>
<component id=”log-1.2.3.jar”/>
<component id=”eventadmin-1.1.0.jar”/>
<component id=”cm-2.0.0.jar”/>
......
Firmware Update Operation. Switches to a new
version. New / changed components are
downloaded, installed/updated and started.
Restarts the framework and/or the JVM if required.
New version of the firmware.
Components may have been added,
removed or updated.
Only deltas will be provisioned.
cm-2.0.1
framework-6.1.2
<firmware>
<version=”1.0.1”>
<components>
<component id=”framework-6.1.2.jar”/>
<component id=”log-1.2.3.jar”/>
<component id=”eventadmin-1.1.0.jar”/>
<component id=”cm-2.0.1.jar”/>
...... OSGi Firmware
v.1.0.0
OSGi Firmware
v.1.0.1
Provisioning
41. Christer Larsson
Makewave AB
OSGi Firmware Update
• Firmware versions can be INSTALLED, RUNNING and FAILED.
• When starting a new OSGi firmware it will be marked as
FAILED if any of the bundle start methods throw an exception.
In this case the mgmt agent will automatically revert to the
previous “good” version.
• There is always a basic initial version, e.g. a “Factory Settings”
versions.
• Any number of firmware versions may be kept but typically
there is: Factory Settings, PreviousVersion, CurrentVersion.
• The bundles are stored locally in a bundle cache and there is
only one JAR-file for each version of the bundles
40
42. Gateway
OSGi Firmware
v.1.0.0
Christer Larsson
Makewave AB
Service Applications
• A Service Application is a grouping of bundles
• Typically grouped as a functional unit / logical unit, e.g. an “app”
• The Service Applications are subscribed to by a user or the edge
device itself.
• The Service Application run on top of the firmware.
41
Service App XYX
v.1.0.0
bundleA-1.2.3
bundleB-1.1.0
bundleC-2.0.0 cm-2.0.0 framework-6.1.1
cm-2.0.0
cm-2.0.0
Service App XYX
v.1.0.0
bundleA-1.2.3
bundleB-1.1.0
bundleC-2.0.0
43. Christer Larsson
Makewave AB
Service Applications
• A bundle can exist in multiple Service Applications so
Service Applications can “overlap”
• There will be only one instance of the bundle
installed / started
42
Service App XYZ
v.1.0.0
bundleX-1.2.3
bundleZ-1.1.0bundleY-2.0.0
Service App ABC
v.2.0.0
bundleA-1.2.3
bundleB-1.1.0 bundleZ-1.1.0
44. Christer Larsson
Makewave AB
It was 20 years ago today…
• Quick introduction to Makewave
• Going back 20 years in time
• Animus Home - a Smart Home system designed
today
• A few words on Remote Management
• Summary / Lessons learnt
43
45. Christer Larsson
Makewave AB
OSGi is (still) an excellent model for
embedded device architectures
• The fundamental principles of OSGi are still, after 20
years, an excellent design.
• OSGi guides you / pushes you in the right direction on
modularity and a service oriented architecture.
• Many of the predictions and assumptions on Smart
Homes and “Things that talk” were absolutely right,
only way too early in 1999/2000
• A bundle developed for OSGi R1 still runs perfectly on
R7, 20 years later.
44
46. Christer Larsson
Makewave AB
Today - Use Declarative Services
• Base the design on Declarative Services
• It will force the developers to design well defined,
services performing well defined tasks.
• Even if there are hundred of services, by keeping
them well defined and task specific, large and
complex systems become manageable.
• But bare in mind the declarative and dynamic
behaviour. If not careful, component or service jo-
jos can be created.
45
47. Christer Larsson
Makewave AB
And yes, there are still problems
• OSGi is a very powerful tool. However, it can also
be your worst enemy.
• In the hands of the mad and / or incompetent
developer really bad designs can be made.
• Be aware of dynamics & multi-threading
• Using 3rd party libraries can be troublesome.
• Many claim they support OSGi. Often they do, but
sometimes they don’t.
• Debugging DS is somewhat of a challenge
46
48. Christer Larsson
Makewave AB
Thank you!
47
Christer Larsson CEO Makewave www.makewave.com
VP EMEA OSGi www.osgi.org
Knopflerfish OSGi www.knopflerfish.org
It was 20 years ago today
OSGi taught the world to modularity obey
They’ve been going in and out of style
But they’re guaranteed to still compile