Posts Tagged PHP

Integrating Nest with Amazon Echo (Alexa)

I got an echo the other day and I’m excited about the functionality – especially seeing as it connected directly to my wink hub, however it didn’t connect to my nest thermostat, so I got a bit discouraged…However after a bit of trial and error as well as a few scripts on the internet, I’m happy to say, my Nest is now connected to the Echo. I can set the temperature, turn it up, turn it down (in three degree increments) or just check the temperature it is. How did I do it? Pretty simple…Here’s the prerequisites

Now that we’ve got all of that sorted, let’s dig in.

Go ahead and create the Azure Web App and in the root directory, copy nest.class.php from GitHub there. After you’ve created that file, go ahead and create an index.php (maybe you want to bury the two files a directory deeper than the root for “additional” security)…

Once you’ve created index.php add the following code to it (note you’ll need your username and password):

<?php
require_once(‘nest.class.php’);
define(‘USERNAME’, ‘mynestuser@gmail.com’);
define(‘PASSWORD’, ‘my-nest-password’);
$nest = new Nest();
$nest_detail = $nest->getDeviceInfo();
$EchoJArray = json_decode(file_get_contents(‘php://input’));
$intent = $EchoJArray->request->intent->name;
$ct = $nest_detail->current_state->temperature;
if ($intent == “NestSetTempIntent”) {
$new_temp = $EchoJArray->request->intent->slots->temp->value;
$nest->setTargetTemperature($new_temp);
$feedback = “I went ahead and set the temperature to $new_temp”;
} else if ($intent == “NestCoolDownIntent”) {
$new_temp = $nest_detail->current_state->temperature – 3;
$nest->setTargetTemperature($new_temp);
$feedback = “I went ahead and set the temperature to $new_temp”;
} else if ($intent == “NestWarmUpIntent”) {
$new_temp = $nest_detail->current_state->temperature + 3;
$nest->setTargetTemperature($new_temp);
$feedback = “I went ahead and set the temperature to $new_temp”;
}
else {
$feedback = “Currently the temperature is ” . $nest_detail->current_state->temperature . ” degrees.”;
}
header(‘Content-Type: application/json;charset=UTF-8’);
$text = ‘{
“version” : “1.0”,
“response” : {
“outputSpeech” : {
“type” : “PlainText”,
“text” : “‘. $feedback .'”
},
“card”: {
“type”: “Simple”,
“title”: “Nest Integration”,
“content”: “‘ . $feedback . ‘”
},
“shouldEndSession” : true
}
}’;
header(‘Content-Length: ‘ . strlen($text));
echo $text;
?>

After you have those two files in place, you’re ready to head over to the developer portal and create a new “Skill” for Alexa and the Echo. To do this:

  • log in
  • Click on Alexa
  • Click on “Get Started” below the Alexa Skills Kit
  • Click “Add A New Skill”
  • For the Name simply enter “Nest Controller”
  • For the Invocation Name I used “nest”
  • For version I used “1.0”
  • Endpoint is the URL to the Azure website I had created (https://webappname.azurewebsites.net/nest/)
  • Click Next
  • For the Intent Schema, enter:

{
“intents”: [
{
“intent”: “NestCoolDownIntent”,
“slots”: []
},
{
“intent”: “NestWarmUpIntent”,
“slots”: []
},
{
“intent”: “NestInquireIntent”,
“slots”: []
},
{
“intent”: “NestSetTempIntent”,
“slots”: [
{
“name”: “temp”,
“type”: “NUMBER”
}
]
}
]
}

  • For sample utterances enter:

NestSetTempIntent set temperature to {seventy four|temp}
NestSetTempIntent set temperature to {eighty one|temp} degrees
NestSetTempIntent set to {sixty one|temp}
NestSetTempIntent set to {eighty one|temp} degrees
NestSetTempIntent set {sixty one|temp}
NestSetTempIntent set {eighty one|temp} degrees
NestSetTempIntent set thermostat to {sixty one|temp}
NestSetTempIntent set thermostat to {eighty one|temp} degrees

NestCoolDownIntent turn the temperature down
NestCoolDownIntent temperature down
NestCoolDownIntent I’m too warm
NestCoolDownIntent I’m burning up
NestCoolDownIntent burning up
NestCoolDownIntent i’m too hot
NestCoolDownIntent too hot
NestCoolDownIntent cool down
NestCoolDownIntent cool the house down
NestCoolDownIntent turn the thermostat down
NestCoolDownIntent thermostat down

NestWarmUpIntent turn the temperature up
NestWarmUpIntent temperature up
NestWarmUpIntent I’m cold
NestWarmUpIntent I am cold
NestWarmUpIntent I’m too cold
NestWarmUpIntent it’s cold
NestWarmUpIntent its cold
NestWarmUpIntent it is too cool
NestWarmUpIntent it is too cold
NestWarmUpIntent it is freezing
NestWarmUpIntent it’s freezing
NestWarmUpIntent it is chilly
NestWarmUpIntent its chilly
NestWarmUpIntent warm up the house

NestInquireIntent current temperature
NestInquireIntent what’s the temperature
NestInquireIntent what’s the current temperature
NestInquireIntent what’s the temperature inside
NestInquireIntent what’s the temperature indoors
NestInquireIntent what is the temperature
NestInquireIntent what is the current temperature
NestInquireIntent what is the temperature inside
NestInquireIntent what is the temperature indoors
NestInquireIntent why am I freezing
NestInquireIntent why am I burning up

  • Click Save
  • Click Next
  • For SSL Certificate choose the middle “My development endpoint is a subdomain …” (All *.azurewebsites.net addresses have an https wildcard certificate associated with them)
  • That’s it!

Now it should show up in your skills list on your Echo App (iPhone, Android or even on https://echo.amazon.com/). To invoke any of the commands simply ask or tell Alexa what we listed above…For example:

  • Alexa tell nest turn the temperature down
  • Alexa ask nest what is the temperature inside
  • Alexa tell nest set temperature to 68 degrees
  • Alexa tell nest its chilly

Feel free to add more utterances based on the slot of what you’d like her to do. If you want to turn the temperature down, simply prefix your “alexa tell/ask nest” command with NestCoolDownIntent in the utterances. To turn it up, simply use NestWarmUpIntent .

Have fun!

Tags: , , ,

Installing MRTG and RRD in Azure on Windows Server 2012R2

It’s been a while since I wrote anything down, albeit I’ve been keeping very busy. This week though, I’ve been digging through lots of articles and such and it triggered a thought in my mind…If I document what I do publically, I can always go back and look at it (I refer to my booting an OS from a USB article all too often) and also I can share my experiences with the broader world!

Today’s post as the title alludes to takes us down the MRTG route in the Azure world. First off, MRTG is a great program that was written many years back by a guy named Tobi Oetiker. The latest release is 2.17.4 which was released in January 2012, yet it’s still a great tool. The simple idea behind it – you run a script every 5 minutes that takes two input variables and then it graphs them. The most common use for this is routers – in and out packets – hence the name MRTG (Multi-Router Traffic Grapher). However, you can do just about anything you want with MRTG. One of the things I do with it is simply plot the same number twice in some instances which gives a great effect to the number I’m displaying (say the number of active helpdesk calls).

At any rate, with the ability to go Hybrid Cloud, the premise of this article is to explain how to get it working in Azure on Windows 2012R2 (sure you can do the same on-prem too)…If you’ve got an MSDN account, you’ve got monthly credit to use too, that’s what I do with mine :)  So, let’s get going:

1. Create a new VM in azure (New -> Compute -> Virtual Machine -> Quick Create)

Windows Server 2012R2 Datacenter – Basic A0 is what I went for

create-vm

2. After the VM Builds, log in and patch it

3. Turn off IE Enhanced Security (for the time being) – Server Manger -> Local Server -> IE Enhanced Security

4. Download the latest version of ActivePerl

5. Run the ActiveState installer and install to c:\perl64 (the default directory)

6. Download the latest MRTG Windows .zip file

7. Unzip the package to c:\

8. Rename mrtg-2.17.4 it to mrtg

c mrtg

9. Download the latest WebPI

10. Run the Web Platform Installer and choose to install PHP 5.6.0 (Note this will install 19 “components”)

11. Download the x86 version of the Visual C++ Redistributable 2012 (even if you have an x64 install use the x86 version of the C++ package because PHP will run x86) Install PHP 5.6.0 (optional)

12. Install the Visual C++ Redist

13. Download the PECL library for RRD (ensure it’s 5.6 Non Thread Safe (NTS) x86)

14. Copy the following .dll files in to to c:\program files(x86)\php\v5.6\ cairo, expat, fontconfig, gobject-2, pango-1, pangocairo-1, pangoft2-1, pangowin32-1, pixman-1, rrdlib

standard dlls

15. Copy php_rrd.dll in to c:\program files(x86)\php\v5.6\ext\

16. Open c:\program files(x86)\php\v5.6\php.ini and add the following to the very bottom of the file “extension=php_rrd.dll”

php rrd dll

17. Open notepad and create a file that has “<?php phpinfo();?>” in it (sans the “‘s)

phpinfo

18. Save this file to c:\inetpub\wwwroot as “about.php” (make sure you put “‘s around the file name so notepad saves the .php extension)

 save as

19. Open IE and navigate to http://localhost/about.php to see it’s installed correctly

php about screen

20. Scroll further down to also see that the RRD library is enabled

rrd lib enabled

21. Open a command prompt

22. Change the directory to c:\mrtg\bin

23. run “perl mrtg”

perl mrtg

If MRTG is installed correctly, you’ll see the program disclaimer.

Voila!

The next article will talk about what you can do with MRTG and PHP together. Hope you enjoyed!

Tags: , , , ,

Is SQL 2008 Faster? Not Sure Yet

So, is it any faster?  Not sure.  Does it take longer to install?  Yes.  Does it seem better OOBE (Out Of Box Experice)?  Yes.

Today I’ve installed SQL 2008 on a Windows Server 2008 install with IIS and PHP to try and do some development work.  I’m interested in the performance.  So far, I can’t say as I’m disappointed, but watch this space for further results…

Tags: , , ,