JavaScript Beyond the Web

Patrick Catanzariti

In the span of only a few years, JavaScript has fast become the most valuable language I’ve ever worked with. I know I’m not alone on this one. I remember the early days on Netscape Navigator when I was overjoyed to see I could change the text on my webpage by asking the user a question in a prompt dialog box. Like all great technology moments, it truly did feel like magic.

Since then, JavaScript has grown and matured to so much more than I could have ever imagined in the early scripting days. We can now code powerful web applications, mobile apps, Windows 8 apps and even entire servers with JavaScript.

The true versatility of this language has hit what I believe is its most exciting moment yet -­ it now can be used to control and monitor your mobile phone, the lights in your house, robotics, augmented reality with Google Glass, your hand and finger movements with Leap Motion and so much more.

In this article, I’d like to give a high level overview of some of the technology enabling the “Internet of Things” that JavaScript developers can start working with today.

If you’re a JavaScript developer and want to get tinkering in the world of Internet connected things using your existing skill set, there are more options than most developers realise. There is so much opportunity for innovation and an equally enticing opportunity for some entertaining tech driven pranks …

Ninja Blocks

ninjablocks
Photo credit: Ninja Blocks Inc

What are they?

Ninja Blocks are small computer devices that let you invoke and respond to devices in the real world all from the cloud. It works by communicating to devices over either the 433Mhz band (a common set of frequencies for remote controlled devices) or via USB connection. It has a JavaScript API allowing you to connect it up to your own Node server and tap into the Ninja Blocks platform.

What could you do with it?

New combinations of the technology are being tinkered with every day, a few examples of what is possible include:

  • Turn on your lights via a tweet on Twitter
  • Fire a Nerf gun remotely and take a photo of what ensues on a connected webcam
  • Turn on your air conditioning any time you get home and the temperature is above a certain threshold
  • Switch the colour of your lights to certain colours if your phone receives texts from certain people

Arduino

What is it?

Arduino boards are single­board microcontrollers that control electronics using an open­source platform. Luckily for JavaScript developers, there are several JavaScript APIs that have been developed to interface with the Arduino platform. The main ones I’ve come across are:

  • Johnny Five, an open source JS Arduino framework
  • node­-arduino, a Node package for working with Arduinos
  • Noduino, another Node and JS framework for toggling basic Arduinos controls

What could you do with it?

A few examples of Arduino projects I’ve seen are:

Raspberry Pi

What is it?

The Raspberry Pi is a small computer that you can plug into your television to do everything from play HD video to editing spreadsheets. It is a fully functional computer at a low price that is open for tinkering! For all of you JavaScript lovers out there, Pijs.io allows you to write embedded applications for the Pi in JavaScript using their cloud platform for communication. It is also possible to install Node on a Raspberry Pi, using it as a server to relay any information you’d like from devices you connect to your Pi.

What could you do with it?

  • A home automation system running on Node, MongoDB, HTML5 and web sockets
  • One group made a miniature version of the house from the Pixar movie “Up” that flew over Paris and posted photos on Instagram using a Pi
  • You could even get a “Pi Crust” which allows you to turn your Raspberry Pi into a Ninja Block

Tessel

Tessel
Photo credit: Technical Machine

What is it?

Tessel is a wifi enabled microcontroller allowing you to add it to a hardware device so it can communicate with the web and join the Internet of Things. It aims to help make the transition to hardware as simple as possible for software developers by using the same workflow and skillset that JavaScript developers already have. It doesn’t just have a JavaScript API as an option, JavaScript is its central focus making it all the more exciting for us JavaScript developers. Sadly, it isn’t available just yet but you can pre­order now for the 2014 release.

What could you do with it?

  • Develop your own gadget that can be remotely controlled via the web
  • Bring new functionality to an existing hardware device by adding in Tessel modules like an accelerometer, RFID, GPS and more

Espruino

espruino
Photo credit Pur3 Ltd

What is it?

Espruino a JavaScript interpreter for microcontrollers. Espruino boards are like the Tessel, however the Espruino board is a much cheaper board with only 8KB of RAM and doesn’t have preset modules such as the accelerometer available to plug and play (you’d need to find and attach some of that yourself).

What could you do with it?

  • Similar usage to Tessel, interact with motors, lights and so forth, however the Espruino board may be better for more battery efficient smaller projects

on{X}

What is it?

on{X} is an Android application that allows you to control your device and respond to events like incoming text messages, GPS location, battery life and more via a JavaScript API. You can add and remove rules you’ve made remotely and they’ll install to your device over the web. It’s one of my favourite Android apps to date. Truly a coder’s paradise.

What could you do with it?

  • Launch foursquare when you stay in one location for longer than 20 minutes
  • Text your partner when your phone is about to run out of battery
  • Have your phone suggest for you to bring an umbrella if the weather forecast thinks it’ll be rainy that day

Leap Motion

What is it?

Leap Motion is an incredible little device that can sense and respond to your hand, finger and pen motions. Connect it up to your computer via USB and Leap Motion apps will have the ability to respond to your movements. Definitely one of those devices that makes you feel like you’ve stumbled into the future. The best part is that they’ve created a JavaScript API for it ready for you to play around with.

What could you do with it?

  • Create a drawing app that lets the user draw with their fingers in the air
  • Add the ability for users to spin an object on your webpage to see it in more detail, resize it and so forth using natural hand movements
  • Develop games like Fruit Ninja that can be controlled via hand and finger swipes

WearScript

What is it?

WearScript is a library that lets you run JavaScript code on Google Glass. Their goal is to develop an open ecosystem of apps for Google Glass that doesn’t rely on Google’s own app store and is quick and easy for developers to share their creations around. A really neat idea.

What could you do with it?

  • Develop Google Glass apps that respond to your location and display information
  • Create voice activated simple apps that make every day life just that little bit more Internet enabled

In conclusion

The message here to JavaScript developers around the world is simple. That “Internet of Things” you keep reading about is possible right now with the skill set you already have. Get out there and make something indistinguishable from magic.

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • Pedro Heliodoro.

    Please don’t forget that many of these apps run on top of node.js which is a packaged compilation of the V8 engine by Google.

    • Anonymous

      The progress JavaScript has made in leaps and bounds thanks to Google and its efforts has been a great one :) The guys at Node too deserve huge commendation for making something that’s fast becoming a driver for so much innovation… in this case bringing the Internet of Things to a new dev community that I hope are ready to embrace and innovate even further!

  • Anonymous

    Nice article!!

  • Anonymous

    Don’t forget the NodeCopter (nodecopter.com) for controlling flying robots.

  • Anonymous

    Really amazing technologies