Note: This topic has been relocated to the Zetta doc wiki, the new home for all Zetta documentation. Please bookmark the doc wiki for future reference.
So, you want to create a Zetta device driver? This guide will get you started.
Step #1: Know Your Device and Platform
Zetta drivers are created for specific devices on specific platforms. The Zetta community uses a naming convention for drivers that incorporates the device and platform names separated by hyphens: zetta-{device}-{platform}-driver
.
Know the names for the device and platform you are making:
- device
- platform
For example, the Zetta driver for an LED on Arduino is named: zetta-led-arduino-driver
.
Step #2: Clone the Starter Code
Clone the Zetta starter driver to a new directory called zetta-{device}-{platform}-driver
:
git clone https://github.com/zettajs/zetta-starter-driver zetta-{device}-{platform}-driver
action Replace
{device}
with the name of the device and{platform}
with the name of the platform for the driver you are making.
Step #3: Run the Example Server
-
Change to the new driver directory.
cd zetta-{device}-{platform}-driver
-
Install default Zetta driver dependencies.
npm install
-
Change to example directory.
cd example
-
Install default Zetta server dependencies.
npm install
-
Run the driver’s example server.
node server.js
-
Ensure you see expected startup messages in the terminal.
{timestamp} [scout] Device (starter) {id} was discovered {timestamp} [server] Server (server.name) server.name listening on http://127.0.0.1:1337 {timestamp} [Starter-log] DEFAULT: ./app.js is running {timestamp} [device] starter transition do
-
Ensure you see Starter in the Zetta browser and that the the state visualization updates.
http://browser.zettajs.io/#/overview?url=http:%2F%2F127.0.0.1:1337
You now have a working device driver, scout, example server and example app running on your development machine.
Step #4: Search and Replace the Starter Code
Adapt the starter code to your device.
-
Change directory to project root.
cd ..
-
Edit the following files and replace references to
starter
andStarter
with the device you are making.- Scout:
index.js
- NPM package:
package.json
- README:
README.md
- Driver:
starter.js
- Scout:
-
Rename the driver file to the name of your device.
git mv starter.js {device}.js
action Replace
{device}
with the name of the device you are making. For example, if you are creating the driver for an LED, you would executegit mv starter.js led.js
. There is no need to addzetta
ordriver
to the name of the driver file in this context. -
Restart the example server.
node example/server.js
-
Ensure you see your {device} labeled in the Zetta browser and that the the state visualization updates.
http://browser.zettajs.io/#/overview?url=http:%2F%2F127.0.0.1:1337
Step #5: Update the Git Repo
After renaming the starter device you will likely want to push changes to your own git repo.
-
Create a git repository for the new driver on your git repository of choice. Follow the Zetta naming convention:
zetta-{device}-{platform}-driver
.info The Zetta team uses GitHub as the source code repository for Zetta.
-
Change the remote of the git repository.
git remote set-url origin {your git repo url}
info In the case of GitHub, your
{git repo url}
would look something likehttps://github.com/{username}/zetta-{device}-{platform}-driver.git
. -
Commit changes to the repository.
git commit -a
-
Push changes to the new origin.
git push origin master
Step #6: Get Inspired
There are many Zetta drivers that can serve as starting point for creating a device driver.
-
Query NPM for drivers that have been created for other devices by the community: https://www.npmjs.com/search?q=zetta-*-driver
-
Query GitHub for drivers that have been created by the core Zetta team: https://github.com/zettajs?query=driver
-
Narrow the search by device type: zetta-led-*-driver
-
Narrow the search by platform type: zetta-*-edison-driver.
The Zetta Discuss Google Group is the ideal spot for getting the broader community’s help when creating device drivers: https://groups.google.com/forum/#!forum/zetta-discuss
Step #7: Build the Driver
Starting with the {device}.js
driver file and the index.js
scout file, write the code that models your device. Use the Zetta Browser to validate your work as you go.
Step #8: Publish with NPM
Follow these steps to publish your device driver to NPM: https://gist.github.com/coolaj86/1318304