Usage & Enterprise Capabilities
Zetta is an open-source, API-first platform for the Internet of Things (IoT) built on Node.js. It transforms micro-controllers and heterogeneous hardware into fully functional, programmable web services. By abstracting hardware capabilities into standardized REST APIs and WebSocket data streams, Zetta allows web and mobile developers to interact with physical devices using the same HTTP paradigms they use for standard web applications.
Unlike monolithic IoT platforms, Zetta is designed geometrically. You can run Zetta Hubs at the edge (e.g., on a Raspberry Pi within a local network) to interface directly with local hardware sensors. These localized hubs can then peer with aggregate Zetta servers running in cloud environments. This distributed peer-to-peer architecture makes it ideal for managing sprawling, multi-location IoT setups.
Because it inherits Node.js's event-driven, non-blocking I/O model, Zetta is exceptionally well-suited for handling thousands of concurrent WebSocket data streams generated by chatty hardware sensors.
Key Benefits
API-First Hardware: Zetta generates REST APIs and Siren hypermedia responses for every device automatically, eliminating the need to write custom networking code for hardware.
Real-Time Streaming: Built-in WebSocket support creates persistent connections, allowing dashboards and mobile apps to receive real-time streams of sensor metrics.
Hardware Agnostic: By writing simple Node.js device drivers, you can interact with Arduinos, Philips Hue bulbs, temperature sensors, or custom hardware using a uniform interface.
State Machine Modeling: Devices are modeled as finite state machines. You define transitions (e.g., from
offtoon) and the SDK automatically prevents impossible API combinations.Cloud to Edge Topology: Zetta's ability to "link" servers means you can securely control edge devices heavily hidden behind local firewalls via a public cloud node.
Production Architecture Overview
A production Zetta ecosystem is naturally distributed:
Zetta Server (Hub): A Node.js application running the Zetta framework.
Edge Hubs: Run locally near the hardware (e.g., inside a factory building). These load the hardware "device drivers" to talk over serial, Bluetooth, or local IP protocols.
Cloud Hubs: Run in public AWS/GCP data centers. They aggregate data and serve the public-facing APIs to external mobile or web clients.
Device Drivers: JavaScript classes that inherit from
zetta.Devicedetermining how Node.js physically interacts with a specific piece of hardware.Apps: JavaScript modules loaded into the Zetta server that watch for state changes on devices and trigger reactions (e.g., "If motion sensor is triggered, turn on light bulb").
Client Applications: Web interfaces, dashboards, or mobile applications consuming the Hypermedia API and WebSockets provided by the Cloud Hubs.
Implementation Blueprint
Implementation Blueprint
Prerequisites
# Ensure Node.js and npm are installed
node -v
npm -v
# Create a new project directory
mkdir my-zetta-hub
cd my-zetta-hub
npm init -y
# Install Zetta
npm install zetta --saveBuilding a Local Zetta Hub
Create the main entry point for your Zetta server, server.js.
// server.js
const zetta = require('zetta');
const PORT = process.env.PORT || 1337;
// Initialize the Zetta runtime
zetta()
.name('my-local-edge-hub')
// .use(SomeHardwareDriver) -> We will add devices here
// .load(SomeLogicApp) -> We will add logic here
.listen(PORT, function() {
console.log(`Zetta is running at http://127.0.0.1:${PORT}`);
});Run the server:
node server.jsVisiting http://127.0.0.1:1337/ in a browser will return the root JSON Siren hypermedia API containing links to all available devices.
Creating a Device Driver (State Machine)
To integrate a device, you write a driver representing its states, transitions, and data streams.
# Install the base class
npm install zetta-device --saveCreate a mock LED driver (mock-led.js):
// mock-led.js
const Device = require('zetta-device');
const util = require('util');
const MockLED = module.exports = function() {
Device.call(this);
};
util.inherits(MockLED, Device);
MockLED.prototype.init = function(config) {
config
.type('led')
.state('off') // Initial state
.name('Living Room Light')
// Define available transitions
.when('off', { allow: ['turn-on'] })
.when('on', { allow: ['turn-off'] })
// Map transitions to JavaScript functions
.map('turn-on', this.turnOn)
.map('turn-off', this.turnOff);
};
MockLED.prototype.turnOn = function(cb) {
this.state = 'on';
console.log("HARDWARE LOG: LED is turning ON");
cb(); // Callback indicating completion
};
MockLED.prototype.turnOff = function(cb) {
this.state = 'off';
console.log("HARDWARE LOG: LED is turning OFF");
cb();
};Update server.js to use it:
const MockLED = require('./mock-led');
zetta()
.name('my-local-edge-hub')
.use(MockLED)
.listen(1337);Adding Data Streams
IoT isn't just about control; it's about telemetry. You can easily stream data (like temperature).
// Inside your device init function:
config
.type('thermometer')
.monitor('temperature'); // Declares a monitorable stream
// ...
// Simulate reading temperature every second
setInterval(() => {
this.temperature = Math.floor(Math.random() * 30);
}, 1000);Clients can connect to this device's generated WebSocket URL to receive real-time temperature updates instantly.
Reactive IoT Logic (Zetta Apps)
Write apps to link devices. For example, triggering a light when a button is pressed.
// dusk-to-dawn-app.js
module.exports = function(server) {
// Query for devices
const ledQuery = server.where({ type: 'led' });
const sensorQuery = server.where({ type: 'photocell' });
// Whenever both devices are discovered on the network
server.observe([ledQuery, sensorQuery], function(led, sensor) {
// Stream the sensor's luminosity stream
sensor.streams.luminosity.on('data', function(m) {
if(m.data < 50) {
if (led.state !== 'on') led.call('turn-on');
} else {
if (led.state !== 'off') led.call('turn-off');
}
});
});
};Update server.js to .load(app) this module.
Cloud-to-Edge Peering (Production Scaling)
To control a Raspberry Pi hidden behind a NAT router at home from a commercial web app, deploy a cloud Zetta node and link the local hub to it.
Cloud Server (runs on AWS):
zetta()
.name('my-cloud-api')
.listen(process.env.PORT);Local Edge Hub (runs on Raspberry Pi):
zetta()
.name('my-home-hub')
.use(MockLED)
.link('http://cloud.mycompany.com') // Dials out to the cloud server
.listen(1337);The edge hub initiates an outbound WebSocket connection to the cloud hub. The cloud hub proxies all REST API commands down that established tunnel, bypassing the local firewall.
Security Practices
Reverse Proxies: Never expose a Node.js process directly to the internet in production. Use Nginx or HAProxy to terminate TLS (HTTPS/WSS) and forward traffic to Zetta on
localhost:1337.Authentication: Zetta lacks robust built-in API key/JWT management out of the box. Implement authentication middlewares at the proxy level or create an express wrapper around Zetta to validate Tokens before allowing API interaction.
Secure Tunneling: When peering edge hubs to cloud servers, guarantee the communication is over secure
wss://WebSockets to prevent man-in-the-middle attacks on your physical hardware telemetry.