{"_id":"5750bf6ed159a11900e8b4e9","__v":0,"category":{"_id":"573c99725c4c010e006caa58","version":"573c99725c4c010e006caa57","__v":0,"project":"573c99725c4c010e006caa54","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-05-18T16:33:54.308Z","from_sync":false,"order":9999,"slug":"documentation","title":"Data Forwarders"},"user":"5564f227f0f70f0d00a9ab20","version":{"_id":"573c99725c4c010e006caa57","project":"573c99725c4c010e006caa54","__v":3,"createdAt":"2016-05-18T16:33:54.264Z","releaseDate":"2016-05-18T16:33:54.264Z","categories":["573c99725c4c010e006caa58","5750c01651b4bb2b00178745","5751d0628e9ef90e0083eb06"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"githubsync":"","project":"573c99725c4c010e006caa54","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-06-02T23:21:18.898Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":999,"body":"Since we support forwarding data to many different services, we made a generator to make creating new data forwarders easier. By using our [Yeoman](http://yeoman.io) generator, you can develop data forwarders in CoffeeScript quickly and easily by filling in the blanks in the generated code!\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"1. Install Yeoman and the Generator\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"npm install -g yo\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nInstall the Data Forwarder generator:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"npm install -g generator-data-forwarder\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"2. Generate a New Data Forwarder\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"mkdir data-forwarder-seti\\ncd data-forwarder-seti\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nGenerate the data-forwarder in this directory:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"yo data-forwarder\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"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](https://github.com/octoblu/octoblu-dev) for local Meshblu development\",\n  \"title\": \"Production and Development Files\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"3. Customize the Generated Forwarder\"\n}\n[/block]\nAfter generating the forwarder project, there are 3 files that must be customized in order for it to actually do anything. They are:\n\n* **src/models/{project-name}-model.coffee**\n    - implement the onMessage function with logic that executes every time a message is received by the forwarder\n  \n \n* **schemas/configure-schema.json**\n   - Define a [JSON Schema](http://json-schema.org) that describes the data format the forwarder expects on the device data in order to work\n\n\n* **examples/example.sh**\n    - Not strictly necessary, but it's nice to have a real example for the users of your service.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"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.\",\n  \"title\": \"Configuration Format\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"4. Run the Data Forwarder!\"\n}\n[/block]\nData forwarders depend on 2 environment variables in order to run:\n\n* **SERVICE_URL** \n    - The URL of the forwarder that is being run. This is necessary for setting up webhooks, etc.\n\n* **PORT**\n - The port on which to run the service.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"env PORT=8899 SERVICE_URL=http://data-forwarder-seti.octoblu.dev npm start\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nThat's it! You should now be able to use this service in the way described in [Creating via a Service](https://meshblu-forwarders.readme.io/docs/creating-via-service)","excerpt":"","slug":"how-to-make-one","type":"basic","title":"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](http://yeoman.io) generator, you can develop data forwarders in CoffeeScript quickly and easily by filling in the blanks in the generated code! [block:api-header] { "type": "basic", "title": "1. Install Yeoman and the Generator" } [/block] [block:code] { "codes": [ { "code": "npm install -g yo", "language": "shell" } ] } [/block] Install the Data Forwarder generator: [block:code] { "codes": [ { "code": "npm install -g generator-data-forwarder", "language": "shell" } ] } [/block] [block:api-header] { "type": "basic", "title": "2. Generate a New Data Forwarder" } [/block] [block:code] { "codes": [ { "code": "mkdir data-forwarder-seti\ncd data-forwarder-seti", "language": "shell" } ] } [/block] Generate the data-forwarder in this directory: [block:code] { "codes": [ { "code": "yo data-forwarder", "language": "text" } ] } [/block] [block:callout] { "type": "info", "body": "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](https://github.com/octoblu/octoblu-dev) for local Meshblu development", "title": "Production and Development Files" } [/block] [block:api-header] { "type": "basic", "title": "3. Customize the Generated Forwarder" } [/block] 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](http://json-schema.org) 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. [block:callout] { "type": "warning", "body": "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.", "title": "Configuration Format" } [/block] [block:api-header] { "type": "basic", "title": "4. Run the Data Forwarder!" } [/block] 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. [block:code] { "codes": [ { "code": "env PORT=8899 SERVICE_URL=http://data-forwarder-seti.octoblu.dev npm start", "language": "shell" } ] } [/block] That's it! You should now be able to use this service in the way described in [Creating via a Service](https://meshblu-forwarders.readme.io/docs/creating-via-service)