SDK Develop
  • 28 Mar 2025
  • 2 Minutes to read
  • Contributors

SDK Develop


Article summary

Learn how to start developing and iterating on your Tulip Edge Driver

Introduction

  1. What you will learn
    1. How to develop your first edge driver project
      1. Build a project
      2. Update the manifest and index files
  2. What you will need (pre-requisites)
    1. Followed all of the steps in SDK Create

Getting Started

Once you have created your new Edge Driver with the create-edge-driver tool, you're ready to start implementing your own driver code!

Updating manifest.json

First, we need to define the events and functions implemented by our driver. Device events can be used as triggers for logic in Tulip Apps. For example, you can set up an App trigger like:

"When my sensor fires a measurement event, store the temperature data in the 'Shop Floor Temperature' variable."

Drivers can also implement device functions, which can be executed in response to triggers within an app. For instance:

"When I click this button, call the 'Toggle Light' function on my device."

In this example, our driver will have no functions, but will fire an event called "data" when our sensor takes a measurement. Update the functions section in your src/manifest.json file by either leaving it empty or removing it entirely:

...
  "functions": [],
...

Then update the events section to define the shape of the "data" event. This event will be an object with two float properties, "temperature" and "humidity":

...
  "events": [
    {
      "name": "data",
      "schema": {
        "type": "object",
        "properties": {
          "temperature": { "type": "float" },
          "humidity": { "type": "float" }
        }
      }
    }
  ],
...

Updating index.ts

Now we will write the driver code that uses the Edge Driver SDK to find and connect to a serial port, reads incoming serial data, parses the JSON messages, and fires the "data" event using fireEvent(). Replace the example code in your src/index.ts file with this new code:

edgeDriverSdk.SerialPort.listAvailablePorts().then((ports) => {
  const esp32port = ports.find((port) => port.product_id === 33128);
  const serial = new edgeDriverSdk.SerialPort(esp32port.path, {
    baudRate: 115200,
  });

  serial.onData((data) => {
    try {
      const decoder = new TextDecoder();
      const stringData = decoder.decode(new Uint8Array(data));
      const espData = JSON.parse(stringData.split("ESP: ")[1]);
      edgeDriverSdk.fireEvent("data", espData);
    } catch (error) {
      console.error(error);
    }
  });

  serial.open();
});

This is a very simple example that automatically tries to find the device using the Product ID of the USB device, a single time when the driver starts. The Edge Driver SDK also supports registering drivers to be started when new devices are detected by the system, which can help make more robust production drivers.

Building the Driver

After updating the driver code and manifest.json, build the driver again:

npm run build

This will generate the compiled and bundled JavaScript file as well as a copy of the validated manifest inside the dist directory.
SDK


Was this article helpful?

What's Next