Hey guys,
I searched the forum to see if anyone had done this, and I am sure someone has, though I did not find anything in the first couple of pages of results.
I created this to control my house lights from my android phone and my Ipod touch, but it can very easily be tweaked to do almost anything.
The concept is simple. I created a ahk script [monitor.ahk] that looks for another ahk script [myCommand.hak] and then launches it. Then I made a php website [proofofconcetp.php] that creates myCommand.ahk. I use WAMP
http://www.wampserver.com/en/ to serve php on my computer, so that I can see the file from any web capable device on my network.
monitor.ahk looks like this and needs to be in the www folder in wamp.
Code:
loop
{
if FileExist("myCommand.ahk")
{
Run, myCommand.ahk
while FileExist("myCommand.ahk")
{
sleep, 500
FileDelete, myCommand.ahk
}
}
sleep, 1000
}
I am sure there is a much more elegant way to do this, but it works well for me.
The next part is to have a php site create "myCommand.ahk" in that same folderr.
This file is called prrofofconcept.php and it also needs to be in the www folder that WAMP uses:
Code:
<form method="POST" action="proofofconcept.php">
Living Room Lights:
<input type="radio" name="lamp" value="Run C:\Program Files\Common Files\X10\Common\ahcmd.exe sendplc a1 On">On
<input type="radio" name="lamp" value="Run C:\Program Files\Common Files\X10\Common\ahcmd.exe sendplc a1 Off">Off <br />
<input type="submit" value="Execute">
</form>
<?php
$ourFileName = "myCommand.ahk";
$fh = fopen($ourFileName, 'w') or die("can't open file");
$scriptHeader = "#SingleInstance \n";
$scriptFooter = "FileDelete, myCommand.ahk \n";
$linebreak = "\n";
fwrite($fh, $scriptHeader);
$stringData = $_POST['lamp'];
fwrite($fh, $stringData);
fwrite($fh, $linebreak);
fwrite($fh, $scriptFooter);
fclose($fh);
?>
The value for each of the radio buttons is the line of ahk code that you want executed when that button is pressed. You can easily include a functions.ahk file and set the value to a function instead of passing the code of course.
When i browse to that computers ip address + /proofofconcept.php, I see a simple form that has an on and off buttons and a submit button.
Now I can use ahk to turn a light on and off from my phone/ipod/computer/etc.
BTW, i am not very good with php yet, so I am sure there are security issues here. I am not worried because I have my firewall set up properly, but if you allow someone to uplaod to that folder, you could have problems.
I hope this script is useful to someone. I plan on using it to control all of my lights and also some multimedia stuff like playing a playlist, changing the volume etc. I am also going to ditch the form stuff and go for something a bit more eye pleasing. [/url]