How to Create a Device Driver

This guide will show you how to create a device driver.
  • compass Guide
  • calendar Oct 21, 2014

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 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

  1. Change to the new driver directory.

    cd zetta-{device}-{platform}-driver
  2. Install default Zetta driver dependencies.

    npm install
  3. Change to example directory.

    cd example
  4. Install default Zetta server dependencies.

    npm install
  5. Run the driver’s example server.

    node server.js
  6. Ensure you see expected startup messages in the terminal.

    {timestamp} [scout] Device (starter) {id} was discovered
    {timestamp} [server] Server ( listening on
    {timestamp} [Starter-log] DEFAULT: ./app.js is running
    {timestamp} [device] starter transition do   
  7. Ensure you see Starter in the Zetta browser and that the the state visualization updates.

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.

  1. Change directory to project root.

    cd ..
  2. 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:
    • Driver: starter.js
  3. 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 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.

  4. Restart the example server.

    node example/server.js
  5. Ensure you see your {device} labeled in the Zetta browser and that the the state visualization updates.

Step #5: Update the Git Repo

After renaming the starter device you will likely want to push changes to your own git repo.

  1. 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.

  2. 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 like{username}/zetta-{device}-{platform}-driver.git.

  3. Commit changes to the repository.

    git commit -a
  4. 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.

The Zetta Discuss Google Group is the ideal spot for getting the broader community’s help when creating device drivers:!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: