How to Make One

Since we support forwarding data to many different services, we made a generator to make creating new data forwarders easier. By using our Yeoman generator, you can develop data forwarders in CoffeeScript quickly and easily by filling in the blanks in the generated code!

1. Install Yeoman and the Generator

npm install -g yo

Install the Data Forwarder generator:

npm install -g generator-data-forwarder

2. Generate a New Data Forwarder

mkdir data-forwarder-seti
cd data-forwarder-seti

Generate the data-forwarder in this directory:

yo data-forwarder

📘

Production and Development Files

The generator will ask if you want to generate the configuration files for production and local development. There's no harm in doing this, but the files will be of little use unless you use something like Octoblu-Dev for local Meshblu development

3. Customize the Generated Forwarder

After generating the forwarder project, there are 3 files that must be customized in order for it to actually do anything. They are:

  • src/models/{project-name}-model.coffee

    • implement the onMessage function with logic that executes every time a message is received by the forwarder
  • schemas/configure-schema.json

    • Define a JSON Schema that describes the data format the forwarder expects on the device data in order to work
  • examples/example.sh

    • Not strictly necessary, but it's nice to have a real example for the users of your service.

🚧

Configuration Format

Data Forwarders require that all the configuration used by the service to be stored under the key forwarderConfig on the device. So make sure that your configure-schema nests all of it's configuration data under this key! The schema generated by the generator does this for you by default.

4. Run the Data Forwarder!

Data forwarders depend on 2 environment variables in order to run:

  • SERVICE_URL

    • The URL of the forwarder that is being run. This is necessary for setting up webhooks, etc.
  • PORT

  • The port on which to run the service.
env PORT=8899 SERVICE_URL=http://data-forwarder-seti.octoblu.dev npm start

That's it! You should now be able to use this service in the way described in Creating via a Service