Talk from IoT World in Santa Clara, May 12, 2016. How to make IoT objects interoperable and adapble by adding JavaScript. Introduces XS6 open source JavaScript engine optimized for embedded development. Hat tip to Hallelujah the Hills for the epigrams.
3. • Engineer and entrepreneur
• Focus on the objects we own (aka “the client”)
• Closest to the user, biggest opportunity for impact
• Hand crafted software optimized for size and speed
• Tools for developers and users
• Working for interoperability of data and devices
Aboutme
@phoddie
6. • Every trade show presentation begins by defining it
• We don’t know
• The user doesn’t know
• Well, they do…. once you show them your product working
• They like the object
• They just want a different behavior…
…for their life, their home, their car.
For them.
IoTisshroudedinmystery
@phoddie
8. • We’ve seen the future
• Seen it in movies
• Binge watched it on TV
• Read about it in books
• We all have a sense of what connected future should be
• Just can’t explain it beyond lights automatically turning on
when you arrive home
WhatIoTshoulddoisobvious
@phoddie
9. • We expect it
• Our devices should be able to communicate with the cloud and
each other
• That’s the premise of the “I” in IoT
• Great products that work well together
• Too many products consider interoperability an
“interesting idea for a future update”
Interoperability
@phoddie
16. @phoddie
Toomuch.Toosoon.
• It isn’t obvious what we want to do in the big picture
• Trying to create “underpinning” standards
• Not necessary for this market – investment level is
already unbelievably high
• Leading to bad standards
• Too much functionality
• Allow for too many possible futures
• Too big and complex to be practical
17. @phoddie
NeedtimetofigureoutIoT
• Experiments to discover what is possible
• Experience to know what works in the real world
• Too early for new standards
• Plenty of existing standards to build on
20. PopularFrameworksAren’tIoTReady
• Browser-based solutions: Too heavy for IoT devices
• Node.js: Server solution being shoehorned into the
embedded space
• Qt: Designed for desktop, too much of a catch-all of
features
• Lua: Less popular than assembly and COBOL, so difficult
to find talent and no significant ecosystem
@phoddie
26. JavaScriptforEmbedded/IoT
@phoddie
• JSON built in – de facto data format of the
web
• Exceptionally portable – OS independent
• Helps eliminate memory leaks and
fragmentation so devices can run for a very
long time – garbage collector
27. JavaScript 2015 (aka ES6) is first truly major enhancement
to the language.
More than 400 individual changes including:
• Classes – familiar tool for inheritance
• Promises – clean, consistent asynchronous operation
• Modules – reusable code libraries
• ArrayBuffer – work with binary data
JavaScript6thEdition–featuresforIoT
@phoddie
28. @phoddie
High level programming languages
on embedded systems
Relatedly, writing software to control drones, vending
machines, and dishwashers has become as easy as
spinning up a website. Fast, efficient processors … are
turning JavaScript into a popular embedded
programming language—unthinkable less than a
decade ago.
29. Securefoundation
@phoddie
• Sandbox
• Core language provides no access to network, files, hardware, screen,
audio, etc.
• Scripts can only see and do what the system designer chooses to
provide
• Secure – many classes of security flaws in native code are non-existent
• Uninitialized memory
• Stack overflow
• Buffer overruns
• Mal-formed data injection
31. AddingES6toyourproduct
• Just a few steps to get the basics working
• Get XS6 from GitHub
• Build it with your product
• Entirely ANSI C – likely builds as-is
• All host OS dependencies in three files xs6Host.c,
xs6Platform.h, and xs6Platform.6
• Update as needed for your host OS / RTOS
@phoddie
34. • Two key constraints to address
• CPU performance
• Single core
• ARM Cortex – thumb instructions only
• 200 MHz or less is common
• Memory
• RAM is limited, Flash storage is much less of an issue
XS6–JavaScriptoptimizedforembedded
@phoddie
35. • No JIT
• Requires much more memory
• Significantly increases complexity of JavaScript engine
• Takes time to manage
• Performance critical functions can be coded in C directly
• Even faster
• No security risk as native code is installed “at the factory”
XS6–JavaScriptoptimizedforembedded
@phoddie
36. • Memory efficient strings
• JavaScript defines strings as Unicode 16, requires 2 bytes
per character
• XS6 uses UTF-8, which uses 1 byte for most common
characters
• Tuned garbage collector
• Small memory size allows use of simple garbage collector,
fast, single threaded, and compact
XS6–JavaScriptoptimizedforembedded
@phoddie
37. • Precompiled byte code
• JavaScript can be compiled on desktop
• Eliminates parse and code generation on device
• Execute-in-place for byte code
• JavaScript byte code stored in flash storage can be executed
directly
• Eliminates JavaScript code from RAM
XS6–JavaScriptoptimizedforembedded
@phoddie
38. • “Threaded” dispatch
• Byte code instructions are dispatched using a computed
goto, fastest way to implement byte code interpreter
• JavaScript module unloading
• Extends ES6 to allow code modules loaded at runtime to be
unloaded when no longer in use
XS6–JavaScriptoptimizedforembedded
@phoddie
39. Goingdeeper
• JavaScript is also great for building the product
• App logic
• Communication
• Network protocols
• Hardware
@phoddie
40. WhyuseJavaScripttobuildyourproduct?
• Get it working faster
• Iterate incredibly fast
• Leverage code and techniques
developed by other JS developers
• Hardware independent; easy to re-use
in your next generation
• Re-use JavaScript code with Node.js cloud
service, mobile apps, and web pages
• Much easier to find JavaScript programmers
to work on your project @phoddie
44. • People know the behaviors they want from their devices
• Many people can code in one way or another
• Let them
• That’s how the computer and mobile grew
• That’s where the ideas come from
• Traditional embedded development doesn’t scale
• JavaScript is proven for growing developer communities
Makescriptablethings
@phoddie
45. • You can’t implement every feature for every market
• Really.
• Apple, Microsoft, Google, and Cisco can’t.
• You can’t either.
• Individual products seldom win
• Products that connect to a larger ecosystem have more
leverage
Goodbusiness
@phoddie
46. • Gives customers a stake in the product
• Gives customers a sense of being in control of their products
• Allows products to address features and connect to cloud
services the manufacturer chooses not to support
• Extends product life
• Long after manufacturer stops issuing updates, the market
can continue to enhance
Goodforcustomers
@phoddie
47.
48. • Open source is used to build closed devices
• Doesn’t give the customer the ability to change the behavior of
their objects
• Doesn’t give ecosystem the ability to enhance the object
• Doesn’t ensure interoperability in any way
Opensourceisn’tenough
@phoddie
50. • One word: JavaScript
• The flexibility to change the behavior of the objects in our world
• The foundation to discover the potential of IoT
• The only practical way to achieve the interoperability we dream
about
HowwefigureoutIoT
@phoddie
51. • Kinoma – selected slides and images
• Hallelujah the Hills – intriguing quotes
• Playground Global – room to play
• IoTracks and Param Singh – invitation to speak
Acknowledgements
@phoddie