Control Panasonic VT50 with PHP

Posted on
Tue Dec 31, 2013 7:05 am
Vaillant offline
Posts: 105
Joined: Nov 06, 2011
Location: Belgium

Control Panasonic VT50 with PHP

Hi,

I had my Panasonic TV working through a PHP-script. I did a fresh install on my Mac and lost the script.
Now I am setting it up again but can't get it to work.

Got the standard script from the net. Just have to add a fixed IP in the script in the right place. Did several try's but none works.
Who can help?

Greetings,
Adrian

Code: Select all
<?php
class vieraControl
{
   public $host;
   
   function __construct($hostname = false)
   {
      if ($hostname)
         $this->host = $hostname;
   }
   
   function createRequest($url, $urn, $action, $option = array())
   {

$input = '<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
 <s:Body>
  <u:'.$action.' xmlns:u="urn:'.$urn.'">
  '.$option['args'].'
  </u:'.$action.'>
 </s:Body>
</s:Envelope>';
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL, 'http://'.$this->host.':55000/'.$url);
      curl_setopt($curl, CURLOPT_POST, 1);
      curl_setopt($curl, CURLOPT_HTTPHEADER, array('SOAPACTION: "urn:'.$urn.'#'.$action.'"'));   
      curl_setopt($curl, CURLOPT_POSTFIELDS, $input);
      //curl_setopt($curl, CURLOPT_HEADER, true);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      $data = curl_exec($curl);
      
      if ($option['returnXml'])
         return $data;
      else
         return $this->getResponse($data);
   }
   
   function getResponse($data)
   {
      $xml = simplexml_load_string($data);
      if ($xml === false)
         return false;
      $ns = $xml->getNamespaces(true);
      $soap = $xml->children($ns['s']);
      $res = $soap->children($ns['u'])->children();
      return $res[0];
   }
   
   function getVolume()
   {
      return $this->createRequest(
         'dmr/control_0',
         'schemas-upnp-org:service:RenderingControl:1',
         'GetVolume',
         array('args' => '<InstanceID>0</InstanceID><Channel>Master</Channel>')
      );
   }
   
   function sendKey($keyCode)
   {
      return $this->createRequest(
         'nrc/control_0',
         'panasonic-com:service:p00NetworkControl:1',
         'X_SendKey',
         array(
            'args' => '<X_KeyEvent>' . $keyCode . '</X_KeyEvent>',
            'returnXml' => true
         )
      );
   }
   
   function getMute()
   {
      return $this->createRequest(
         'dmr/control_0',
         'schemas-upnp-org:service:RenderingControl:1',
         'GetMute',
         array('args' => '<InstanceID>0</InstanceID><Channel>Master</Channel>')
      );
   }
   
   function setMute($enable = false)
   {
      $data = ($enable) ? '1' : '0';
      return $this->createRequest(
         'dmr/control_0',
         'schemas-upnp-org:service:RenderingControl:1',
         'SetMute',
         array('args' => '<InstanceID>0</InstanceID><Channel>Master</Channel><DesiredMute>'.$data.'</DesiredMute>')
      );
   }

   function setVolume($volume = '0')
   {
      $volume = intval($volume);
      if ($volume > 100 || $volume < 0)
         throw new Exception('Bad request to volume control. Must be between 0 and 100');
         
      return $this->createRequest(
         'dmr/control_0',
         'schemas-upnp-org:service:RenderingControl:1',
         'SetVolume',
         array('args' => '<InstanceID>0</InstanceID><Channel>Master</Channel><DesiredVolume>'.$volume.'</DesiredVolume>', 'returnXml' => true)
      );
   }
   
   function sendString($string)
   {
      return $this->createRequest(
         'nrc/control_0',
         'panasonic-com:service:p00NetworkControl:1',
         'X_SendString',
         array(
            'args' => '<X_String>' . $string . '</X_String>',
            'returnXml' => true
         )
      );      
   }
}

$keys = array(
   "NRC_CH_DOWN-ONOFF", // channel down
   "NRC_CH_UP-ONOFF", // channel up
   "NRC_VOLUP-ONOFF", // volume up
   "NRC_VOLDOWN-ONOFF", // volume down
   "NRC_MUTE-ONOFF", // mute
   "NRC_TV-ONOFF", // TV
   "NRC_CHG_INPUT-ONOFF", // AV,
   "NRC_RED-ONOFF", // red
   "NRC_GREEN-ONOFF", // green
   "NRC_YELLOW-ONOFF", // yellow
   "NRC_BLUE-ONOFF", // blue
   "NRC_VTOOLS-ONOFF", // VIERA tools
   "NRC_CANCEL-ONOFF", // Cancel / Exit
   "NRC_SUBMENU-ONOFF", // Option
   "NRC_RETURN-ONOFF", // Return
   "NRC_ENTER-ONOFF", // Control Center click / enter
   "NRC_RIGHT-ONOFF", // Control RIGHT
   "NRC_LEFT-ONOFF", // Control LEFT
   "NRC_UP-ONOFF", // Control UP
   "NRC_DOWN-ONOFF", // Control DOWN
   "NRC_3D-ONOFF", // 3D button
   "NRC_SD_CARD-ONOFF", // SD-card
   "NRC_DISP_MODE-ONOFF", // Display mode / Aspect ratio
   "NRC_MENU-ONOFF", // Menu
   "NRC_INTERNET-ONOFF", // VIERA connect
   "NRC_VIERA_LINK-ONOFF", // VIERA link
   "NRC_EPG-ONOFF", // Guide / EPG
   "NRC_TEXT-ONOFF", // Text / TTV
   "NRC_STTL-ONOFF", // STTL / Subtitles
   "NRC_INFO-ONOFF", // info
   "NRC_INDEX-ONOFF", // TTV index
   "NRC_HOLD-ONOFF", // TTV hold / image freeze
   "NRC_R_TUNE-ONOFF", // Last view
   "NRC_POWER-ONOFF", // Power off
   
   "NRC_REW-ONOFF", // rewind
   "NRC_PLAY-ONOFF", // play
   "NRC_FF-ONOFF", // fast forward
   "NRC_SKIP_PREV-ONOFF", // skip previous
   "NRC_PAUSE-ONOFF", // pause
   "NRC_SKIP_NEXT-ONOFF", // skip next
   "NRC_STOP-ONOFF", // stop
   "NRC_REC-ONOFF", // record
   
   // numeric buttons
   "NRC_D1-ONOFF", "NRC_D2-ONOFF", "NRC_D3-ONOFF", "NRC_D4-ONOFF", "NRC_D5-ONOFF",
   "NRC_D6-ONOFF", "NRC_D7-ONOFF", "NRC_D8-ONOFF", "NRC_D9-ONOFF", "NRC_D0-ONOFF",
   
   // The below commands were not avaliable in the iPhone app when using my
   // VIERA G30 - they were pulled out from a disassembly instead
   // only these top three did anything on my TV
   
   "NRC_P_NR-ONOFF", // P-NR (Noise reduction)
   "NRC_OFFTIMER-ONOFF", // off timer
   "NRC_R_TUNE-ONOFF", // Seems to do the same as INFO
   
   "NRC_CHG_NETWORK-ONOFF",
   "NRC_CC-ONOFF",
   "NRC_SAP-ONOFF",
   "NRC_RECLIST-ONOFF",
   "NRC_DRIVE-ONOFF",
   "NRC_DATA-ONOFF",
   "NRC_BD-ONOFF",
   "NRC_FAVORITE-ONOFF",
   "NRC_DIGA_CTL-ONOFF",
   "NRC_VOD-ONOFF",
   "NRC_ECO-ONOFF",
   "NRC_GAME-ONOFF",
   "NRC_EZ_SYNC-ONOFF",
   "NRC_PICTAI-ONOFF",
   "NRC_MPX-ONOFF",
   "NRC_SPLIT-ONOFF",
   "NRC_SWAP-ONOFF",
   "NRC_R_SCREEN-ONOFF",
   "NRC_30S_SKIP-ONOFF",
   "NRC_PROG-ONOFF",
   "NRC_TV_MUTE_ON-ONOFF",
   "NRC_TV_MUTE_OFF-ONOFF",
   "NRC_DMS_CH_UP-ONOFF",
   "NRC_DMS_CH_DOWN-ONOFF"

);

Posted on
Wed Jan 01, 2014 6:08 am
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: Control Panasonic VT50 with PHP

very interesting, was just looking to put something similar in place. May have to try and convert the script to use curl calls, but my scripting is very limited.

doen't the ip address go in before the port number ie, xxx.xxx.xxx.xxx:55000

just a guess as my scripting is poor.

Happy new year


Mat

Late 2018 mini 10.14

Posted on
Wed Jan 01, 2014 7:23 am
Vaillant offline
Posts: 105
Joined: Nov 06, 2011
Location: Belgium

Re: Control Panasonic VT50 with PHP

Hi Mat,

Tried that already and no luck.
At this point I want confirmation that the script should work (with the ip in the right place) so I can trouble shoot the other elements in my setup.

Scanned the Web for solutions in the past. This one was the only that worked with the VT50.

Thanks for your suggestion.

To all; happy new year.

Adrian

Posted on
Wed Jan 01, 2014 9:57 am
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Control Panasonic VT50 with PHP

I haven't tried this, but I had bookmarked this Python Vierra class to try out -- I hope to write a fully-featured plugin for mine at some point in the future. This one is pretty bare bones (doesn't do too much) but might could be extended for more functionality fairly easily based on my quick look previously.

Note it is a bit old now so ignore the model numbers supported. But I haven't tried it either...

Posted on
Wed Jan 01, 2014 11:47 am
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: Control Panasonic VT50 with PHP

happy to do some testing on a VT if it helps out. Just shout.

Late 2018 mini 10.14

Posted on
Fri Jan 03, 2014 5:58 am
Vaillant offline
Posts: 105
Joined: Nov 06, 2011
Location: Belgium

Re: Control Panasonic VT50 with PHP

For those interested. This script makes it work.

Most action codes from previous script work.

Code: Select all
<?php
$action = $_GET['action'];
$input = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$input .= "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n";
$input .= "<s:Body>\n";
$input .= "<u:X_SendKey xmlns:u=\"urn:panasonic-com:service:p00NetworkControl:1\">\n";
$input .= "<X_KeyEvent>";
$input .= $action;
$input .= "</X_KeyEvent>\n";
$input .= "</u:X_SendKey>\n";
$input .= "</s:Body>\n";
$input .= "</s:Envelope>\n\n";
$header = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPACTION: \"urn:panasonic-com:service:p00NetworkControl:1#X_SendKey\"",
"Content-Length: ".strlen($input),
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://192.168.0.100:55000/nrc/control_0');
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POSTFIELDS, $input);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  if(curl_exec($curl) === false) {
    $err = 'Curl error: ' . curl_error($curl);
    curl_close($curl);
    print $err;
  } else {
    curl_close($curl);
    print 'Operation completed without any errors';
  }
?>

Posted on
Wed Mar 19, 2014 4:52 pm
BassMint offline
Posts: 105
Joined: Dec 24, 2013

Re: Control Panasonic VT50 with PHP

Vaillant wrote:
For those interested. This script makes it work.



cn you elaborate a bit on how to set this up?

Posted on
Sun Mar 23, 2014 5:51 am
Vaillant offline
Posts: 105
Joined: Nov 06, 2011
Location: Belgium

Re: Control Panasonic VT50 with PHP

Hi,

I am not an expert but I made it work. What I have done:
- I use OSX Server and enabled Websites.
- I use the default website (with python web programs enabled).
- Saved the PHP-script as pan.php and put it in de directory of the website.
- In Indigo I call the PHP-script with the action I want it to perform (http://192.168.1.12/pan.php?action=NRC_MENU-ONOFF)

The only command that is not working is power on (power off works). This is due to the VT disabling ethernet connection after power off.

Hope this helps.

Greetings,
Adrian

Posted on
Sun Mar 23, 2014 7:29 am
BassMint offline
Posts: 105
Joined: Dec 24, 2013

Re: Control Panasonic VT50 with PHP

Vaillant wrote:
Hi,

I am not an expert but I made it work. What I have done:
- I use OSX Server and enabled Websites.
- I use the default website (with python web programs enabled).
- Saved the PHP-script as pan.php and put it in de directory of the website.
- In Indigo I call the PHP-script with the action I want it to perform (http://192.168.1.12/pan.php?action=NRC_MENU-ONOFF)

The only command that is not working is power on (power off works). This is due to the VT disabling ethernet connection after power off.

Hope this helps.

Greetings,
Adrian


thanks.

Posted on
Tue Nov 22, 2016 10:55 am
Albatros offline
Posts: 132
Joined: Feb 07, 2015

Re: Control Panasonic VT50 with PHP

I have got a Panasonic Panasonic TX-P55VT50.I did the following steps:

- I enabled Apache server OSX on my mac mini
- I have only changed the IP address in the php script from above with my Panasonic IP address
- I have put the php script in /Library/WebServer/Documents and called it pan.php


I didn't enabled the python web programs. Not sure why I need it.


When I put this Url in the browser http://<mac mini ip>/pan.php?action=NRC_MENU-ONOFF it returns the content of the php page but does not put the "menu on" at the TV. Also the power of didn'y work. Any ideas?

Posted on
Wed Nov 23, 2016 12:40 pm
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: Control Panasonic VT50 with PHP

Only power off works for the panasonic screens, power on does not work - its a well documented issue. I just switch mine on and off with a powerline zwave socket.

Late 2018 mini 10.14

Posted on
Mon Nov 28, 2016 2:16 am
rhanson offline
Posts: 192
Joined: Apr 30, 2013

Re: Control Panasonic VT50 with PHP

The VT50 and VT60 (and probably others) respond to Wake-On-LAN packets, so you can power them on anytime.

I believe you need to enable this in the Panasonic menu.

Once done, install the "awake" python library:
https://pypi.python.org/pypi/awake/1.0

And then,

Code: Select all
from awake import wol
wol.send_magic_packet('8C:C1:21:xx:xx:xx')


Throw that in an action group called "Turn on TV" or embed into your favorite script.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest