PDA

View Full Version : How to: Control mControl by URL (and keyboard)


Jaro
10-28-2008, 05:35 PM
Hi,

I was looking for a way to control my X10 devices by keyboard, using mControl. Because I was trying for a quick (and dirty?) solution (and have no experience with the SDK), I decided to take the mControl mobile web-interface and create a script to control the devices using an URL.

This resulted in the following to scripts (attached to this post), which should be put in the root of the mControl webserver:

URLE.aspx: This script accepts a querystring for executing a command or a macro (it creates a SOAP envelope based on the querystring and submits this to mControl for execution).

and

URLI.aspx: This script displays all possible querystrings for your installation (change 'var server = "localhost:29990"; on line 22' in the script to the IP of your installation to create URLs that can be used on any client in your network).

Illustration. To turn device with ID 0 On, the following URL is generated by URLI.aspx and used to invoke URLE.aspx:

http://localhost:29990/URLE.aspx?type=AutomationCommand&devid=0&str=On

Finally, by using a combination of HotkeyP, hstart and wget, I was able to create keyboard shortcuts for controlling my devices. To achieve this, the following should be configured in HotkeyP for any key that you would like to assign to a device command (i.e. turn device 0 on, assuming hstart.exe and wget.exe are installed in C:\tools\):

Command:

C:\tools\hstart.exe

Parameters:

/NOCONSOLE "C:\tools\wget.exe --spider http://localhost:29990/URLE.aspx?type=AutomationCommand&devid=0&str=On"

Window "Minimized" and "Enable multiple instances" activated.

Reason for using hstart is to prevent wget getting the focus and interfering with Media Center, this way wget will run in the background. Reason for using --spider is to prevent wget generating any output (on drive), it will just call the URL.

I hope this is useful. I hope I didn't reinvent the wheel...

-- Jaro

PS. You can also use URLI.aspx to send commands, but in this case some client side javascript processing is required, wget will not do this. My apologies for the lack of comments in the code, I didn't find the time to clean it up. All I did was strip the mControl scripts to end up with the pieces I needed for my purpose.

mens_2000
11-16-2008, 02:29 AM
I converted the program into the Perl language.
However, SOAP communication to mControl doesn't function correctly.
Please advise me on a correct description method.


#!/usr/bin/perl

use SOAP::Lite +trace => 'debug';

my $method = 'AutomationCommand';
my $targetNamespace = 'http://embeddedautomation.com/webservices/mControl/';
my $proxy = 'http://localhost:29990/mServer.asmx' ;

my $deviceID = '1';
my $command = 'On';

$soap = SOAP::Lite
-> uri($targetNamespace)
-> on_action( sub { $targetNamespace . $method } )
-> proxy($proxy);

$result = $soap->call(
SOAP::Data->name("AutomationCommand")->attr({ xmlns => $targetNamespace }),
SOAP::Data->name("deviceId" => $deviceID),
SOAP::Data->name("command" => $command)
);

die "[".$result->faultcode."]".$result->faultstring if $result->fault;

print "Content-type: text/plain;charset=UTF-8\n\n";

print $result . "\n";

katrash
11-17-2008, 08:55 PM
I'm not a Perl programmer and can't help in this, but I can direct you to the proper links for the web service and its wsdl on the local machine:

http://localhost:29990/mServer.asmx (http://localhost:29990/mServer.asmx?wsdl)
http://localhost:29990/mServer.asmx?wsdl

This is a standard .NET web service created via Visual Studio 2005 which is supposedly a SOAP (both 1.1 and 1.2) compliant one.

hadiesper
06-14-2010, 08:35 PM
Great Stuff, Is there a way to do this but to change polling rate on a device instead of perform an automation command?

hadiesper
04-06-2012, 07:50 PM
Is It possible to make a version of this for v3?