-
Notifications
You must be signed in to change notification settings - Fork 114
Create Device Driver
This topic explains how to create a Zetta device driver using a set of starter files that you can modify to suit your particular device. Let's get started!
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
.
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
Replace
{device}
with the name of the device and{platform}
with the name of the platform for the driver you are making.
-
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.
Adapt the starter code to your device.
-
Change directory to project root.
cd ..
-
Edit the following files and replace references to starter and Starter with the device you are making.
- Scout: index.js
- NPM package: package.json
- README: README.md
- Driver: starter.js
-
Rename the driver file to the name of your device.
git mv starter.js {device}.js
Replace {device} with the name of the device you are making. For example, if you are creating the driver for an LED, you would execute git mv starter.js led.js. There is no need to add zetta or driver 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
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.
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}
In the case of GitHub, your {git repo url} would look something like https://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
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
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.
Follow these steps to publish your device driver to NPM:
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