Blog

JavaScript Bindings for Browser/Node.js and Authentication

We just released a big bunch of new software. The release includes JavaScript Bindings for Node.js and JavaScript Bindings for Browser as well as support for authentication. In order to do this we also have new versions of Brick Daemon, Brick Viewer and the Master Brick Firmware as well as new versions for all Bindings.

JavaScript for Node.js

https://www.tinkerforge.com/static/img/_stuff/logo_nodejs.png

Node.js is a platform that can run server-side JavaScript. With Node.js it is now possible to control Bricks and Bricklets with server-side JavaScript. Reading out the current illuminance from the Ambient Light Bricklet looks as following:

The JavaScript Bindings for Node.js work by the same principle as all of the other Bindings. A TCP/IP connection to the Brick Daemon or the WIFI/Ethernet Extension is established through normal sockets. The functionality to do this is provided by Node.js. JavaScript that is run in the Browser can unfortunately not open normal sockets. Because of this we have separate JavaScript Bindings for Browser.

JavaScript for Browser

https://www.tinkerforge.com/static/img/_stuff/html5_websocket.png

The JavaScript Bindings for the Browser are based on WebSockets. To this end the newest versions of the Brick Daemon as well as the Master Brick include a small web server with support for WebSockets. In the current Master Brick version Websockets only work with the Ethernet Extension. Support for the WIFI Extension will be added later on.

Why is this so awesome that we expended this huge effort? The JavaScript Bindings for the Browser allow to control Bricks and Bricklets directly from every Browser that supports modern web standards. For example: It is possible to get the environmental data from the Starter Kit: Weather Station with a small amount of HTML and JavaScript lines und show them on a web page. This web page can either be loaded from a server or locally. It does not matter where the HTML/JavaScript comes from, since the JavaScript itself is always executed locally.

That means that you can make apps for Android or IPhone that show weather data or that can control the Remote Switch Bricklet with just a few lines of HTML and JavaScript. It is not necessary to write a complicated native app in Java or Objective-C!

Reading out the current illuminance from the Ambient Light Bricklet looks as following:

The JavaScript Bindings for the Browser introduce a big amount of new possibilities in the realm of the Internet of Things. To demonstrate this we will release a new Starter Kit that consists of a complex web application (completely open source) which can control one of our Bricklets.

To counteract possible attacks (over the Internet) through the Browser on our Bricks/Bricklets, we released a possibility to authenticate connections to Bricks/Bricklets in addition to the JavaScript Bindings.

Authentication

By default no access control is performed on the TCP/IP interface of Brick Daemon and the Ethernet/WIFI Extension. If you can connect to it you can control the Bricks and Bricklets. With the new JavaScript Bindings it is now easier for an attacker to get access to the local TCP/IP network (through the Browser), for this we introduced authentication. With authentication enabled only parties that know your authentication secret can control your Bricks and Bricklets.

Authentication can be activated for the Brick Daemon as well as for the Ethernet/WIFI Extension. Additionally we added an authentication tutorial to ease the beginning. To extend an existing program by authentication you usually only have to add one line to your program that sets the authentication secret.

Internally the authentication is done with the HMAC-SHA1 technique. The same technique is for example also used by amazon to authenticate access to Amazon S3.