{"_id":"59c0245a5dc43e003a1bdc23","project":"568bdc1483d2061900d86cdc","version":{"_id":"59a72290d61777001b6c42c3","project":"568bdc1483d2061900d86cdc","__v":29,"createdAt":"2017-08-30T20:39:44.453Z","releaseDate":"2017-08-30T20:39:44.453Z","categories":["59a7236e3fe4d90025117c10","59a72eb6cb0db3001b84cfe2","59a734eb757d030019b85af8","59c0243b1b2d07001a9d2b76","59c035e42126e10028effb12","59c06c40df5b3c0010584a13","59c1a5852cabe5002641a3e7","59c2fb00b2b45c0010b7a3d7","59c32ceb9aea850010ac4130","59c32e6e190c90003cb0d12f","59c33affb2b45c0010b7aa23","59c7dfa457bd8200105444dc","59c7e975c50cf30010d712a0","59cffdef0cd4dd0010294d54","59d0622ca91a810032c8f60c","59d06733c1aec60026253065","59d174d44ac471001a07b123","59d5a5e323e6e800103defb2","59ecf1d8ed507c001c52b255","59f76fef8581dc0010593e6f","5a0c003680a35b0012c35db0","5a8358722e78660075e45f42","5a846645b5ec3a001203517e","5b258091bc7a6700033b9cb5","5b26e48e024807000315a740","5b44edff3306680003663f5c","5b468abd3d4a9e0003789111","5b468d8f3dcb6a0003c6e374","5b47b0b93d4a9e000378a33a"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"0.0.0","version":"0"},"category":{"_id":"59c0243b1b2d07001a9d2b76","project":"568bdc1483d2061900d86cdc","version":"59a72290d61777001b6c42c3","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-09-18T19:53:31.813Z","from_sync":false,"order":8,"slug":"tutorial","title":"Tutorial"},"user":"58cc41f21751ce2f003be3b7","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-09-18T19:54:02.520Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"# Overview\n\nDroplit is a cloud service that provides API-based control of connected devices. Use the following procedure to create and control a virtual device in this tutorial.\n\n1. Create a developer portal account.\n2. Define a service class.\n3. Create a virtual device.\n4. Assign the service class to the device.\n5. Directly control the virtual device in the developer portal and the command line.\n\n# Create a developer portal account.\n\nGo to the [Droplit portal](http://portal.droplit.io) to create a free developer account and login.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/3889752-dashboard.png\",\n        \"dashboard.png\",\n        1280,\n        720,\n        \"#1f1f23\"\n      ],\n      \"caption\": \"The dashboard of the Droplit portal.\"\n    }\n  ]\n}\n[/block]\n# Define a service class.\n\nThe goal of this tutorial is to create and control a virtual light bulb. Therefore, the service class must define what the virtual light bulb does. The most basic thing a light bulb does is to turn on and off: a switch. Go to the “Service Classes” area in the portal to begin defining a service class.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/ccaf01e-serviceClasses.png\",\n        \"serviceClasses.png\",\n        1280,\n        720,\n        \"#1c1c1d\"\n      ],\n      \"caption\": \"The \\\"service classes\\\" tab on the Droplit portal. No custom classes are defined, but several preconstructed \\\"Libary Service Classes\\\" are provided.\"\n    }\n  ]\n}\n[/block]\nA simple version of a binary switch, which turns on and off, could be defined with the following service class. The class defines a service called “BinarySwitch”. It contains a property called “swtich”, which can have one of two values, “on” or “off”. The class also defines two methods: “switchOn”, which turns on the switch, and “switchOff”, which turns off the switch.\n```\n{\n\t\"name\": \"BinarySwitch\",\n\t\"properties\": {\n\t\t\"switch\": {\n\t\t\t\"description\": \"On/off state of the switch\",\n\t\t\t\"enum\": [\n\t\t\t\t\"on\",\n\t\t\t\t\"off\"\n\t\t\t],\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"methods\": {\n\t\t\"switchOn\": {\n\t\t\t\"description\": \"Sets switch to on\"\n\t\t},\n\t\t\"switchOff\": {\n\t\t\t\"description\": \"Sets switch to off\"\n\t\t}\n\t}\n}\n```\n\nThe `BinarySwitch` service class is already included in the Droplit portal as a curated service class, as seen above in the list of \"Library Service Classes\".\n\nMost modern web browsers can be used to watch API requests made from the portal. Requests can also be monitored using API tools like [Fiddler](http://www.telerik.com/fiddler). The portal makes calls to the same API endpoints that are covered later in this documentation.\n\n# Create a device.\n\nGo to the “Devices” tab and create a virtual device named TestLight. Set the alias to “TestLight” in order for command line operations later in this tutorial to work properly.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/bcc3064-emptyDevices.png\",\n        \"emptyDevices.png\",\n        1280,\n        720,\n        \"#1c1c1c\"\n      ],\n      \"caption\": \"The devices tab of the Droplit portal with no devices created.\"\n    }\n  ]\n}\n[/block]\n# Assign the service class to the device.\n\nDevices are displayed in the portal along with the service classes they support. This virtual light currently does not implement any service classes. View details about the device by selecting the card which contains its information.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/a8319fe-testLight.png\",\n        \"testLight.png\",\n        1280,\n        720,\n        \"#1a1a1b\"\n      ],\n      \"caption\": \"The page for the newly created device \\\"TestLight\\\".\"\n    }\n  ]\n}\n[/block]\nSelect “Add Service”. Any service classes that have already been defined will be present in the dropdown list. Select “BinarySwitch” to associate it with the bulb.\n\n# Directly control the virtual device in the developer portal and the command line.\n\nThe virtual light bulb, “TestLight”, can now be controlled.\n\nFor the first test, set the bulb value directly in the portal. The session log will display any events that happen while on the device detail page.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/ef44616-testLight-BinarySwitch.png\",\n        \"testLight-BinarySwitch.png\",\n        1280,\n        720,\n        \"#161719\"\n      ],\n      \"caption\": \"\\\"TestLight\\\" with the \\\"BinarySwitch\\\" service class enabled.\"\n    }\n  ]\n}\n[/block]\nFor the next test, control the bulb through the command line. Login to the Droplit console by running the following command, and entering account login credentials when prompted:\n`droplit account authenticate`\n\nSelect the ecosystem and environment containing the “TestLight” by running the following commands. The ecosystem and environment IDs can be found on the portal, in the “Ecosystem” and “Environment” areas, respectively.\n```\ndroplit ecosystem select ECOSYSTEM-ID\ndroplit environment select ENVIRONMENT-ID\n```\nTurn on the “TestLight” by accessing its “BinarySwitch” service class and the class’s “switch” property. Set the property to “on”.\n\n`droplit device set TestLight BinarySwitch.switch on`\n\n# Conclusion\n\nVirtual devices can also be controlled through API calls, and these devices can be used to test application development without requiring physical devices. Physical devices, however, can be controlled in the same way as virtual devices.\n\nThis procedure can be followed to control any of the following devices:\n * Any of the Philips Hue ecosystem\n * Any of the Belkin WeMo devices (other than the crockpot)\n * Sonos speakers\n * LIFX smart bulbs\n * Venstar Voyager thermostat\n\nPlease let the developers at Droplit, in the portal chat, know how long this tutorial took to complete.","excerpt":"","slug":"droplit-system-tutorial","type":"basic","title":"Droplit System Tutorial"}

Droplit System Tutorial


# Overview Droplit is a cloud service that provides API-based control of connected devices. Use the following procedure to create and control a virtual device in this tutorial. 1. Create a developer portal account. 2. Define a service class. 3. Create a virtual device. 4. Assign the service class to the device. 5. Directly control the virtual device in the developer portal and the command line. # Create a developer portal account. Go to the [Droplit portal](http://portal.droplit.io) to create a free developer account and login. [block:image] { "images": [ { "image": [ "https://files.readme.io/3889752-dashboard.png", "dashboard.png", 1280, 720, "#1f1f23" ], "caption": "The dashboard of the Droplit portal." } ] } [/block] # Define a service class. The goal of this tutorial is to create and control a virtual light bulb. Therefore, the service class must define what the virtual light bulb does. The most basic thing a light bulb does is to turn on and off: a switch. Go to the “Service Classes” area in the portal to begin defining a service class. [block:image] { "images": [ { "image": [ "https://files.readme.io/ccaf01e-serviceClasses.png", "serviceClasses.png", 1280, 720, "#1c1c1d" ], "caption": "The \"service classes\" tab on the Droplit portal. No custom classes are defined, but several preconstructed \"Libary Service Classes\" are provided." } ] } [/block] A simple version of a binary switch, which turns on and off, could be defined with the following service class. The class defines a service called “BinarySwitch”. It contains a property called “swtich”, which can have one of two values, “on” or “off”. The class also defines two methods: “switchOn”, which turns on the switch, and “switchOff”, which turns off the switch. ``` { "name": "BinarySwitch", "properties": { "switch": { "description": "On/off state of the switch", "enum": [ "on", "off" ], "type": "string" } }, "methods": { "switchOn": { "description": "Sets switch to on" }, "switchOff": { "description": "Sets switch to off" } } } ``` The `BinarySwitch` service class is already included in the Droplit portal as a curated service class, as seen above in the list of "Library Service Classes". Most modern web browsers can be used to watch API requests made from the portal. Requests can also be monitored using API tools like [Fiddler](http://www.telerik.com/fiddler). The portal makes calls to the same API endpoints that are covered later in this documentation. # Create a device. Go to the “Devices” tab and create a virtual device named TestLight. Set the alias to “TestLight” in order for command line operations later in this tutorial to work properly. [block:image] { "images": [ { "image": [ "https://files.readme.io/bcc3064-emptyDevices.png", "emptyDevices.png", 1280, 720, "#1c1c1c" ], "caption": "The devices tab of the Droplit portal with no devices created." } ] } [/block] # Assign the service class to the device. Devices are displayed in the portal along with the service classes they support. This virtual light currently does not implement any service classes. View details about the device by selecting the card which contains its information. [block:image] { "images": [ { "image": [ "https://files.readme.io/a8319fe-testLight.png", "testLight.png", 1280, 720, "#1a1a1b" ], "caption": "The page for the newly created device \"TestLight\"." } ] } [/block] Select “Add Service”. Any service classes that have already been defined will be present in the dropdown list. Select “BinarySwitch” to associate it with the bulb. # Directly control the virtual device in the developer portal and the command line. The virtual light bulb, “TestLight”, can now be controlled. For the first test, set the bulb value directly in the portal. The session log will display any events that happen while on the device detail page. [block:image] { "images": [ { "image": [ "https://files.readme.io/ef44616-testLight-BinarySwitch.png", "testLight-BinarySwitch.png", 1280, 720, "#161719" ], "caption": "\"TestLight\" with the \"BinarySwitch\" service class enabled." } ] } [/block] For the next test, control the bulb through the command line. Login to the Droplit console by running the following command, and entering account login credentials when prompted: `droplit account authenticate` Select the ecosystem and environment containing the “TestLight” by running the following commands. The ecosystem and environment IDs can be found on the portal, in the “Ecosystem” and “Environment” areas, respectively. ``` droplit ecosystem select ECOSYSTEM-ID droplit environment select ENVIRONMENT-ID ``` Turn on the “TestLight” by accessing its “BinarySwitch” service class and the class’s “switch” property. Set the property to “on”. `droplit device set TestLight BinarySwitch.switch on` # Conclusion Virtual devices can also be controlled through API calls, and these devices can be used to test application development without requiring physical devices. Physical devices, however, can be controlled in the same way as virtual devices. This procedure can be followed to control any of the following devices: * Any of the Philips Hue ecosystem * Any of the Belkin WeMo devices (other than the crockpot) * Sonos speakers * LIFX smart bulbs * Venstar Voyager thermostat Please let the developers at Droplit, in the portal chat, know how long this tutorial took to complete.