AutoHotkey Community

It is currently May 27th, 2012, 3:39 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: July 16th, 2010, 8:28 pm 
Offline

Joined: November 16th, 2007, 8:31 am
Posts: 10
Location: California, USA
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]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2010, 5:58 pm 
Offline

Joined: October 4th, 2006, 2:15 am
Posts: 250
Location: Louisville, KY
Nice explanation. However, if you're only running a web server for this purpose, you might want to check out TweetMyPC. It's a lot easier to install and less to configure than WAMP, and while it lets you configure custom commands, it also has a number of delivered functions, including commands for restarting the PC, retrieving files (emails them to you), and printing documents (great for printing a PDF sent from your phone).

Anyway, I don't want to hijack your thread but I found it while looking to do something much like you and thought TweetMyPC was such a clever idea that I couldn't help but share it.


Last edited by wtg on July 20th, 2010, 9:02 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2010, 8:13 pm 
Offline

Joined: November 23rd, 2007, 10:23 am
Posts: 841
Location: ~/.
once upon a time i've written a webserver in ahk which may directly execute almost any type of embedded ahk scripts directly from the website on the server. instead of running a full blown wamp server, this might be easier

OTO if you have excessive use of POST and GET features, like FILEUPLOADS, a xampp or wamp or even lighty or nginx for windows suit better.

check: Sparrow AHK Webserver

greets
dR

_________________
Image
    All scripts, unless otherwise noted, are hereby released under CC-BY


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 13th, 2010, 1:26 am 
Thank you very much for this :D Good idea I will be able to build off this quite easily.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: xXDarknessXx and 15 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group