Thursday, August 6, 2015

A FirefoxOS powered internet of things

I've been meaning to write this post for a long time now. It is about the topic of a series of talks I gave at the beginning of the summer. The last one was at #devtalks was also recorded so you can enjoy it here + slides.

A few days ago, one of my favourite kickstarter projects, Matchstick, announced that they were unable to complete the project, and refunding everyone's pledges. I am very saddened by this decision, considering this was a
project I really believed in. The founders suggest that this occurred because it was unable to implement DRM in time for a release. Why they couldn't ship it without DRM and update it later, or just forget the DRM and deliver what they promised is a question they haven't answered. This of course hasn't stopped Panasonic from launching their FirefoxOS powered TV.

However, this post isn't about DRM, or about Matchstick. It's about the potential of Firefox OS powered devices.

Firefox OS has had a bumpy ride during the past few years. It only started as a concept in 2011, so you could say it's still pretty early for the project. The first version of the OS came out in 2013, but in the mobile industry 2 years is a lifetime (the lifetime of your average phone at least).

As both user and developer, my impression of Firefox OS phones is that they're pretty nice. They're not missing any relevant features, performance is quite good, and its hackability is amazing. The only reason everyone is not using it is that almost everyone is using something else. Inertia is very difficult to overcome.

Still, hackability is an immensely powerful feature, and it makes Firefox OS great for prototyping new devices. That prototyping can turn into a marketable device very easily, and it allows you to quickly ship new features on top of an existing platform.

This is where JanOS - the main topic in my talks - comes in. It's a Firefox OS distro, with no apps. The entire app management that Firefox OS does is a burden for you when you want to have full control of the device. So what Jan OS gives you is a system app, with all of the permissions, none of the restrictions, and a blank canvas on which to implement whatever functionality you want.

A few weeks ago I had the great opportunity of meeting the man behind JanOS, +Jan Jongboom, at a recent Mozilla meeting. You can watch his talk about the project here.

On top of freeing you from all of the restrictions imposed by the operating system (app permissions, resource management), JanOS also provides some cool APIs you might like in some circumstances, such as raw access to the filesystem, or executing binary applications (non-JavaScript) using a JS API. What more could you want?

I am curious to see how many devices running Firefox OS come out in the following years. But I'm more interested in what people can do with it. It's awesome for wearable devices, things with a limited amount of RAM, things with sensors that you feel should be webby. It's awesome for building a surveillance camera, or a phone answering machine, or a GPS tracker using an old phone you just had lying around.

I am also excited about Google's Weave protocol (part of project Brillo). It's essentially a JSON based protocol you can use to communicate between IoT devices. The project is just getting started, but the fact that it's webby is really great. Only good things can come of that. And it means that you can use Firefox OS to build devices that play together well with Google's ecosystem.

There's a lot to be said about IoT, Firefox OS, JanOS and everything else in that group, but words are cheap. I've been meaning for a while to build an answering machine/call forwarder, but hadn't had the time to. I'll try to do so in the next 2 months and put the code on github. That should be fun!

Saturday, May 23, 2015

DevTools, Firefox OS and wearable devices

Recently, I had the opportunity to give talks at two amazing events. I will try to summarize the experience, as well as share the same content here.

The first event was Mobile:Next, where I had a bunch of fun. For some reason, my laptop wouldn't work with the projector there, so I had to use some other laptop. It was both good and bad. For one, I was able to setup everything I needed to give a technical demo, in just 10 minutes. That really shows you the ease with which you can get into developing for Firefox OS.
The atmosphere was really really nice. People were quite friendly, and I feel I managed to get my point across to all people.

The most recent event was at BucharestJS. Given that these people were either JS developers, or people interested in JS, it felt like preaching to the choir. These people did JS better than I ever could, and still I was able to show them a bunch of new things about DevTools and even JavaScript ( most of them didn't know about ASM.js ) Here too I had a bit of a hiccup with the demo, where the Firefox OS Simulator failed to load. (My fault. Apparently I can't use it on release Firefox, after using it on Nightly).

So, let's get into the content:

First off, I talked about Firefox OS, and the way it works. I didn't get too much into it. The real stars of Firefox OS are the WebAPIs. These are the things developers care about. How do I do things?

The demo is a really great way of showing people how it works. Moreover, a bunch of people have no idea of the power that lies in the DevTools. On of the great features is Valence which allows you to debug other browsers, such as Chrome on Desktop, or Safari on iOS. (this is something most developers didn't know)

After the demo I went into how the apps work. As opposed to iOS and Android, apps for Firefox OS are web apps, so the really powerful feature is that you don't have to download an app from an app store, to be able to use it. Web pages and Apps would work largely the same way.
Of course, those don't always work when we don't have an internet connection. For that we need packaged apps. These are basically packaged web pages, that are downloaded so you can use offline, whether it's games, dictionaries, camera apps, etc.
One special group of these is privileged apps, which are packaged apps with certain permissions, so they can use various more powerful APIs.
The last group is certified apps, which are apps developed by Mozilla or partners. Certified APIs can only be used by developer apps through WebActivities

The best thing about Firefox OS apps is that it doesn't pin you to a certain app ecosystem. You don't have to distribute your app through the Marketplace. You can just host it on your own web server, and even sell your app, without any involvement from Mozilla, without the user having to take any risk or check a "allow apps from untrusted sources" box.

However, one of the incentives to distribute your app through the Marketplace is that you can use Firefox as a runtime for your apps. If you go to the marketplace on Android, or desktop, the app will be downloaded and packaged as a native app (Android, Windows, whatever), and then you can use it just as you would a native app. It will still be using Firefox as an engine, but it will lack Firefox's UI, and you will be able to uninstall it just as you would a normal application.

The next part of my presentation was largely based on Jan Jongboom's project, JanOS. It's a great project, as it solves one of the major hurdles to starting your own wearable device project - Cost! If you just do the obvious thing, and go for RaspberryPi, but if you need a screen, a battery, wires and a couple of sensors, it can easily cost you upwards of 100$.
Meanwhile, the cheapest FirefoxOS phone packs all those components, and more, and costs only 25$.
Moreover, if you strip it down to the essentials, its a bit smaller than a credit card, making it great for a wearable device prototype.

The really cool thing about this is JanOS, which is a stripped down version of FirefoxOS, without all of the apps, and UI, just a simple web page and all the JavaScript bindings and premissions you might need.

There are several simple things you can do with it right after you flash it, such as the doorbell demo. It involves the phone's proximity sensor, and a Bluetooth speaker. I didn't have a speaker, to I set it to vibrate when you triggered the proximity sensor, then I disconnected it from the computer, and passed it into the audience to play with it.
Of course, there's a bunch of cooler stuff you can do with it. You could use it as a security camera, or as an answering machine, or as an alarm, or as a webcam.
There are a lot of possibilities!

And JanOS comes with a bit of goodies on the side - 2 APIs that allow you to run native commands on the phone, and to directly access the filesystem.

Recently a bunch of companies have emerged that build their devices on Firefox OS. Such as Matchstick, Panasonic's UHD TVs running Firefox OS, or even something like the Monohm Runcible. The reason to use it is that it's a great platform, which requires very few resources, and which you can easily adapt to your own needs.

This was basically my talk. I also had a few slides prepared to address questions from the audience. One of these was for the performance question - Asm.JS addresses performance very well. The way this works, is the emscripten compiler transforms your C/C++ code, into a very optimized subset of JavaScript. This allows the JavaScript engine to run it really really fast, while browsers that don't support ASM.js will still be able to run it, albeit at a slower speed. This page lists a bunch of great demos - Dead trigger proved to be a hit with the audience.

I also included a few tips for the audience interested in porting existing apps to Firefox OS. Mainly, if you already have a web application, or an app built with Apache Cordova/Phone Gap, your job should be super easy. If your app is very Android/iOS specific, you might a difficult road ahead of you.

These were a couple of great events. I hope I managed to reach the audience, and clarify all that they needed to start developing for the web.


If you read this blog post and have any questions about Mozilla, Firefox OS, the web or anything... comment, or send me a tweet or email. I'll do my best to anwer.