Home Live Radio Podcast Live TV Vodcast Forum Files Login Register :     Contact : 
 
Forum index Forum: ListenLive Network Remote control development Topic: ListenLive Web Remote Control Last replied to: March 8, 2015, 8:27 pm Back to post view
AuthorPostOptions
Posted by AutoStatic Message # 1     Posted at December 13, 2014, 3:13 pm,     subject: ListenLive Web Remote Control  
Messages: 7 posts
Registration date: November 28, 2014
Status: Offline

ListenLive Web Remote Control (LLWRC)

An attempt to create a super simple web page that allows to remote control the ListenLive firmware via its ListenLive Network Remote Control daemon.

Prerequisites

Web server with PHP extensions enabled in the same local network as the ListenLive device.

Installation

Download the master.zip and extract it in a directory that is readable for your webserver. I'm using LLWRC on my WD My Book Live which runs Debian with Apache and created a dedicated listenlive virtual host configuration. For more info see: https://github.com/AutoStatic/listenlive


(Last Edited by AutoStatic on December 13, 2014, 3:28 pm)
 
Posted by FeliXY Message # 2     Posted at February 11, 2015, 2:54 pm,     subject: ListenLive Web Remote Control  
Messages: 9 posts
Registration date: August 24, 2011
Status: Offline

<pre>Nice script, thank you!

I've done some improvements:
- display of song
- display of state and volume level
- some colors for different states (pause, mute, power off)


---php---
<?php

//--- config ---

$ip = "192.168.20.106";                 // ip of your device
$port = 8080;                        // listening port, no need to change

$refresh_rate_on  = 10;                 // refresh period of website if device is on (seconds)
$refresh_rate_off = 60;                // and period if device is off (seconds)

//--- end config ---

if(!@fsockopen($ip, $port, $errno, $errstr, 2)){
    $on  = "off";
    $vol = "1";
    $answer = "The device is off.<br /><br />
             Press [power] on the device to switch it on.";
    $refresh = $refresh_rate_off;
}else{
    $on = "on";
    if(!empty($_GET)){                // a button was pressed
        $btnval=$_GET["button"];
        $refresh = 1;              // refresh the site immediately
    }else{
        $btnval="METAINFO";            // no button was pressed, get the avabile infos from the device
        $refresh = $refresh_rate_on;
    }

    switch($btnval) {
      case "":
        break;
      case "POWER":
        $on = "off";
        sendData($btnval);
        break;
      case "home":
        goHome();
        break;
      case "settings":
        goHome();
        $settings_cmd = array("DOWN", "DOWN", "DOWN", "RIGHT", "RIGHT", "RIGHT", "OK");
        foreach($settings_cmd as $cmd) {
         sendData("$cmd");
        }
        break;
      case "i_radio":
        goHome();
        $i_radio_cmd = array("OK", "OK");
        foreach($i_radio_cmd as $cmd) {
         sendData("$cmd");
        }
        break;
      case "music_library":
        goHome();
        $music_library_cmd = array("OK", "OK");
        foreach($music_library_cmd as $cmd) {
         sendData("$cmd");
        }
        break;
      case "fav1":
        goHome();
        $fav1_cmd = array("OK", "OK", "OK");
        foreach($fav1_cmd as $cmd) {
         sendData("$cmd");
         usleep(200000);
        }
        break;
      case "fav2":
        goHome();
        $fav2_cmd = array("OK", "OK", "DOWN", "OK");
        foreach($fav2_cmd as $cmd) {
         sendData("$cmd");
         usleep(500000);
        }
        break;
      case "fav3":
        goHome();
        $fav3_cmd = array("OK", "OK", "DOWN", "DOWN", "OK");
        foreach($fav3_cmd as $cmd) {
         sendData("$cmd");
         usleep(200000);
        }
        break;
      case "fav4":
        goHome();
        $fav4_cmd = array("OK", "OK", "DOWN", "DOWN", "DOWN", "OK");
        foreach($fav4_cmd as $cmd) {
         sendData("$cmd");
         usleep(200000);
        }
        break;
      case "fav5":
        goHome();
        $fav5_cmd = array("OK", "OK", "DOWN", "DOWN", "DOWN", "DOWN", "OK");
        foreach($fav5_cmd as $cmd) {
         sendData("$cmd");
         usleep(200000);
        }
        break;
      case "fav6":
        goHome();
        $fav6_cmd = array("OK", "OK", "DOWN", "DOWN", "DOWN", "DOWN", "DOWN", "OK");
        foreach($fav6_cmd as $cmd) {
         sendData("$cmd");
         usleep(200000);
        }
        break;
      default:
        sendData("$btnval");
    }
}

$mute = $vol==0 ? "mute" : "none";
if(strpos($answer, "Playing")> 0){
    $play = "play";
}elseif(strpos($answer, "Paused")> 0){
    $play = "paused";
}else{
    $play = "";
}

function sendData($data) {
    global $ip;
    global $answer;
    global $refresh;
    global $vol;
    $socket = fsockopen($ip, 8080);
    fwrite($socket,$data);
    usleep(300000);
    while (!feof($socket)) {
        $answer .= fgets($socket, 128);
    }
    if($answer == "OK" or $answer == "UNK"){
        $answer = "Command: " . $data . "  -->  " . $answer . "<br><br><br><br><br>";
    }else{   
        $answer  = str_replace("Meta <br>", "", preg_replace("[\d=]", "<br>", $answer));
    }
   
    fclose($socket);
   
    $socket = fsockopen($ip, 8080);
    fwrite($socket, "VOLUME");
    while (!feof($socket)) {
        $vol .= str_replace("VOL=", "", fgets($socket, 128));
    }
    fclose($socket);
}

function goHome() {
    $home_cmd = array("EXIT", "EXIT", "EXIT", "EXIT", "HOME");
    foreach($home_cmd as $cmd) {
        sendData("$cmd");
    }
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Listenlive Web Remote Control</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="refresh" content="<?php echo($refresh);?>; URL=http://<?php echo($_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'])?>">
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>

<form action="index.php" method="get">

<table id="remote">
    <tr>
    <td colspan=3 class="head"><?php echo($answer); ?></td>
  <tr>
    <td><button name="button" value="POWER" class="<?php echo($on) ?>">POWER</button></td>
    <td><button name="button" value="settings">SETTINGS</button></td>       
    <td><button name="button" value="home">HOME</button></td>
  </tr>
  <tr>
    <td><button name="button" value="i_radio">I-RADIO</button></td>
    <td><button name="button" value="MUTE" class="<?php echo($mute)?>">MUTE</button></td>       
    <td><button name="button" value="music_library">MUSIC<br>LIBRARY</button></td>
  </tr>
  <tr>
    <td><button name="button" value="PGUP">PAGE-</button></td>
    <td><button name="button" value="del">DEL</button></td>       
    <td><button name="button" value="PGDN">PAGE+</button></td>
  </tr>
  <tr>
    <td><button id="symbol" name="button" value="REWIND">&#9665;&#9665;</button></td>
    <td><button name="button" value="fav">FAV</button></td>       
    <td><button id="symbol" name="button" value="FORWARD">&#9655;&#9655;</button></td>
  </tr>
  <tr>
    <td><button name="button" value="MENU">MENU</button></td>
    <td><button id="symbol" name="button" value="UP">&#9651;</button></td>       
    <td><button name="button" value="EXIT">EXIT</button></td>
  </tr>
  <tr>
    <td><button id="symbol" name="button" value="LEFT">&#9665;</button></td>
    <td><button name="button" value="OK">ENTER</button></td>       
    <td><button id="symbol" name="button" value="RIGHT">&#9655;</button></td>
  </tr>
  <tr>
    <td><button id="symbol" name="button" value="OK" class="<?php echo($play)?>">&#9655;&#9647;&#9647;</button></td>
    <td><button id="symbol" name="button" value="DOWN">&#9661;</button></td>       
    <td><button id="symbol" name="button" value="STOP">&#9633;</button></td>
  </tr>
  <tr>
    <td><button name="button" value="VOLp">VOL+</button></td>
    <td><button id="symbol" name="button">&#8649;</button></td>       
    <td><button id="symbol" name="button" value="track_next">&#9655;&#9647;</button></td>
  </tr>
  <tr>
    <td class="vol"><?php echo($vol);?></td>
    <td><button name="button" value="shuffle">SHUFFLE</button></td>       
    <td></td>
  </tr>
  <tr>
    <td><button name="button" value="VOLm">VOL-</button></td>
    <td><button id="symbol" name="button" value="REPEAT">&#8634;</button></td>       
    <td><button id="symbol" name="button" value="track_prev">&#9647;&#9665;</button></td>
  </tr>
  <tr>
    <td><button name="button" value="fav1">FAV1</button></td>
    <td><button name="button" value="fav2">FAV2</button></td>       
    <td><button name="button" value="fav3">FAV3</button></td>       
    <td></td>
  </tr>
  <tr>
    <td><button name="button" value="fav4">FAV4</button></td>
    <td><button name="button" value="fav5">FAV5</button></td>       
    <td><button name="button" value="fav6">FAV6</button></td>       
    <td></td>
  </tr>
</table>
</form>

</body>
</html>



---css---
table#remote {
    /*width: 33%;*/
    /*text-align: center;*/
}

button {
    width: 100px;
    height: 36px;
}

button#symbol {
    font-size: 125%;
}

button.on, .play {
     background-color: #08B408;
}
button.off {
     background-color: #F59223;
}
.vol{
     font-size: 11px;
     font-family:arial;
     padding:5px;
     text-align: center;
}
.head {
     background-color:#cccccc;
     font-size: 11px;
     font-family:arial;
     padding:5px;
    
}
.mute, .paused{
     background-color:yellow;
}
</pre>
(Last Edited by FeliXY on February 11, 2015, 3:03 pm)
 
Posted by AutoStatic Message # 3     Posted at March 8, 2015, 8:27 pm,     subject: ListenLive Web Remote Control  
Messages: 7 posts
Registration date: November 28, 2014
Status: Offline

Hello FeliXY, I'm going to try out the improvements and report back!