Simple Script

Moderator: Telldus

Post Reply
Tiny
Posts: 1
Joined: Fri Mar 17, 2023 9:45 am

Simple Script

Post by Tiny »

Maybe i just cant find it or it doesn't exist but the way i saw it all mobile implementations required both client and serverside installation. Furthermore the applications that seemed promising was windows only, i run ubuntuserver 10.10 and wanted to jack my tellstick into that and the solution that did run on linux was extremely slow(20-30secs between click and action). This solution suited me well since my server is behind a router and i had everything else already installed on the server.

Code: Select all

<?php
if($_GET['unit']){
    exec('tdtool --'.(($_GET['action'] == 'on') ? 'on' : 'off').' '.$_GET['unit'], $out);
}

$out = array();
exec('tdtool --list', $out);
array_shift($out); //Removes the first line of the output "Number of devices: X"
$list = array();
foreach($out as $switches){
    $l = array();
    list($l['id'], $l['name'], $l['state']) = explode("\t", $switches);
    $list[] = $l;
}

foreach($list as $s)
    echo '<a style="font-size: 80px;" href="?unit='.$s['id'].'&action='.(($s['state'] == 'ON') ? 'off' : 'on').'">'.$s['name'].'</a><br />';

?>
It simply lists all configured devices as links at a huge size for my HTC Desire HD. Could probably be shortened further but this format provides easy manipulation to other purposes.

*Edit*
I forgot an important piece. The /dev/tellstick needs to have chmod o+rw in order for the www-data user (webserver) to access it. Without this the tdtool returns permission denied
Post Reply