-
Notifications
You must be signed in to change notification settings - Fork 114
Linking Servers
Zetta servers allow for establishing a secure tunneled link between two servers. This connection takes care of network configurations, and firewalls that make Cloud connected IoT solutions difficult to maintain.
Zetta then exposes an API at the Cloud endpoint for developers to consume.
In this topic, we'll show you how to link a locally running Zetta server to a server instance deployed in the Cloud. Zetta then exposes an API at the Cloud endpoint that developers can consume. It's very cool and very simple to do!
To make things easy, we'll deploy an existing Zetta server that resides on GitHub to the Heroku platform. The README for this GitHub repo includes the Deploy to Heroku button, which does all the work for you.
Note: To do these steps, you'll need to have an Heroku account.
-
In a browser, go to the Zetta Cloud Starter repository on GitHub.
-
Click the Deploy to Heroku button in the README.
-
You'll be asked to log in to your Heroku account, or register for a free account.
-
In the deployment form, enter an app name (if you don't, the system will pick a random one for you).
-
Click Deploy for Free.
-
In a browser (or in a REST client like Postman), hit this URL:
https://<your-heroku-app-name>.herokuapp.com
You'll get back a standard Zetta server response, like this:
{
"class": [
"root"
],
"links": [
{
"rel": [
"self"
],
"href": "https://zetta-test-1234.herokuapp.com/"
},
{
"title": "cloud",
"rel": [
"http://rels.zettajs.io/server"
],
"href": "https://zetta-test-1234.herokuapp.com/servers/cloud"
},
{
"rel": [
"http://rels.zettajs.io/peer-management"
],
"href": "https://zetta-test-1234.herokuapp.com/peer-management"
}
],
"actions": [
{
"name": "query-devices",
"method": "GET",
"href": "https://zetta-test-1234.herokuapp.com/",
"type": "application/x-www-form-urlencoded",
"fields": [
{
"name": "server",
"type": "text"
},
{
"name": "ql",
"type": "text"
}
]
}
]
}
Here is where things get interesting. You can link another Zetta server to this Cloud instance. For example, if you have a locally running Zetta hub, and link it to a Cloud server, you can access the local hub from anywhere!
In the rest of this example, we'll use Links to control the Mock LED project from the Zetta instance running on Heroku.
-
The first thing you'll need is a locally running Zetta hub. For simplicity, we recommend that you implement and use the Mock Device tutorial project, get it running, and make sure it's working correctly.
-
cd to the root directory of the project, which we called
hello-zetta
. -
In an editor, open the
index.js
file. -
Add the
link()
function to the hub server, like this, wherezetta-test-1234
is the name of the Heroku app -- yours will be different.link('https://zetta-test-1234.herokuapp.com/')
The server code should look something like this:
var zetta = require('zetta'); var LED = require('zetta-led-mock-driver'); zetta() .name('Device Tutorial') .use(LED) .link('https://zetta-test-1234.herokuapp.com/') .listen(1337, function(){ console.log('Zetta is running at http://127.0.0.1:1337'); });
-
Start the local Zetta server:
node index.js
. Notice in the server output that the peer connection was established:Oct-23-2015 15:44:27 [scout] Device (led) f826f6e0-ebb8-430a-9e1e-6efddebc42fc was provisioned from registry. Oct-23-2015 15:44:27 [server] Server (Device Tutorial) Device Tutorial listening on http://127.0.0.1:1337 Zetta is running at http://127.0.0.1:1337 Oct-23-2015 15:44:28 [peer-client] WebSocket to peer established (wss://zetta-test-1234.herokuapp.com/peers/Device Tutorial) Oct-23-2015 15:44:28 [peer-client] Peer connection established (wss://zetta-test-1234.herokuapp.com/peers/Device Tutorial)
-
Now, point the Zetta browser client app to the server running on Heroku. In your browser, simply enter this URL, and substitute the name of your Heroku app for
zetta-test-1234
.http://browser.zettajs.io/#/overview?url=https://zetta-test-1234.herokuapp.com
-
Toggle the turn-on/turn-off button.
-
Notice that the browser shows the state transition very nicely. And, if you look at your local server's stdout, you'll see output indicating each state change:
Oct-23-2015 15:49:36 [device] led transition turn-on Oct-23-2015 15:49:42 [device] led transition turn-off
Congratulations! You can now control the mock LED running on your local machine from anywhere in the world!
Need help? Visit the Zetta Discuss List !
Need help? Visit the Zetta Discuss List ! |
---|
About Zetta
Videos and webcasts
- NEW! Building with Zetta
Tutorials
- NEW! Zetta tutorial series
- Quick start
- Configure a simple device
- Build a mock LED device
- Use the browser client
- Deploy a Zetta server to Heroku
Understanding Zetta
Writing Zetta drivers
- Finding Zetta device drivers
- Create a device driver from starter code
- More coming soon...
Using streams
Reference