Usage & Enterprise Capabilities
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
- 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
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}`);
});node server.jshttp://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)
# Install the base class
npm install zetta-device --savemock-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();
};server.js to use it:const MockLED = require('./mock-led');
zetta()
.name('my-local-edge-hub')
.use(MockLED)
.listen(1337);Adding Data Streams
// 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);Reactive IoT Logic (Zetta Apps)
// 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');
}
});
});
};server.js to .load(app) this module.Cloud-to-Edge Peering (Production Scaling)
zetta()
.name('my-cloud-api')
.listen(process.env.PORT);zetta()
.name('my-home-hub')
.use(MockLED)
.link('http://cloud.mycompany.com') // Dials out to the cloud server
.listen(1337);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.
Recommended Hosting for Zetta
For systems like Zetta, we recommend high-performance VPS hosting. Hostinger offers dedicated setups for open-source tools with one-click installer scripts and 24/7 priority support.
Get Started on HostingerExplore Alternative Tools Infrastructure
Kubernetes
Kubernetes is a production-grade, open-source platform for automating deployment, scaling, and operations of application containers.
Supabase
Supabase is the leading open-source alternative to Firebase. It provides a full backend-as-a-service (BaaS) powered by PostgreSQL, including authentication, real-time subscriptions, and storage.