Zetta: An API-First IoT Plat­form

Runs ev­ery­where; en­ables us to API ev­ery­thing, code with joy, stream Big Data and build big apps—that’s what Zetta does for us.

OpenSource For You - - Contents - By: Maulik Parekh The au­thor has an M. Tech de­gree in cloud com­put­ing from VIT Univer­sity, Chen­nai. He can be reached at maulik­parekh2@gmail.com. Web­site: https://www. linkedin.com/in/maulik­parekh2.

The In­ter­net of Things is one of the hottest top­ics in the tech in­dus­try. By us­ing IoT, we can easily connect with dif­fer­ent ob­jects and in­ter­act with them, like the way we are en­gag­ing with cur­rent smart tech­nolo­gies. It will change how we live, sig­nif­i­cantly. IoT of­fers tremen­dous op­por­tu­ni­ties, but there are sub­stan­tial risks too. In this ar­ti­cle, we will look at how we can lever­age the ad­van­tages of Zetta, an API plat­form in IoT.

What is Zetta?

Zetta is an open source plat­form for IoT on which we can build APIs for de­vice in­ter­ac­tion. The plat­form is built on Node.js. Peo­ple who are fa­mil­iar with Node.js can easily get started with Zetta but, for be­gin­ners, a ba­sic un­der­stand­ing of Node.js is re­quired.

Let’s un­der­stand the Zetta plat­form and its char­ac­ter­is­tics

Zetta is an open source plat­form, so any­one can use it free of cost. If you are pas­sion­ate about Node.js (https:// nodejs.org/), then you can con­trib­ute to this open source project. Cur­rently, the com­mu­nity is small, but it’s grow­ing. Ba­si­cally, it’s a tool that will help to gen­er­ate APIs which we can use to com­mu­ni­cate be­tween de­vices. Node.js is ba­si­cally a server-side JavaScript. De­vel­op­ers can de­fine de­vices as state ma­chines us­ing JavaScript. It is also cross-plat­form and is easily de­ploy­able in mul­ti­ple cloud plat­forms.

Zetta is an API driven plat­form. Ev­ery call is API based so that we can use these APIs for any other pur­pose like send­ing data to other an­a­lyt­ics plat­forms.

Zetta ex­poses Web­socket end­points to stream re­al­time events. This model of merg­ing Hyper­me­dia with Web­socket stream­ing is ac­knowl­edged as Re­ac­tive Hyper­me­dia.

It can sup­port al­most all de­vice pro­to­cols, and me­di­ate them to HTTP. Con­nec­tions be­tween servers are also per­sis­tent, so that we can use the seam­less ser­vices be­tween servers in the cloud.

We can cre­ate state­less ap­pli­ca­tions in Zetta servers. Ap­pli­ca­tions can be use­ful to connect de­vices, run dif­fer­ent queries and in­ter­act be­tween them. We can also write queries and trig­gers so that when­ever new de­vices are at­tached, we will be no­ti­fied.

Zetta ar­chi­tec­ture

The Zetta server: The Zetta server is the main com­po­nent of Zetta, which con­tains dif­fer­ent sub-components like drivers, scouts, server ex­ten­sions and apps. A Zetta server will run on a hard­ware hub such as Bea­gleBone Black, Rasp­berry Pi or In­tel Edi­son. The server man­ages in­ter­ac­tions be­tween all the sub-components in or­der to com­mu­ni­cate with de­vices and gen­er­ate APIs, by which con­sumers can in­ter­act.

Scouts: Scouts pro­vide a dis­cov­ery mech­a­nism for de­vices on the net­works or to those which re­quire sys­tem re­sources to un­der­stand and com­mu­ni­cate with a spe­cific type of pro­to­col.

Scouts help Zetta to search for de­vices based on a par­tic­u­lar pro­to­col. They also fetch spe­cific in­for­ma­tion about de­vices and whether those de­vices have al­ready in­ter­acted with Zetta or not. They main­tain se­cu­rity cre­den­tials and re­lated de­tails while com­mu­ni­cat­ing.

Drivers: Drivers are used to rep­re­sent the de­vices in a state ma­chine for­mat. They are used for modelling de­vices and phys­i­cal in­ter­ac­tion be­tween de­vices. De­vice mod­els are used to gen­er­ate dif­fer­ent API calls.

Server ex­ten­sions: These are used for ex­tend­ing func­tion­al­i­ties. They are in a plug­gable mode, and deal with API man­age­ment, adding ad­di­tional se­cu­ri­ties, etc.

Registry: This is a data­base for the Zetta server, which stores in­for­ma­tion about the de­vices con­nected to the server. It is a per­sis­tence layer.

Se­cure link­ing: We can es­tab­lish se­cure and en­crypted tun­nelling be­tween dif­fer­ent servers while com­mu­ni­cat­ing. This takes care of fire­walls and network set­tings.

Apps: Apps that are used for dif­fer­ent in­ter­ac­tions be­tween de­vices or to fetch and process some data are cre­ated in JavaScript. Apps can be cre­ated based on sen­sor streams or changes in de­vices. They can be used to track cer­tain kinds of events that hap­pen in sys­tems.

Zetta de­ploy­ment

Now let us ex­plore the de­ploy­ment of Zetta.

1. The Zetta server runs on a hard­ware hub, which can be Rasp­berry Pi, In­tel Edi­son or Bea­gleBone Black.

2. The hub is con­nected to de­vices, and they com­mu­ni­cate via

HTTP to the spe­cific pro­to­cols used in the de­ploy­ment.

3. An­other sim­i­lar server runs in the cloud, which has the same Node.js pack­ages that are avail­able on the Zetta server in the hub. Both the servers are con­nected.

4. Zetta pro­vides an API at the cloud end­point so that con­sumers can use it.

Hard­ware re­quire­ments: Zetta runs with ap­prox­i­mately six con­nected de­vices per hub, which is the ideal sce­nario sug­gested by it. Hard­ware re­quire­ments are de­pen­dent upon the num­ber of de­vices, the load of each de­vice and the type of data flow­ing be­tween them. The ideal min­i­mum re­quire­ment is a 500MHz CPU, 500MB RAM and stor­age of 1GB-2GB. Zetta re­quires 500MB to be able to run. It sup­ports all com­mon op­er­at­ing sys­tems with 32-bit and 64-bit ver­sions.

Zetta in­stal­la­tion and demo project

Now let’s take a look at in­stalling Zetta and a ‘Hello world’ ver­sion of the Zetta sam­ple project. Be­fore start­ing Zetta, here’s a brief in­tro­duc­tion to Node.js.


This is built on Chrome’s JavaScript run­time for build­ing scal­able and faster ap­pli­ca­tions. It uses an event-driven, non­block­ing IO model. It is pop­u­lar and very ef­fi­cient for real-time ap­pli­ca­tions run­ning across distributed sys­tems. Ba­si­cally, it’s a server-side JavaScript.

Go to the of­fi­cial site https://nodejs.org and from the Down­loads sec­tion, down­load the ap­pro­pri­ate in­staller file based on the op­er­at­ing sys­tem. More de­tails about cre­at­ing projects in Node.js are de­scribed in the fol­low­ing steps.

Zetta in­stal­la­tion

For Zetta in­stal­la­tion, the first thing re­quired is Node.js. As dis­cussed, down­load the Node.js in­staller on to your sys­tem. This will in­stall both Node.js and npm (node pack­age man­ager). So we don’t need to in­stall any­thing separately; it’s a com­plete pack­age. We can ver­ify the ver­sions by us­ing the com­mands shown in Fig­ure 3.

Cre­at­ing a Zetta project

1. Cre­ate a new di­rec­tory to save the project, e.g., demo-zetta.

2. Now cd to that di­rec­tory. Here, it’s cd demo-zetta.

3. To cre­ate a new Node.js project, run the com­mand given be­low:

npm init 4. 5.

You will be asked for ba­sic in­for­ma­tion about the project. By de­fault, it will choose the value if you press En­ter. If you want to change the value, then do so and press En­ter sev­eral times and fin­ish the in­stal­la­tion. Ba­si­cally, it will cre­ate a pack­age.json file, which con­tains meta data about the project and its de­pen­den­cies.

Now we will in­stall the Zetta Node.js mod­ule. Here, the -save op­tion adds Zetta to the pack­age.json de­pen­den­cies list.

npm in­stall zetta -save

Af­ter all these steps, we have a ba­sic Zetta project, which con­tains a pack­age.json file and a node_­mod­ules di­rec­tory.

Next, let’s con­fig­ure the Zetta server.

Zetta server con­fig­u­ra­tion

We can in­stall the Zetta server lo­cally as a Zetta hub or in the cloud. We can link both the servers to ac­cess it from ev­ery­where. Here we will in­stall it lo­cally for demo pur­poses.

1. Go to the demo-zetta di­rec­tory.

2. Cre­ate a new file called in­dex.js, and copy the code given be­low into it:

var zetta = re­quire(‘zetta’); zetta()

.name(‘Zetta Demo’)

.lis­ten(1337, func­tion(){ con­sole.log(‘Zetta is run­ning at’);


3. Now save and close the file.

Af­ter per­form­ing the steps given above, we have con­fig­ured a ba­sic Zetta server hub.

Start­ing the server

In the demo-zetta di­rec­tory, en­ter the com­mand given be­low: node in­dex.js

Fig­ure 6 demon­strates the out­put of the above com­mand. It shows the sta­tus of a run­ning server.

Call­ing 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 com­mand with or any REST client tools. I am us­ing the Rest Web Ser­vice Client. I have shared the down­load link in the Ref­er­ences sec­tion at the end of the ar­ti­cle.

In the URL sec­tion of the REST client, en­ter and sub­mit the re­quest.

Now, in the re­sponse (for­mat­ted) sec­tion, you can see the re­sponse (see Fig­ure 7). Check it for more in­for­ma­tion.

The Zetta server re­turns a JSON ob­ject that de­scribes the root class of the API. The re­sponse demon­strates the cur­rent API state and links to re­sources given by the API. This is the ba­sic API, which is not do­ing any­thing much as we don’t have de­vices at­tached. Once we add the de­vices, the API will show more in­for­ma­tion.

Zetta API fol­lows the Siren hyper­me­dia spec­i­fi­ca­tion. For more in­for­ma­tion on that, you can visit https://github.com/kevin­swiber/siren.

Zetta API is a built-in fea­ture of Zetta, which au­to­mat­i­cally gen­er­ates APIs for de­vices. We can de­ploy these APIs in the cloud, which al­lows any au­tho­rised user to com­mu­ni­cate with these de­vices from any­where.

Ev­ery­thing is API based. All the in­for­ma­tion is stored in JSON for­mat, so that we can use it on dif­fer­ent plat­forms and take ad­van­tage of it. We can use the link http://lo­cal­host:1337/servers/ Zetta%20Demo to check the API re­sponse for the demo Zetta server.


[1] Node.js of­fi­cial web­site: https://nodejs.org [2] Zetta of­fi­cial web­site: http://www.zettajs.org/ [3] Rest Web ser­vice client in­stal­la­tion link: https://chrome. google.com/web­store/de­tail/rest-web-ser­vice-client [4] GitHub link for Zetta: https://github.com/zettajs/zetta/wiki

Fig­ure 2: Zetta de­ploy­ment

Fig­ure 1: Zetta ar­chi­tec­ture

Fig­ure 5: In­stalling the Zetta Node.js mod­ule

Fig­ure 4: Cre­at­ing the Node.js project

Fig­ure 3: Node.js ver­sion

Fig­ure 6: Node.js Zetta server sta­tus

Fig­ure 7: The Zetta API call re­sponse

Fig­ure 8: Demo Zetta server API re­sponse

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.