<p>IoT solutions have many moving parts. Devices, connectivity, device management, and data services. So we've taken all of these components, wrapped them all up into one unified environment, and provided them for you to try out. We're going to take a look at one of our core data services, scriptr.</p>
<h2 id="scriptr">scriptr</h2>
<p>Scriptr, on it's own, is a cloud-based javascript web API framework. It gives you an interface to write some javascript code, and then makes that available at an HTTP endpoint in the cloud. At wot.io, we've taken that interface and wrapped it into our environment. So now, any messages that your devices send can automatically get parsed in scriptr, giving you a tool to create your business logic out of those messages.</p>
<h4 id="gettingstarted">Getting Started</h4>
<p>To get started, check out the tutorial on getting the Philips Hue system integrated with wot.io <a href="/phillips-hue-on-wot-io">here</a>. Once you have that running, get the path for the Blink Demo from the email you received when signing up, or <a href="http://wot.io/about-wot-io/contact-us/">contact us</a> for help.</p>
<h4 id="demooneblink">Demo one - blink</h4>
<p>In this demo, we're going to use scriptr to automatically turn on and off a lightbulb.</p>
<p>In your scriptr account, create a new script and call it <code>connectedhome/blink</code>. To find out how, please refer to the <a href="https://www.scriptr.io/documentation#documentation-2-GettingStarted">scriptr documentation</a>. Then type in the following code and save it:</p>
<pre><code>var lights = JSON.parse(request.rawBody).data[0].lights; // Retrieve the data that we are putting onto the wot.io bus
return '["phue","set_light",3,"on",' + !(lights["3"]["state"]["on"]) + ']'; // Send a message that either turns off the light if it is on or vice versa.
</code></pre>
<p>Now, run your Philips Hue integration from the previous step, using the path from the email</p>
<pre><code>python hue.py <bridge ip> <wot path>
</code></pre>
<p>And that's it! Your light bulb should now turn on and off every few seconds. If you want to adjust the speed, simply change the delay in <code>hue.py</code>.</p>
<h4 id="demotwocolorchange">Demo two - color change</h4>
<p>Let's try another simple script, where the color of the bulb changes. This time, create a script called <code>connectedhome/changecolor</code>, type in the following code, and save it:</p>
<pre><code>return '["phue","set_light",3,"hue",' + Math.floor((Math.random()*65000)) + ']'; // Send a command to change the light bulb color
</code></pre>
<p>Connect with the <code>hue.py</code> script again, and voila! That's all that it takes to create a production-ready deployment. There's no need to set up any servers or anything else.</p>
Home Integration Tutorial
Jun 2015/ Posted By: wotio team