The De Facto Language Of The Internet Of Things: A JavaScript Primer

The De Facto Language Of The Internet Of Things: A JavaScript Primer

When I was first introduced to hardware programming a while back, there were experts who opposed the use of C/C++ arguing that it concealed the most important aspects of low level hardware. A few years ago JavaScript for IoT suffered the same fate at is was seen by some as misplaced creativity, particularly in automation systems where technology stacks are proprietary. But yet, In analogy to C/C++ for embedded development, technology inadvertently becomes too chaotic to predict or control even for the experts.

Hence we have witnessed the rise of JavaScript to become the de facto programming language of the internet of things. It has evolved to be used for much more than simple client facings apps and today stands at the intersection of distributed, real-time applications and micro-controllers. In this article I will discuss the JavaScript language, its variants, frameworks, tools and data platforms.

Why Javascript?

Working with different devices communicating with different platforms and each other means dealing with issues such as converting the data into formats that the other languages require and so on. Now imagine all of your devices understanding data types in the same way and using a language that much of the Internet already speaks. That's the kind of power that JavaScript holds. The same business logic for an app can be reused in different devices, servers, web apps and APIs.


Here is the crazy part. JavaScript is the most used language of the Internet today and its npm packages that are reusable for solutions on the client, server, and devices has the largest ecosystem of open-source libraries in the world. And because of this ecosystem of APIs most of the developers that have been previously been confined to the web browser are now able to step out into the world of hardware and physical computing. This ubiquity gives JavaScript a unique potential to serve as a gateway for millions of web developers to get started on IoT development.

You may be wondering what really makes JavaScript a perfect fit for IoT? I believe it is mainly because JavaScript is good at event driven applications. These are the types of applications in which each device listens for various events and responds when events occur that it cares about. A great example is Socket.io, a JavaScript module providing real time event based communication across multiple devices. This asynchronous nature of JavaScript function calls and I/O makes it useful for event-driven hardware programming as it allows execution of a number of tasks without needing to wait for each task to be finished before moving to the next one.

Server-side Scripting

Historically JavaScript has been used as a client-side scripting language, performing its tasks solely on a web browser. But in what may be the widest reaching change of recent times in software programming, Ryan Dahl invented Node.js, a framework for running JavaScript on the server. Before then, a typical client server web application architecture would require usage of a server side scripting language like C#, PHP or Java communicating with a client side scripting language like JavaScript. The obvious implication for such a case is the intricacy of using two very different languages to build a single solution, not to mention the requirement of two developers specialising in each of the languages.

Node JS is a server side framework built on Google Chrome's V8 javascript engine, an engine that is nearly as fast as C/C++ . This is a quite popular framework mainly due to its over a hundred thousand packages available via the npm package manager. Its event-driven programming model and support for asynchronous functions makes it well-suited for embedded devices and servers where handling of multiple concurrent connections (up to millions) becomes possible.

Communicating with embedded devices has always been possible but now with Node.js and protocols like MQTT it's easier than ever to build an end-to-end IoT solution. A typical architecture is shown in the diagram below.


Javascript On Hardware

What I find fascinating is that the way to build electronic circuits remains the same, what changes is the use of JavaScript instead of the traditional assembly or C languages to control the processor. Methods for using JavaScript to provide this kind of logic for hardware vary based on where the JavaScript logic itself executes. Using Host-Client method is a way of trying to get around the constraints of some micro-controllers by executing JavaScript on a more powerful computer, exchanging only instructions and data with the embedded hardware acting as a client.

Another method is Embedded JavaScript, here JavaScript logic runs directly on the hardware's micro-controller. As you would expect this method requires the target hardware to be up to the task in terms of resources and optimisation. Last but not least, recent advances in technology have necessitated the use of single board computers like the Raspberry Pi and LattePanda that can run full OS environments and consequently Node.js. This method combines both features of Host-Client and Embedded JavaScript on a single board with the processor being a general purpose one that can simultaneously run other processes.

What I consider the best part about all of this, is new set of projects that have emerged capitalising on the popularity of JavaScript and low cost prototyping hardware allowing developers to use JavaScript skills they already possess to start controlling elements in the physical world. I have put together a non exhaustive list of these tools and platforms below:

Tools

  • Johnny-Five - a JavaScript Robotics & IoT Platform. 
  • NodeRed - a tool for wiring together hardware devices, APIs and onlines services.
  • JerryScript - IoT Javascript Engine for devices with less than 64 KB of RAM and less than 200 KB of flash memory.
  • NodeBots - robots that are controlled by node.js.
  • Favor - A javascript/node.js library to abstract away complex and inconsistent hardware interfaces into a single simple to use API.

Platforms

  • Zetta - An open source platform built on Node.js for creating Internet of Things servers that run across geo-distributed computers and the cloud. 
  • Netbeast - An IoT development platform that empowers developers to easily create and deploy IoT apps
  • ibmiotf - Node.js client is used for simplifying the interacting with the IBM Watson Internet of Things Platform.
  • AWS IoT SDK - allows developers to write JavaScript applications which access the AWS IoT Platform

In conclusion, JavaScript is an open standard that can be implemented using a variety of JavaScript engines. No particular IDE or Operating system. Thus, I'm hopeful that this language will keep the ideals of the open web alive. These are my opinions and I'd love to hear your thoughts and any experiences you've had with JavaScript in the comments section below.

Want the latest best IoT practices and tutorials delivered straight to your inbox?Click here to signup!


Kudzai Manditereza

AI in Manufacturing Podcast Host | Sr. Industry Solutions Advocate @ HiveMQ | Founder @ Industry40.tv

7 年

Thanks Venkatarao

回复
Venkata Rao Gaddam

Embedded Technology Leader | Social Scientist | Motivator | Industrial Automation | Medical | Energy | Automotive | Mobility | IoT | Smart Solutions | AI-ML | Cyber Security | FuSa | Emerging Tech.

7 年

Thank you for sharing this good article. Yes, I agree.

回复

要查看或添加评论,请登录

Kudzai Manditereza的更多文章

社区洞察

其他会员也浏览了