{"_id":"59c0245a5dc43e003a1bdc23","project":"568bdc1483d2061900d86cdc","version":{"_id":"59a72290d61777001b6c42c3","project":"568bdc1483d2061900d86cdc","__v":19,"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"],"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":7,"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\n![tutorial step 1](https://droplit.box.com/shared/static/b4of85535il76wonz41l7af039azx9pe.png)\n\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\n![tutorial step 2](https://droplit.box.com/shared/static/kiz74lcnihac256jj2f5e5a0lws6syf4.png)\n\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    \"name\":\"BinarySwitch\",\n    \"properties\": {\n        \"switch\": {\n            \"values\": [\"on\", \"off\"]\n        }\n    },\n    \"methods\": {\n        \"switchOn\": {\n            \"description\": \"Turn a switch on.\"\n        },\n        \"switchOff\": {\n            \"description\": \"Turn a switch off.\"\n        }\n    }\n}\n```\nCreate a “BinarySwitch” service class by copying the above JSON into the portal.\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\n![tutorial step 3](https://droplit.box.com/shared/static/onuxkldjgixgpyk0ss4n44aq9v38efr9.png)\n\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\n![tutorial step 4](https://droplit.box.com/shared/static/cuqdh3zitekndsm0h5igc37tzc1h0czu.png)\n\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\n![tutorial step 5](https://droplit.box.com/shared/static/yn8aofoqsnzna0no7cgh74wknyhb87a5.png)\n\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```\n`droplit ecosystem select` + ECOSYSTEM-ID\n`droplit 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![tutorial step 6](https://droplit.box.com/shared/static/ccmvxdp1mjedzakew3cgu5q9fcqj9e7p.png)\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. ![tutorial step 1](https://droplit.box.com/shared/static/b4of85535il76wonz41l7af039azx9pe.png) # 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. ![tutorial step 2](https://droplit.box.com/shared/static/kiz74lcnihac256jj2f5e5a0lws6syf4.png) 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": { "values": ["on", "off"] } }, "methods": { "switchOn": { "description": "Turn a switch on." }, "switchOff": { "description": "Turn a switch off." } } } ``` Create a “BinarySwitch” service class by copying the above JSON into the portal. 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. ![tutorial step 3](https://droplit.box.com/shared/static/onuxkldjgixgpyk0ss4n44aq9v38efr9.png) # 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. ![tutorial step 4](https://droplit.box.com/shared/static/cuqdh3zitekndsm0h5igc37tzc1h0czu.png) 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. ![tutorial step 5](https://droplit.box.com/shared/static/yn8aofoqsnzna0no7cgh74wknyhb87a5.png) 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` ![tutorial step 6](https://droplit.box.com/shared/static/ccmvxdp1mjedzakew3cgu5q9fcqj9e7p.png) # 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.