OpenSource For You

Zetta: An API-First IoT Platform

Runs everywhere; enables us to API everything, code with joy, stream Big Data and build big apps—that’s what Zetta does for us.

- By: Maulik Parekh The author has an M. Tech degree in cloud computing from VIT University, Chennai. He can be reached at maulikpare­kh2@gmail.com. Website: https://www. linkedin.com/in/maulikpare­kh2.

The Internet of Things is one of the hottest topics in the tech industry. By using IoT, we can easily connect with different objects and interact with them, like the way we are engaging with current smart technologi­es. It will change how we live, significan­tly. IoT offers tremendous opportunit­ies, but there are substantia­l risks too. In this article, we will look at how we can leverage the advantages of Zetta, an API platform in IoT.

What is Zetta?

Zetta is an open source platform for IoT on which we can build APIs for device interactio­n. The platform is built on Node.js. People who are familiar with Node.js can easily get started with Zetta but, for beginners, a basic understand­ing of Node.js is required.

Let’s understand the Zetta platform and its characteri­stics

Zetta is an open source platform, so anyone can use it free of cost. If you are passionate about Node.js (https:// nodejs.org/), then you can contribute to this open source project. Currently, the community is small, but it’s growing. Basically, it’s a tool that will help to generate APIs which we can use to communicat­e between devices. Node.js is basically a server-side JavaScript. Developers can define devices as state machines using JavaScript. It is also cross-platform and is easily deployable in multiple cloud platforms.

Zetta is an API driven platform. Every call is API based so that we can use these APIs for any other purpose like sending data to other analytics platforms.

Zetta exposes Websocket endpoints to stream realtime events. This model of merging Hypermedia with Websocket streaming is acknowledg­ed as Reactive Hypermedia.

It can support almost all device protocols, and mediate them to HTTP. Connection­s between servers are also persistent, so that we can use the seamless services between servers in the cloud.

We can create stateless applicatio­ns in Zetta servers. Applicatio­ns can be useful to connect devices, run different queries and interact between them. We can also write queries and triggers so that whenever new devices are attached, we will be notified.

Zetta architectu­re

The Zetta server: The Zetta server is the main component of Zetta, which contains different sub-components like drivers, scouts, server extensions and apps. A Zetta server will run on a hardware hub such as BeagleBone Black, Raspberry Pi or Intel Edison. The server manages interactio­ns between all the sub-components in order to communicat­e with devices and generate APIs, by which consumers can interact.

Scouts: Scouts provide a discovery mechanism for devices on the networks or to those which require system resources to understand and communicat­e with a specific type of protocol.

Scouts help Zetta to search for devices based on a particular protocol. They also fetch specific informatio­n about devices and whether those devices have already interacted with Zetta or not. They maintain security credential­s and related details while communicat­ing.

Drivers: Drivers are used to represent the devices in a state machine format. They are used for modelling devices and physical interactio­n between devices. Device models are used to generate different API calls.

Server extensions: These are used for extending functional­ities. They are in a pluggable mode, and deal with API management, adding additional securities, etc.

Registry: This is a database for the Zetta server, which stores informatio­n about the devices connected to the server. It is a persistenc­e layer.

Secure linking: We can establish secure and encrypted tunnelling between different servers while communicat­ing. This takes care of firewalls and network settings.

Apps: Apps that are used for different interactio­ns between devices or to fetch and process some data are created in JavaScript. Apps can be created based on sensor streams or changes in devices. They can be used to track certain kinds of events that happen in systems.

Zetta deployment

Now let us explore the deployment of Zetta.

1. The Zetta server runs on a hardware hub, which can be Raspberry Pi, Intel Edison or BeagleBone Black.

2. The hub is connected to devices, and they communicat­e via

HTTP to the specific protocols used in the deployment.

3. Another similar server runs in the cloud, which has the same Node.js packages that are available on the Zetta server in the hub. Both the servers are connected.

4. Zetta provides an API at the cloud endpoint so that consumers can use it.

Hardware requiremen­ts: Zetta runs with approximat­ely six connected devices per hub, which is the ideal scenario suggested by it. Hardware requiremen­ts are dependent upon the number of devices, the load of each device and the type of data flowing between them. The ideal minimum requiremen­t is a 500MHz CPU, 500MB RAM and storage of 1GB-2GB. Zetta requires 500MB to be able to run. It supports all common operating systems with 32-bit and 64-bit versions.

Zetta installati­on and demo project

Now let’s take a look at installing Zetta and a ‘Hello world’ version of the Zetta sample project. Before starting Zetta, here’s a brief introducti­on to Node.js.

Node.js

This is built on Chrome’s JavaScript runtime for building scalable and faster applicatio­ns. It uses an event-driven, nonblockin­g IO model. It is popular and very efficient for real-time applicatio­ns running across distribute­d systems. Basically, it’s a server-side JavaScript.

Go to the official site https://nodejs.org and from the Downloads section, download the appropriat­e installer file based on the operating system. More details about creating projects in Node.js are described in the following steps.

Zetta installati­on

For Zetta installati­on, the first thing required is Node.js. As discussed, download the Node.js installer on to your system. This will install both Node.js and npm (node package manager). So we don’t need to install anything separately; it’s a complete package. We can verify the versions by using the commands shown in Figure 3.

Creating a Zetta project

1. Create a new directory to save the project, e.g., demo-zetta.

2. Now cd to that directory. Here, it’s cd demo-zetta.

3. To create a new Node.js project, run the command given below:

npm init 4. 5.

You will be asked for basic informatio­n about the project. By default, it will choose the value if you press Enter. If you want to change the value, then do so and press Enter several times and finish the installati­on. Basically, it will create a package.json file, which contains meta data about the project and its dependenci­es.

Now we will install the Zetta Node.js module. Here, the -save option adds Zetta to the package.json dependenci­es list.

npm install zetta -save

After all these steps, we have a basic Zetta project, which contains a package.json file and a node_modules directory.

Next, let’s configure the Zetta server.

Zetta server configurat­ion

We can install the Zetta server locally as a Zetta hub or in the cloud. We can link both the servers to access it from everywhere. Here we will install it locally for demo purposes.

1. Go to the demo-zetta directory.

2. Create a new file called index.js, and copy the code given below into it:

var zetta = require(‘zetta’); zetta()

.name(‘Zetta Demo’)

.listen(1337, function(){ console.log(‘Zetta is running at http://127.0.0.1:1337’);

});

3. Now save and close the file.

After performing the steps given above, we have configured a basic Zetta server hub.

Starting the server

In the demo-zetta directory, enter the command given below: node index.js

Figure 6 demonstrat­es the output of the above command. It shows the status of a running server.

Calling the Zetta API

Now, let’s call the Zetta API. We need to call the server’s root URL for that. Here we can use the curl command with http://127.0.0.1:1337 or any REST client tools. I am using the Rest Web Service Client. I have shared the download link in the References section at the end of the article.

In the URL section of the REST client, enter http://127.0.0.1:1337 and submit the request.

Now, in the response (formatted) section, you can see the response (see Figure 7). Check it for more informatio­n.

The Zetta server returns a JSON object that describes the root class of the API. The response demonstrat­es the current API state and links to resources given by the API. This is the basic API, which is not doing anything much as we don’t have devices attached. Once we add the devices, the API will show more informatio­n.

Zetta API follows the Siren hypermedia specificat­ion. For more informatio­n on that, you can visit https://github.com/kevinswibe­r/siren.

Zetta API is a built-in feature of Zetta, which automatica­lly generates APIs for devices. We can deploy these APIs in the cloud, which allows any authorised user to communicat­e with these devices from anywhere.

Everything is API based. All the informatio­n is stored in JSON format, so that we can use it on different platforms and take advantage of it. We can use the link http://localhost:1337/servers/ Zetta%20Demo to check the API response for the demo Zetta server.

References

[1] Node.js official website: https://nodejs.org [2] Zetta official website: http://www.zettajs.org/ [3] Rest Web service client installati­on link: https://chrome. google.com/webstore/detail/rest-web-service-client [4] GitHub link for Zetta: https://github.com/zettajs/zetta/wiki

 ??  ?? Figure 5: Installing the Zetta Node.js module
Figure 5: Installing the Zetta Node.js module
 ??  ?? Figure 4: Creating the Node.js project
Figure 4: Creating the Node.js project
 ??  ?? Figure 3: Node.js version
Figure 3: Node.js version
 ??  ?? Figure 6: Node.js Zetta server status
Figure 6: Node.js Zetta server status
 ??  ?? Figure 2: Zetta deployment
Figure 2: Zetta deployment
 ??  ?? Figure 1: Zetta architectu­re
Figure 1: Zetta architectu­re
 ??  ??
 ??  ?? Figure 7: The Zetta API call response
Figure 7: The Zetta API call response
 ??  ?? Figure 8: Demo Zetta server API response
Figure 8: Demo Zetta server API response

Newspapers in English

Newspapers from India