Case Study / Interviews / Technology / Top Stories /

Fitbit ❤️’s JerryScript: JavaScript Breaks into the Internet of Things

13 Mar 2018 9:53am, by

The recent release of the Fitbit Ionic marked Fitbit’s first true smartwatch. More significant to the JavaScript developer community, though, is the fact that the Ionic was produced and shipped using JerryScript, a lightweight JavaScript engine built to power the Internet of Things (IoT).

The Ionic represents one of the first instances of JerryScript being used in production, not to mention the most ambitious thus far. This alone signifies a big win for the JavaScript community’s work toward getting JavaScript in IoT production environments. Equally exciting though is that, in conjunction with the launch, Fitbit also released its SDK. Thus enabling developers to create not just JavaScript-based custom clock faces but also applications for Fitbit OS, and then submit those apps to the Fitbit App Gallery to share with others. This is the first time that Fitbit has opened up its platform for development to external developers.

JerryScript performs beautifully on resource-constrained devices such as microcontrollers, thanks to its ability to run on devices with less than 64KB of RAM, with less than 200KB ROM space required for the code of the engine. Written in C99 for maximum portability and providing snapshot support for precompiling JavaScript source code to bytecode, JerryScript supports on-device compilation, execution and access to peripherals from JavaScript. A mature C API also makes JerryScript easy to embed in applications.

JerryScript was also one of The JS Foundation’s very first sponsored projects. The New Stack caught up with the foundation’s executive director, Kris Borchers, to hear more about this exciting evolution in the IoT market — one that both incorporates an open source technology into a smart device, and then invites developers for the first time to build on top of the software and contribute apps.

Can you give a quick history of JerryScript?

JerryScript itself was created by Samsung, and they do a lot in IoT across all devices, phones to TVs, so my assumption is they wanted to bring JavaScript to these devices to tap into the dev ecosystem. I was working with Samsung in early 2016, as part of relaunching the jQuery Foundation as the JS Foundation, and they brought up that they had created JerryScript wanted to make it not just a Samsung effort. And so that that is where the foundation comes in — we take ownership of the IP but Samsung developers continue to run it, as we bring in new developers to make the sustainer base broader for the long term. We now have contributors from a number of different orgs: Fitbit, IntelArm.

JerryScript is definitely growing, both in use as well as a community. People are really intrigued by the possibilities it represents.

What were, or still are, barriers for JerryScript’s breakthrough into the smart device production environment?

The missing pieces have been the need to transpile JavaScript to the device firmware, in such a resource-constrained context, as well as implementing JavaScript APIs.

JerryScript first shipped on Pebble smartwatches. Then Pebble was acquired by Fitbit, who definitely started utilizing it immediately to build their own watch. Pebble had built Rocky.js, a framework serving as the bindings between JerryScript and the actual device APIs, and Fitbit still uses a version of that to bind JerryScript to the Ionic. Rocky.js is currently not open source, in part because it’s not clear how beneficial it would be either to the project or the JerryScript ecosystem to open source it because it’s so very Fitbit specific. That said, JerryScript benefits a lot from Fitbit’s active involvement — any new features and pieces that run better with their bindings, they contribute that back to JerryScript.

Other projects out there now working to fill the gap. At Samsung, there is a sort of companion project to JerryScript called IoT.js that they are just sort of starting the ramp up. IoT.js is designed to be an inter-operable service platform in a more generic way than Rocky.js, so you can use it on different devices.  Intel has been working on Zephyr, a scalable real-time operating system for resource-constrained devices, and Zephyr.js, a JavaScript runtime for the Zephyr OS.

So these new runtimes are opening the door for JavaScript to not only move into the IoT space, but in a fully open source way?

Zephyr runs on top of JavaScript and has a number of microcontrollers and development boards. It’s open source, built in turn on JerryScript which is also open source.

The whole stack from OS up to JavaScript can now be open source — Zephyr itself is an RTOS and an open source Linux Foundation project. Intel is the main contributor and consumer of Zephyr, so they built Zephyr.js to be an open source JavaScript runtime for Zephyr. And the underlying engine under Zephy.js is JerryScript.

I’ve been building some things in my office with Zephyr, attempting to build some kind of actually serverless rig. You may see people doing this with Raspberry Pis, but in my opinion that’s cheating. It’s basically a server, right? Try it with microcontrollers maxing out at 1MB ROM and 256K RAM — I am playing around with using a stack of those. It’s fun because it’s all JavaScript!

Tell us more about the Ionic Software Development Kit (SDK)?

The SDK is the app developer-facing piece of the project that links JavaScript to the device; so the SDK is how you interact with that layer. Honestly, for now, Fitbit open sourcing their SDK, I can’t say how much immediate benefit that will have beyond Fitbit. But simply having a JavaScript-powered SDK will hopefully get devs engaging with Fitbit devices, get more feedback on what developers would want to see. My ultimate hope is it’s a gateway to get that middle layer get more involved in the IoT JavaScript sphere. Which redounds in both directions: companies choosing to build IoT in JavaScript will find more developers already knowledgeable and contributing. Then, if using JavaScript under the hood, instead of building some proprietary thing they start contributing instead to open source projects that already exist.

It’s a double-edged sword. We have so much fast innovation within the ecosystem driven by people just creating, which is awesome but at the same time also how you end up with 100 best date-picker jQuery plugins of last week. Everybody kind of doing the same thing and repeating themselves. We don’t want to stifle creativity because every now and then something truly new and useful emerges, but it makes it hard for people to figure out ‘What should I be using right now?’ So if there are places, especially in an emerging space like this, where you can potentially replace closed source with something already existing in open source — it’s worth the search.

So: Logical next steps for JavaScript enlarging its presence in the IoT space?

JavaScript in IoT is definitely a growing trend, but it gets a little hard to talk about JavaScript across all IoT because it’s such a generic term by now — IoT is literally everywhere. JavaScript has been pretty well adopted at the edge. You see this in Node-RED, a lightweight runtime for node.js that has been around for awhile, a well-adopted tool for wiring together hardware and APIs and web services. It’s fairly mature and integrated into a number of things.

What we are seeing now is people getting down into the microcontroller small device level in a serious way. JavaScript in IoT really began in the hobbyist and maker space, building robots and fun light shows. But now we are seeing it break into more industrial applications of IoT. Opto 22 is a manufacturer of controllers for industrial machines and processes, they have a microcontroller edge device using NodeRED to aggregate and direct data flows from this device.

Moving from the maker world to enterprise applications is where we started to see people taking JavaScript more seriously. Pebble was quite a bit smaller (in terms of market reach); with Fitbit, we are now seeing at the individual device level JavaScript being taken seriously on a wide production scale. The opportunities are endless as open source tooling continues to grow and span any and all use cases.

The Linux Foundation, which manages the JS Foundation, is a sponsor of The New Stack.

A digest of the week’s most important stories & analyses.

View / Add Comments

Please stay on topic and be respectful of others. Review our Terms of Use.