{"_id":"582789acbe5c080f00a5a855","category":{"_id":"582789abbe5c080f00a5a7ff","version":"582789aabe5c080f00a5a7fe","project":"568bdc1483d2061900d86cdc","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-01-05T15:07:02.028Z","from_sync":false,"order":0,"slug":"documentation","title":"Getting Started"},"version":{"_id":"582789aabe5c080f00a5a7fe","__v":10,"project":"568bdc1483d2061900d86cdc","createdAt":"2016-11-12T21:29:14.915Z","releaseDate":"2016-11-12T21:29:14.915Z","categories":["582789abbe5c080f00a5a7ff","582789abbe5c080f00a5a800","582789abbe5c080f00a5a801","582789abbe5c080f00a5a802","582789abbe5c080f00a5a803","582789abbe5c080f00a5a804","582789abbe5c080f00a5a805","582789abbe5c080f00a5a806","582789abbe5c080f00a5a807","582789abbe5c080f00a5a808","5827ea984ca29e0f00137a9e","583df597887db62f00644283","583df5d9c622791900e78da5","5845cd8763c11b250037967d","5845d13063c11b2500379681","5859e859e3306d1900126725","587aeb9a01cf3a0f008359eb","587c422af45e2d0f005e200d","587d84dc82f6f30f004ceee5"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"beta2","version_clean":"0.0.0","version":"0"},"parentDoc":null,"__v":0,"project":"568bdc1483d2061900d86cdc","user":"56f0260ed386ce0e008e99da","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-08-27T23:17:29.400Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"There are two ways to control devices in Droplit:\n- Conduits: cloud-to-cloud-to-device\n- Edge SDK: cloud-to-hub-to-device\n\nThe Droplit.io Edge SDK is typically run from an embedded device such as a gateway or hub, and is the software that creates a connection to the Droplit.io cloud to control devices on the local network. In this tutorial, we’re going to learn how to deploy the edge server whether on a Raspberry Pi or even your computer. \n\nSpecifically, here’s what we’re going to do:\n1. Set up your environment\n2. Download everything\n3. Configure it\n4. Build it\n5. Run it\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Configuring your Environment\"\n}\n[/block]\nYou can download and install everything directly to your computer, or you can use a Raspberry Pi. Whatever your choice, make sure your device is connected to the local network, we recommend a wired connection for best results. \n\nCurrently we support these platforms:\n - Raspberry Pi 3 (Raspbian Lite 2016-05-27)\n - Windows 10 on desktop\n - macOS 10.11.6\n - Debian 8 on desktop\n - Openwrt\n - DDWRT\n\nInstall Git to repo download source.\n\n**For a Rapsberry Pi:**\n\n`sudo raspi-config`\n\nGo down to boot options and change it to “B2 Console Autologin” This will make it so the user auto logins and then the edge server will start properly.\n\n`sudo apt-get install git`\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Install Node.js\"\n}\n[/block]\n**For Windows and Linux**\nIn the terminal, from the home directory (`cd ~`), run the following commands:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"wget https://nodejs.org/dist/v6.4.0/node-v6.4.0-linux-arm64.tar.xz\\ntar -xvf node-v6.4.0-linux-arm64.tar.xz\\ncd node-v6.4.0-linux-arm64\\nsudo cp -R * /usr/local/\\nsudo chown -R `whoami` ~/.npm\\nsudo chown -R `whoami` /usr/local/lib/node_modules\\nsudo chown -R `whoami` /usr/local\\ncd ..\\nrm –rf node-v6.4.0-linux-arm64\\nrm node-v6.4.0-linux-arm64.tar.xz\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n*This downloads, unpacks and installs NodeJs. It also fixes permission issues to allow for npm install without root permissions*\n\n**For Mac**\nInstall X-Code \nhttps://itunes.apple.com/us/app/xcode/id497799835?mt=12\n\nInstall Homebrew\n`/usr/bin/ruby -e \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\"`\n\nCheck to make sure everything is installed:\n`xcode-select -p`\n\nIf you see:\n/applications/xcode.app/contents/developer \n\nThen the full xcode package is installed\n\nNow, for Node.js:\nhttps://nodejs.org/en/ \nDownload the LTS version\n\nWhen asked where to unpackage it make sure its putting this in `/usr/local`\n\nOnce Node is installed, in the terminal:\n`echo $PATH`\n\nAnd the `usr/local/bin` directory should be listed in the output\n\n**Install global NPM dependencies**\n`npm install -g ntypescript gulp typings`\n(note: you may have to `sudo` this)\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Download Droplit.io Edge\"\n}\n[/block]\n`git clone https://github.com/droplit/droplit.io-edge --depth 1`\n\n**Install project dependencies**\n\nFrom the project root folder (`cd ~/droplit.io-edge`)\n\n`npm install`\n\nThen you can install all the node modules and link the dependent projects with a single command.\n\n`gulp setup`\n\nIf you get an error, try\n`sudo gulp setup`\n\nIf you still get an error, “gulp” may have been installed in in your local folder (/usr/YOURNAME/node_modules) instead of the global NPM folder (/usr/local/node_modules).\n \nTo fix, see where its installed:\n    `npm root`\nand move it:\n    `npm config set prefix /usr/local`\n    \nre-install:\n    `sudo npm install -g gulp`\n    \ncheck location\n    `npm root -g`\n    \nAnd you should have the correct folder: /usr/local/lib/node_modules\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Local Configuration\"\n}\n[/block]\nNow we just need to do some light configuration to get your edge server working properly. \n`cd ~`\nGo to `droplit.io-edge/projects/droplit-edge` \nCopy the file named `localsettings.master.json` and\nRename it `localsettings.json`\nThis is what the file should look like:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\n{\\n    \\\"transport\\\": {\\n        \\\"host\\\": \\\"wss://edge-ws.droplit.io/edge\\\"\\n    },\\n    \\\"ecosystemId\\\": \\\"INSERT_YOUR_ECOSYSTEMID_HERE\\\",\\n    \\\"plugins\\\": {\\n        \\\"droplit-plugin-philips-hue\\\": {\\n            \\\"enabled\\\": true\\n        },\\n        \\\"droplit-plugin-lifx\\\": {},\\n        \\\"droplit-plugin-sonos\\\": {},\\n        \\\"droplit-plugin-wemo\\\": {}\\n    }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nLet's tie your edge server to your ecosystem. To do that, go to the dev portal http://portal.droplit.io and copy your `ecosystemId` into the ecosystemId value into your `localsettings.json` file.\n\nYou’ll notice these plugins are available:\n* droplit-plugin-lifx\n* droplit-plugin-philps-hue\n* droplit-plugin-sonos\n* droplit-plugin-wemo\n* droplit-plugin-voyager\n\n*stay tuned for more bombtastic plugins*\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Building\"\n}\n[/block]\nYou can run a build with linting any time by running:\n`gulp build`\n\nIf you want to build and continuously watch for changes, you can simply run:\n`gulp watch`\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Running\"\n}\n[/block]\nTo run the edge, just open a terminal, navigate to the project root (`cd ~/droplit.io-edge`)\n\nIf you want to see the debug logs of the edge running in your environment:\nUnix/Linux: `export DEBUG=droplit:*`\nWindows: `set DEBUG=droplit:*`\n\n\nrun: `node droplit-edge`\n\nYour Droplit edge server is now running! If you have any of the aforementioned devices on your local network, they will be auto discovered and accessible in your default environment\n\n\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/c1e431d-Screen_Shot_2016-08-27_at_2.58.42_PM.png\",\n        \"Screen Shot 2016-08-27 at 2.58.42 PM.png\",\n        2880,\n        1569,\n        \"#18c08e\"\n      ]\n    }\n  ]\n}\n[/block]\nThe labels for the devices will not be of much help, but the service classes attributed to the device are pretty solid tip-offs as to what is what. \n\nYou can directly manipulate the states of your devices right here from the portal or in the command line. From turning lights on and off, to changing the volume and music on a SONOS, to changing brightness and color temperature, and more.\n\nIt’s blazing fast—here’s a video of it in action: https://youtu.be/JEfuwwzX050","excerpt":"","slug":"deploy-an-edge-server","type":"basic","title":"Control smart devices at the Edge"}

Control smart devices at the Edge


There are two ways to control devices in Droplit: - Conduits: cloud-to-cloud-to-device - Edge SDK: cloud-to-hub-to-device The Droplit.io Edge SDK is typically run from an embedded device such as a gateway or hub, and is the software that creates a connection to the Droplit.io cloud to control devices on the local network. In this tutorial, we’re going to learn how to deploy the edge server whether on a Raspberry Pi or even your computer. Specifically, here’s what we’re going to do: 1. Set up your environment 2. Download everything 3. Configure it 4. Build it 5. Run it [block:api-header] { "type": "basic", "title": "Configuring your Environment" } [/block] You can download and install everything directly to your computer, or you can use a Raspberry Pi. Whatever your choice, make sure your device is connected to the local network, we recommend a wired connection for best results. Currently we support these platforms: - Raspberry Pi 3 (Raspbian Lite 2016-05-27) - Windows 10 on desktop - macOS 10.11.6 - Debian 8 on desktop - Openwrt - DDWRT Install Git to repo download source. **For a Rapsberry Pi:** `sudo raspi-config` Go down to boot options and change it to “B2 Console Autologin” This will make it so the user auto logins and then the edge server will start properly. `sudo apt-get install git` [block:api-header] { "type": "basic", "title": "Install Node.js" } [/block] **For Windows and Linux** In the terminal, from the home directory (`cd ~`), run the following commands: [block:code] { "codes": [ { "code": "wget https://nodejs.org/dist/v6.4.0/node-v6.4.0-linux-arm64.tar.xz\ntar -xvf node-v6.4.0-linux-arm64.tar.xz\ncd node-v6.4.0-linux-arm64\nsudo cp -R * /usr/local/\nsudo chown -R `whoami` ~/.npm\nsudo chown -R `whoami` /usr/local/lib/node_modules\nsudo chown -R `whoami` /usr/local\ncd ..\nrm –rf node-v6.4.0-linux-arm64\nrm node-v6.4.0-linux-arm64.tar.xz", "language": "text" } ] } [/block] *This downloads, unpacks and installs NodeJs. It also fixes permission issues to allow for npm install without root permissions* **For Mac** Install X-Code https://itunes.apple.com/us/app/xcode/id497799835?mt=12 Install Homebrew `/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"` Check to make sure everything is installed: `xcode-select -p` If you see: /applications/xcode.app/contents/developer Then the full xcode package is installed Now, for Node.js: https://nodejs.org/en/ Download the LTS version When asked where to unpackage it make sure its putting this in `/usr/local` Once Node is installed, in the terminal: `echo $PATH` And the `usr/local/bin` directory should be listed in the output **Install global NPM dependencies** `npm install -g ntypescript gulp typings` (note: you may have to `sudo` this) [block:api-header] { "type": "basic", "title": "Download Droplit.io Edge" } [/block] `git clone https://github.com/droplit/droplit.io-edge --depth 1` **Install project dependencies** From the project root folder (`cd ~/droplit.io-edge`) `npm install` Then you can install all the node modules and link the dependent projects with a single command. `gulp setup` If you get an error, try `sudo gulp setup` If you still get an error, “gulp” may have been installed in in your local folder (/usr/YOURNAME/node_modules) instead of the global NPM folder (/usr/local/node_modules). To fix, see where its installed: `npm root` and move it: `npm config set prefix /usr/local` re-install: `sudo npm install -g gulp` check location `npm root -g` And you should have the correct folder: /usr/local/lib/node_modules [block:api-header] { "type": "basic", "title": "Local Configuration" } [/block] Now we just need to do some light configuration to get your edge server working properly. `cd ~` Go to `droplit.io-edge/projects/droplit-edge` Copy the file named `localsettings.master.json` and Rename it `localsettings.json` This is what the file should look like: [block:code] { "codes": [ { "code": "\n{\n \"transport\": {\n \"host\": \"wss://edge-ws.droplit.io/edge\"\n },\n \"ecosystemId\": \"INSERT_YOUR_ECOSYSTEMID_HERE\",\n \"plugins\": {\n \"droplit-plugin-philips-hue\": {\n \"enabled\": true\n },\n \"droplit-plugin-lifx\": {},\n \"droplit-plugin-sonos\": {},\n \"droplit-plugin-wemo\": {}\n }\n}", "language": "json" } ] } [/block] Let's tie your edge server to your ecosystem. To do that, go to the dev portal http://portal.droplit.io and copy your `ecosystemId` into the ecosystemId value into your `localsettings.json` file. You’ll notice these plugins are available: * droplit-plugin-lifx * droplit-plugin-philps-hue * droplit-plugin-sonos * droplit-plugin-wemo * droplit-plugin-voyager *stay tuned for more bombtastic plugins* [block:api-header] { "type": "basic", "title": "Building" } [/block] You can run a build with linting any time by running: `gulp build` If you want to build and continuously watch for changes, you can simply run: `gulp watch` [block:api-header] { "type": "basic", "title": "Running" } [/block] To run the edge, just open a terminal, navigate to the project root (`cd ~/droplit.io-edge`) If you want to see the debug logs of the edge running in your environment: Unix/Linux: `export DEBUG=droplit:*` Windows: `set DEBUG=droplit:*` run: `node droplit-edge` Your Droplit edge server is now running! If you have any of the aforementioned devices on your local network, they will be auto discovered and accessible in your default environment [block:image] { "images": [ { "image": [ "https://files.readme.io/c1e431d-Screen_Shot_2016-08-27_at_2.58.42_PM.png", "Screen Shot 2016-08-27 at 2.58.42 PM.png", 2880, 1569, "#18c08e" ] } ] } [/block] The labels for the devices will not be of much help, but the service classes attributed to the device are pretty solid tip-offs as to what is what. You can directly manipulate the states of your devices right here from the portal or in the command line. From turning lights on and off, to changing the volume and music on a SONOS, to changing brightness and color temperature, and more. It’s blazing fast—here’s a video of it in action: https://youtu.be/JEfuwwzX050