{"_id":"5751c5117b01730e00c28dcf","user":"5564f227f0f70f0d00a9ab20","category":{"_id":"5750c01651b4bb2b00178745","__v":0,"project":"573c99725c4c010e006caa54","version":"573c99725c4c010e006caa57","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-06-02T23:24:06.957Z","from_sync":false,"order":9999,"slug":"using-a-data-forwarder","title":"Using a Data Forwarder"},"project":"573c99725c4c010e006caa54","__v":2,"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"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-06-03T17:57:37.677Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":999,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Setting up Data Forwarder Manually\"\n}\n[/block]\nBelow is an example of how to set up a data forwarder using [Meshblu Utility](https://meshblu.readme.io/docs/meshblu-utility) and [jq](https://stedolan.github.io/jq/). It is based on the scenario described in [What They Are](doc:what-are-meshblu-data-forwarders) \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Configuration\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#!/usr/bin/env bash\\n\\nSERVICE_URL=$1\\n\\nif [ -z \\\"$SERVICE_URL\\\" ]; then\\n   echo \\\"usage: ./example-data-forwarder.sh <SERVICE_URL>\\\"\\n   exit 1;\\nfi\\n\\n\\nmkdir ./tmp\\n\\necho \\\"creating Endoskeleton device\\\"\\nmeshblu-util register -d '{\\\"type\\\": \\\"endoskeleton\\\"}' > ./tmp/endoskeleton-meshblu.json\\nENDOSKELETON_UUID=$(cat ./tmp/endoskeleton-meshblu.json | jq -r '.uuid')\\nENDOSKELETON_TOKEN=$(cat ./tmp/endoskeleton-meshblu.json | jq -r '.token')\\necho \\\"endoskeleton is: $ENDOSKELETON_UUID\\\"\\n\\n\\necho \\\"creating Doorbell device\\\"\\nmeshblu-util register -d '{\\\"type\\\": \\\"doorbell\\\"}' > ./tmp/doorbell-meshblu.json\\nDOORBELL_UUID=$(cat ./tmp/doorbell-meshblu.json | jq -r '.uuid')\\nDOORBELL_TOKEN=$(cat ./tmp/doorbell-meshblu.json | jq -r '.token')\\necho \\\"doorbell is: $DOORBELL_UUID\\\"\\n\\necho \\\"adding Doorbell to Endoskeleton's message.from whitelist\\\"\\nmeshblu-util update -p -d \\\"{\\\\\\\"\\\\$addToSet\\\\\\\": {\\\\\\\"meshblu.whitelists.message.from\\\\\\\": {\\\\\\\"uuid\\\\\\\": \\\\\\\"$DOORBELL_UUID\\\\\\\"}}}\\\" ./tmp/endoskeleton-meshblu.json\\n\\necho \\\"creating Forwarder device\\\"\\nmeshblu-util register -d '{\\\"type\\\": \\\"forwarder\\\"}' > ./tmp/forwarder-meshblu.json\\nFORWARDER_UUID=$(cat ./tmp/forwarder-meshblu.json | jq -r '.uuid')\\nFORWARDER_TOKEN=$(cat ./tmp/forwarder-meshblu.json | jq -r '.token')\\necho \\\"forwarder is: $FORWARDER_UUID\\\"\\n\\necho \\\"adding webhook to forwarder\\\"\\nmeshblu-util create-hook -t message.received -U $SERVICE_URL ./tmp/forwarder-meshblu.json\\n\\necho \\\"adding forwarder to Endoskeleton's message.received whitelist\\\"\\nmeshblu-util update -p -d \\\"{\\\\\\\"\\\\$addToSet\\\\\\\": {\\\\\\\"meshblu.whitelists.message.received\\\\\\\": {\\\\\\\"uuid\\\\\\\": \\\\\\\"$FORWARDER_UUID\\\\\\\"}}}\\\" ./tmp/endoskeleton-meshblu.json\\n\\n\\necho \\\"Subscribing Forwarder to it's own messages\\\"\\nmeshblu-util subscription-create -e $FORWARDER_UUID -s $FORWARDER_UUID -t message.received ./tmp/forwarder-meshblu.json\\n\\necho \\\"Subscribing Forwarder to Endoskeleton's received messages\\\"\\nmeshblu-util subscription-create -e $ENDOSKELETON_UUID -s $FORWARDER_UUID -t message.received ./tmp/forwarder-meshblu.json\\n\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Messaging\"\n}\n[/block]\nOnce the configuration script above is run, sending any message to the Endoskeleton device will result in a message forwarded to the service url. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#!/usr/bin/env bash\\n\\necho \\\"Ringing that doorbell!\\\"\\nENDOSKELETON_UUID=$(jq -r '.uuid' < ./tmp/endoskeleton-meshblu.json)\\n\\nmeshblu-util message -d \\\\\\n\\\"{\\\\\\\"devices\\\\\\\": [\\\\\\\"$ENDOSKELETON_UUID\\\\\\\"], \\\\\\\"payload\\\\\\\": \\\\\\\"Hey, Endoskeleton. Somebody's at the door. Do something about it.\\\\\\\"}\\\" \\\\\\n./tmp/doorbell-meshblu.json\\n\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nRunning the configuration script with a [Request Bin](http://requestb.in/) url will result in a post that looks like:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/JKOyyDnOTZinrLNS2K2L_Screen%20Shot%202016-05-13%20at%203.46.57%20PM.png\",\n        \"Screen Shot 2016-05-13 at 3.46.57 PM.png\",\n        \"2698\",\n        \"1076\",\n        \"#929249\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nNote the bearer token in the Authorization header of the request. This can be used to authenticate with Meshblu as the device that received the message.","excerpt":"","slug":"creating-manually","type":"basic","title":"Creating Manually"}
[block:api-header] { "type": "basic", "title": "Setting up Data Forwarder Manually" } [/block] Below is an example of how to set up a data forwarder using [Meshblu Utility](https://meshblu.readme.io/docs/meshblu-utility) and [jq](https://stedolan.github.io/jq/). It is based on the scenario described in [What They Are](doc:what-are-meshblu-data-forwarders) [block:api-header] { "type": "basic", "title": "Configuration" } [/block] [block:code] { "codes": [ { "code": "#!/usr/bin/env bash\n\nSERVICE_URL=$1\n\nif [ -z \"$SERVICE_URL\" ]; then\n echo \"usage: ./example-data-forwarder.sh <SERVICE_URL>\"\n exit 1;\nfi\n\n\nmkdir ./tmp\n\necho \"creating Endoskeleton device\"\nmeshblu-util register -d '{\"type\": \"endoskeleton\"}' > ./tmp/endoskeleton-meshblu.json\nENDOSKELETON_UUID=$(cat ./tmp/endoskeleton-meshblu.json | jq -r '.uuid')\nENDOSKELETON_TOKEN=$(cat ./tmp/endoskeleton-meshblu.json | jq -r '.token')\necho \"endoskeleton is: $ENDOSKELETON_UUID\"\n\n\necho \"creating Doorbell device\"\nmeshblu-util register -d '{\"type\": \"doorbell\"}' > ./tmp/doorbell-meshblu.json\nDOORBELL_UUID=$(cat ./tmp/doorbell-meshblu.json | jq -r '.uuid')\nDOORBELL_TOKEN=$(cat ./tmp/doorbell-meshblu.json | jq -r '.token')\necho \"doorbell is: $DOORBELL_UUID\"\n\necho \"adding Doorbell to Endoskeleton's message.from whitelist\"\nmeshblu-util update -p -d \"{\\\"\\$addToSet\\\": {\\\"meshblu.whitelists.message.from\\\": {\\\"uuid\\\": \\\"$DOORBELL_UUID\\\"}}}\" ./tmp/endoskeleton-meshblu.json\n\necho \"creating Forwarder device\"\nmeshblu-util register -d '{\"type\": \"forwarder\"}' > ./tmp/forwarder-meshblu.json\nFORWARDER_UUID=$(cat ./tmp/forwarder-meshblu.json | jq -r '.uuid')\nFORWARDER_TOKEN=$(cat ./tmp/forwarder-meshblu.json | jq -r '.token')\necho \"forwarder is: $FORWARDER_UUID\"\n\necho \"adding webhook to forwarder\"\nmeshblu-util create-hook -t message.received -U $SERVICE_URL ./tmp/forwarder-meshblu.json\n\necho \"adding forwarder to Endoskeleton's message.received whitelist\"\nmeshblu-util update -p -d \"{\\\"\\$addToSet\\\": {\\\"meshblu.whitelists.message.received\\\": {\\\"uuid\\\": \\\"$FORWARDER_UUID\\\"}}}\" ./tmp/endoskeleton-meshblu.json\n\n\necho \"Subscribing Forwarder to it's own messages\"\nmeshblu-util subscription-create -e $FORWARDER_UUID -s $FORWARDER_UUID -t message.received ./tmp/forwarder-meshblu.json\n\necho \"Subscribing Forwarder to Endoskeleton's received messages\"\nmeshblu-util subscription-create -e $ENDOSKELETON_UUID -s $FORWARDER_UUID -t message.received ./tmp/forwarder-meshblu.json\n", "language": "shell" } ] } [/block] [block:api-header] { "type": "basic", "title": "Messaging" } [/block] Once the configuration script above is run, sending any message to the Endoskeleton device will result in a message forwarded to the service url. [block:code] { "codes": [ { "code": "#!/usr/bin/env bash\n\necho \"Ringing that doorbell!\"\nENDOSKELETON_UUID=$(jq -r '.uuid' < ./tmp/endoskeleton-meshblu.json)\n\nmeshblu-util message -d \\\n\"{\\\"devices\\\": [\\\"$ENDOSKELETON_UUID\\\"], \\\"payload\\\": \\\"Hey, Endoskeleton. Somebody's at the door. Do something about it.\\\"}\" \\\n./tmp/doorbell-meshblu.json\n", "language": "shell" } ] } [/block] Running the configuration script with a [Request Bin](http://requestb.in/) url will result in a post that looks like: [block:image] { "images": [ { "image": [ "https://files.readme.io/JKOyyDnOTZinrLNS2K2L_Screen%20Shot%202016-05-13%20at%203.46.57%20PM.png", "Screen Shot 2016-05-13 at 3.46.57 PM.png", "2698", "1076", "#929249", "" ] } ] } [/block] Note the bearer token in the Authorization header of the request. This can be used to authenticate with Meshblu as the device that received the message.